etcdserver: commit v3 storage before releasing WAL

This ensures that v3 storage could always find the following log entries
when restart.
This commit is contained in:
Yicheng Qin 2015-10-26 21:06:08 -07:00
parent 7e38f05ceb
commit 263b270708
4 changed files with 13 additions and 0 deletions

View File

@ -1029,6 +1029,13 @@ func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) {
}
plog.Panicf("unexpected create snapshot error %v", err)
}
if s.cfg.V3demo {
// commit v3 storage because WAL file before snapshot index
// could be removed after SaveSnap.
s.kv.Commit()
}
// SaveSnap saves the snapshot and releases the locked wal files
// to the snapshot index.
if err := s.r.storage.SaveSnap(snap); err != nil {
plog.Fatalf("save snapshot error: %v", err)
}

View File

@ -186,6 +186,7 @@ func (kv *nopKV) TxnDeleteRange(txnID int64, key, end []byte) (n, rev int64, err
func (kv *nopKV) Compact(rev int64) error { return nil }
func (kv *nopKV) Hash() (uint32, error) { return 0, nil }
func (kv *nopKV) Snapshot() dstorage.Snapshot { return &fakeSnapshot{} }
func (kv *nopKV) Commit() {}
func (kv *nopKV) Restore() error { return nil }
func (kv *nopKV) Close() error { return nil }

View File

@ -69,6 +69,9 @@ type KV interface {
// Snapshot snapshots the full KV store.
Snapshot() Snapshot
// Commit commits txns into the underlying backend.
Commit()
Restore() error
Close() error
}

View File

@ -294,6 +294,8 @@ func (s *store) Snapshot() Snapshot {
return s.b.Snapshot()
}
func (s *store) Commit() { s.b.ForceCommit() }
func (s *store) Restore() error {
s.mu.Lock()
defer s.mu.Unlock()