Commit + apply all in nextEnts
This fixes essentially all tests using this, since now they don't have
to do anything special about the extra cycle introduced for single
nodes.
@@ -29,14 +29,16 @@ import (
// nextEnts returns the appliable entries and updates the applied index
func nextEnts(r *raft, s *MemoryStorage) (ents []pb.Entry) {
- // Transfer all unstable entries to "stable" storage.
- s.Append(r.raftLog.unstableEntries())
- r.raftLog.stableTo(r.raftLog.lastIndex(), r.raftLog.lastTerm())
-
- ents = r.raftLog.nextEnts()
- r.raftLog.appliedTo(r.raftLog.committed)
+ for {
+ rd := newReady(r, &SoftState{}, pb.HardState{})
+ s.Append(rd.Entries)
+ r.advance(rd)
+ if len(rd.Entries)+len(rd.CommittedEntries) == 0 {
return ents
}
+ ents = append(ents, rd.CommittedEntries...)
+ }
+}
func mustAppendEntry(r *raft, ents ...pb.Entry) {
if !r.appendEntry(ents...) {
