From 21987c87019444d680bfa62670bd293850b19561 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Thu, 6 Nov 2014 17:13:35 -0500 Subject: [PATCH] raft: remove raftLog.resetUnstable and resetNextEnts These methods are no longer used outside of tests and are redundant with the new stableTo and appliedTo methods. --- raft/log.go | 10 ---------- raft/log_test.go | 6 +++--- raft/raft_paper_test.go | 4 ++-- raft/raft_test.go | 2 +- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/raft/log.go b/raft/log.go index 13a763db7..496a1043c 100644 --- a/raft/log.go +++ b/raft/log.go @@ -114,10 +114,6 @@ func (l *raftLog) unstableEnts() []pb.Entry { return cpy } -func (l *raftLog) resetUnstable() { - l.unstable = l.lastIndex() + 1 -} - // nextEnts returns all the available entries for execution. // all the returned entries will be marked as applied. func (l *raftLog) nextEnts() (ents []pb.Entry) { @@ -127,12 +123,6 @@ func (l *raftLog) nextEnts() (ents []pb.Entry) { return nil } -func (l *raftLog) resetNextEnts() { - if l.committed > l.applied { - l.applied = l.committed - } -} - func (l *raftLog) appliedTo(i uint64) { if i == 0 { return diff --git a/raft/log_test.go b/raft/log_test.go index 46072f376..9ea3aba51 100644 --- a/raft/log_test.go +++ b/raft/log_test.go @@ -286,7 +286,7 @@ func TestCompactionSideEffects(t *testing.T) { raftLog.append(uint64(i), pb.Entry{Term: uint64(i + 1), Index: uint64(i + 1)}) } raftLog.maybeCommit(lastIndex, lastTerm) - raftLog.resetNextEnts() + raftLog.appliedTo(raftLog.committed) raftLog.compact(500) @@ -342,7 +342,7 @@ func TestUnstableEnts(t *testing.T) { raftLog.append(0, previousEnts...) raftLog.unstable = tt.unstable ents := raftLog.unstableEnts() - raftLog.resetUnstable() + raftLog.stableTo(raftLog.lastIndex()) if !reflect.DeepEqual(ents, tt.wents) { t.Errorf("#%d: unstableEnts = %+v, want %+v", i, ents, tt.wents) } @@ -384,7 +384,7 @@ func TestCompaction(t *testing.T) { raftLog.append(uint64(i), pb.Entry{}) } raftLog.maybeCommit(tt.applied, 0) - raftLog.resetNextEnts() + raftLog.appliedTo(raftLog.committed) for j := 0; j < len(tt.compact); j++ { raftLog.compact(tt.compact[j]) diff --git a/raft/raft_paper_test.go b/raft/raft_paper_test.go index 546a0ebc1..71e8a5cf5 100644 --- a/raft/raft_paper_test.go +++ b/raft/raft_paper_test.go @@ -891,8 +891,8 @@ func commitNoopEntry(r *raft) { } // ignore further messages to refresh followers' commmit index r.readMessages() - r.raftLog.resetNextEnts() - r.raftLog.resetUnstable() + r.raftLog.appliedTo(r.raftLog.committed) + r.raftLog.stableTo(r.raftLog.lastIndex()) } func acceptAndReply(m pb.Message) pb.Message { diff --git a/raft/raft_test.go b/raft/raft_test.go index 0c334c183..2acf2e636 100644 --- a/raft/raft_test.go +++ b/raft/raft_test.go @@ -31,7 +31,7 @@ import ( // nextEnts returns the appliable entries and updates the applied index func nextEnts(r *raft) (ents []pb.Entry) { ents = r.raftLog.nextEnts() - r.raftLog.resetNextEnts() + r.raftLog.appliedTo(r.raftLog.committed) return ents }