Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ func newRaft(c *Config) *raft {

func (r *raft) hasLeader() bool { return r.lead != None }

func (r *raft) softState() *SoftState { return &SoftState{Lead: r.lead, RaftState: r.state} }
func (r *raft) softState() SoftState { return SoftState{Lead: r.lead, RaftState: r.state} }

func (r *raft) hardState() pb.HardState {
return pb.HardState{
Expand Down
9 changes: 6 additions & 3 deletions rawnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func NewRawNode(config *Config) (*RawNode, error) {
raft: r,
}
rn.asyncStorageWrites = config.AsyncStorageWrites
rn.prevSoftSt = r.softState()
ss := r.softState()
rn.prevSoftSt = &ss
rn.prevHardSt = r.hardState()
return rn, nil
}
Expand Down Expand Up @@ -144,7 +145,9 @@ func (rn *RawNode) readyWithoutAccept() Ready {
Messages: r.msgs,
}
if softSt := r.softState(); !softSt.equal(rn.prevSoftSt) {
rd.SoftState = softSt
// Allocate only when SoftState changes.
escapingSoftSt := softSt
rd.SoftState = &escapingSoftSt
}
if hardSt := r.hardState(); !isHardStateEqual(hardSt, rn.prevHardSt) {
rd.HardState = hardSt
Expand Down Expand Up @@ -445,7 +448,7 @@ func (rn *RawNode) applyUnstableEntries() bool {
func (rn *RawNode) HasReady() bool {
// TODO(nvanbenschoten): order these cases in terms of cost and frequency.
r := rn.raft
if !r.softState().equal(rn.prevSoftSt) {
if softSt := r.softState(); !softSt.equal(rn.prevSoftSt) {
return true
}
if hardSt := r.hardState(); !IsEmptyHardState(hardSt) && !isHardStateEqual(hardSt, rn.prevHardSt) {
Expand Down
1 change: 1 addition & 0 deletions rawnode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,7 @@ func benchmarkRawNodeImpl(b *testing.B, peers ...uint64) {
if applied < uint64(b.N) {
b.Fatalf("did not apply everything: %d < %d", applied, b.N)
}
b.ReportAllocs()
b.ReportMetric(float64(s.callStats.firstIndex)/float64(b.N), "firstIndex/op")
b.ReportMetric(float64(s.callStats.lastIndex)/float64(b.N), "lastIndex/op")
b.ReportMetric(float64(s.callStats.term)/float64(b.N), "term/op")
Expand Down
2 changes: 1 addition & 1 deletion status.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func getBasicStatus(r *raft) BasicStatus {
LeadTransferee: r.leadTransferee,
}
s.HardState = r.hardState()
s.SoftState = *r.softState()
s.SoftState = r.softState()
s.Applied = r.raftLog.applied
return s
}
Expand Down