From 39e6631447677a7446195003bdc30f3823f9abcd Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Tue, 25 Nov 2014 23:27:40 -0800 Subject: [PATCH] raft: always write dummy entry to storage --- raft/log.go | 4 ++-- raft/log_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/raft/log.go b/raft/log.go index 6ece348b7..1488cc4e6 100644 --- a/raft/log.go +++ b/raft/log.go @@ -216,8 +216,8 @@ func (l *raftLog) snap(d []byte, index, term uint64, nodes []uint64) { } func (l *raftLog) restore(s pb.Snapshot) { - l.ents = []pb.Entry{{Term: s.Term}} - l.unstable = s.Index + 1 + l.ents = []pb.Entry{{Index: s.Index, Term: s.Term}} + l.unstable = s.Index l.committed = s.Index l.offset = s.Index l.snapshot = s diff --git a/raft/log_test.go b/raft/log_test.go index 6ce4f5db9..eb68ec6b6 100644 --- a/raft/log_test.go +++ b/raft/log_test.go @@ -501,8 +501,8 @@ func TestLogRestore(t *testing.T) { if raftLog.committed != index { t.Errorf("comitted = %d, want %d", raftLog.committed, index) } - if raftLog.unstable != index+1 { - t.Errorf("unstable = %d, want %d", raftLog.unstable, index+1) + if raftLog.unstable != index { + t.Errorf("unstable = %d, want %d", raftLog.unstable, index) } if raftLog.term(index) != term { t.Errorf("term = %d, want %d", raftLog.term(index), term)