From c6de464587a21b815f00451316adea3588a075cc Mon Sep 17 00:00:00 2001 From: Yicheng Qin Date: Fri, 3 Apr 2015 10:03:39 -0700 Subject: [PATCH] raft: lock storage when compact it etcd now compact raft storage asynchronously, and append entry to raft storage may happen at the same time. Add the lock to fix the bug that the entries saved in storage may be organized in a wrong way. --- raft/storage.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/raft/storage.go b/raft/storage.go index d57cb7cab..65212869f 100644 --- a/raft/storage.go +++ b/raft/storage.go @@ -194,6 +194,8 @@ func (ms *MemoryStorage) CreateSnapshot(i uint64, cs *pb.ConfState, data []byte) // It is the application's responsibility to not attempt to compact an index // greater than raftLog.applied. func (ms *MemoryStorage) Compact(compactIndex uint64) error { + ms.Lock() + defer ms.Unlock() offset := ms.ents[0].Index if compactIndex <= offset { return ErrCompacted