Skip to content

Commit

Permalink
raft: rename raftLog.nextEnts to raftLog.nextCommittedEnts
Browse files Browse the repository at this point in the history
Also rename hasNextEnts to hasNextCommittedEnts.

Pure refactor.

Signed-off-by: Nathan VanBenschoten <[email protected]>
  • Loading branch information
nvanbenschoten committed Nov 10, 2022
1 parent 0bff3ad commit 9337120
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
12 changes: 6 additions & 6 deletions raft/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type raftLog struct {
logger Logger

// maxNextEntsSize is the maximum number aggregate byte size of the messages
// returned from calls to nextEnts.
// returned from calls to nextCommittedEnts.
maxNextEntsSize uint64
}

Expand Down Expand Up @@ -177,10 +177,10 @@ func (l *raftLog) unstableEntries() []pb.Entry {
return l.unstable.entries
}

// nextEnts returns all the available entries for execution.
// nextCommittedEnts returns all the available entries for execution.
// If applied is smaller than the index of snapshot, it returns all committed
// entries after the index of snapshot.
func (l *raftLog) nextEnts() (ents []pb.Entry) {
func (l *raftLog) nextCommittedEnts() (ents []pb.Entry) {
off := max(l.applied+1, l.firstIndex())
if l.committed+1 > off {
ents, err := l.slice(off, l.committed+1, l.maxNextEntsSize)
Expand All @@ -192,9 +192,9 @@ func (l *raftLog) nextEnts() (ents []pb.Entry) {
return nil
}

// hasNextEnts returns if there is any available entries for execution. This
// is a fast check without heavy raftLog.slice() in raftLog.nextEnts().
func (l *raftLog) hasNextEnts() bool {
// hasNextCommittedEnts returns if there is any available entries for execution.
// This is a fast check without heavy raftLog.slice() in nextCommittedEnts().
func (l *raftLog) hasNextCommittedEnts() bool {
off := max(l.applied+1, l.firstIndex())
return l.committed+1 > off
}
Expand Down
8 changes: 4 additions & 4 deletions raft/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func TestCompactionSideEffects(t *testing.T) {
}
}

func TestHasNextEnts(t *testing.T) {
func TestHasNextCommittedEnts(t *testing.T) {
snap := pb.Snapshot{
Metadata: pb.SnapshotMetadata{Term: 1, Index: 3},
}
Expand All @@ -365,14 +365,14 @@ func TestHasNextEnts(t *testing.T) {
raftLog.maybeCommit(5, 1)
raftLog.appliedTo(tt.applied)

hasNext := raftLog.hasNextEnts()
hasNext := raftLog.hasNextCommittedEnts()
if hasNext != tt.hasNext {
t.Errorf("#%d: hasNext = %v, want %v", i, hasNext, tt.hasNext)
}
}
}

func TestNextEnts(t *testing.T) {
func TestNextCommittedEnts(t *testing.T) {
snap := pb.Snapshot{
Metadata: pb.SnapshotMetadata{Term: 1, Index: 3},
}
Expand All @@ -398,7 +398,7 @@ func TestNextEnts(t *testing.T) {
raftLog.maybeCommit(5, 1)
raftLog.appliedTo(tt.applied)

nents := raftLog.nextEnts()
nents := raftLog.nextCommittedEnts()
if !reflect.DeepEqual(nents, tt.wents) {
t.Errorf("#%d: nents = %+v, want %+v", i, nents, tt.wents)
}
Expand Down
2 changes: 1 addition & 1 deletion raft/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ func (n *node) ReadIndex(ctx context.Context, rctx []byte) error {
func newReady(r *raft, prevSoftSt *SoftState, prevHardSt pb.HardState) Ready {
rd := Ready{
Entries: r.raftLog.unstableEntries(),
CommittedEntries: r.raftLog.nextEnts(),
CommittedEntries: r.raftLog.nextCommittedEnts(),
Messages: r.msgs,
}
if softSt := r.softState(); !softSt.equal(prevSoftSt) {
Expand Down
4 changes: 2 additions & 2 deletions raft/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,8 @@ func (s *ignoreSizeHintMemStorage) Entries(lo, hi uint64, maxSize uint64) ([]raf
// internal one. The original bug was the following:
//
// - node learns that index 11 (or 100, doesn't matter) is committed
// - nextEnts returns index 1..10 in CommittedEntries due to size limiting. However,
// index 10 already exceeds maxBytes, due to a user-provided impl of Entries.
// - nextCommittedEnts returns index 1..10 in CommittedEntries due to size limiting.
// However, index 10 already exceeds maxBytes, due to a user-provided impl of Entries.
// - Commit index gets bumped to 10
// - the node persists the HardState, but crashes before applying the entries
// - upon restart, the storage returns the same entries, but `slice` takes a different code path
Expand Down
10 changes: 5 additions & 5 deletions raft/raft_paper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ func TestLeaderCommitEntry(t *testing.T) {
t.Errorf("committed = %d, want %d", g, li+1)
}
wents := []pb.Entry{{Index: li + 1, Term: 1, Data: []byte("some data")}}
if g := r.raftLog.nextEnts(); !reflect.DeepEqual(g, wents) {
t.Errorf("nextEnts = %+v, want %+v", g, wents)
if g := r.raftLog.nextCommittedEnts(); !reflect.DeepEqual(g, wents) {
t.Errorf("nextCommittedEnts = %+v, want %+v", g, wents)
}
msgs := r.readMessages()
sort.Sort(messageSlice(msgs))
Expand Down Expand Up @@ -538,7 +538,7 @@ func TestLeaderCommitPrecedingEntries(t *testing.T) {

li := uint64(len(tt))
wents := append(tt, pb.Entry{Term: 3, Index: li + 1}, pb.Entry{Term: 3, Index: li + 2, Data: []byte("some data")})
if g := r.raftLog.nextEnts(); !reflect.DeepEqual(g, wents) {
if g := r.raftLog.nextCommittedEnts(); !reflect.DeepEqual(g, wents) {
t.Errorf("#%d: ents = %+v, want %+v", i, g, wents)
}
}
Expand Down Expand Up @@ -590,8 +590,8 @@ func TestFollowerCommitEntry(t *testing.T) {
t.Errorf("#%d: committed = %d, want %d", i, g, tt.commit)
}
wents := tt.ents[:int(tt.commit)]
if g := r.raftLog.nextEnts(); !reflect.DeepEqual(g, wents) {
t.Errorf("#%d: nextEnts = %v, want %v", i, g, wents)
if g := r.raftLog.nextCommittedEnts(); !reflect.DeepEqual(g, wents) {
t.Errorf("#%d: nextCommittedEnts = %v, want %v", i, g, wents)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion raft/rawnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (rn *RawNode) HasReady() bool {
if r.raftLog.hasPendingSnapshot() {
return true
}
if len(r.msgs) > 0 || len(r.raftLog.unstableEntries()) > 0 || r.raftLog.hasNextEnts() {
if len(r.msgs) > 0 || len(r.raftLog.unstableEntries()) > 0 || r.raftLog.hasNextCommittedEnts() {
return true
}
if len(r.readStates) != 0 {
Expand Down
4 changes: 2 additions & 2 deletions raft/rawnode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -885,8 +885,8 @@ func TestRawNodeStatus(t *testing.T) {
// Raft group would forget to apply entries:
//
// - node learns that index 11 is committed
// - nextEnts returns index 1..10 in CommittedEntries (but index 10 already
// exceeds maxBytes), which isn't noticed internally by Raft
// - nextCommittedEnts returns index 1..10 in CommittedEntries (but index 10
// already exceeds maxBytes), which isn't noticed internally by Raft
// - Commit index gets bumped to 10
// - the node persists the HardState, but crashes before applying the entries
// - upon restart, the storage returns the same entries, but `slice` takes a
Expand Down

0 comments on commit 9337120

Please sign in to comment.