mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver: restore KV snapshot when receiving snapshot
When a slow follower receives the snapshot sent from the leader, it should rename the snapshot file to the default KV file path, and restore KV snapshot. Have tested it manually and it works pretty well.
This commit is contained in:
parent
d33c26c20a
commit
cacc0d6432
@ -493,6 +493,23 @@ func (s *EtcdServer) run() {
|
||||
apply.snapshot.Metadata.Index, appliedi)
|
||||
}
|
||||
|
||||
if s.cfg.V3demo {
|
||||
if err := s.kv.Close(); err != nil {
|
||||
plog.Panicf("close KV error: %v", err)
|
||||
}
|
||||
snapfn, err := s.r.raftStorage.snapStore.getSnapFilePath(apply.snapshot.Metadata.Index)
|
||||
if err != nil {
|
||||
plog.Panicf("get snapshot file path error: %v", err)
|
||||
}
|
||||
fn := path.Join(s.cfg.StorageDir(), databaseFilename)
|
||||
if err := os.Rename(snapfn, fn); err != nil {
|
||||
plog.Panicf("rename snapshot file error: %v", err)
|
||||
}
|
||||
s.kv = dstorage.New(fn)
|
||||
if err := s.kv.Restore(); err != nil {
|
||||
plog.Panicf("restore KV error: %v", err)
|
||||
}
|
||||
}
|
||||
if err := s.store.Recovery(apply.snapshot.Data); err != nil {
|
||||
plog.Panicf("recovery store error: %v", err)
|
||||
}
|
||||
|
@ -836,6 +836,7 @@ func TestRecvSnapshot(t *testing.T) {
|
||||
cl := newCluster("abc")
|
||||
cl.SetStore(store.New())
|
||||
s := &EtcdServer{
|
||||
cfg: &ServerConfig{},
|
||||
r: raftNode{
|
||||
Node: n,
|
||||
transport: &nopTransporter{},
|
||||
@ -871,6 +872,7 @@ func TestApplySnapshotAndCommittedEntries(t *testing.T) {
|
||||
cl.SetStore(store.New())
|
||||
storage := newRaftStorage()
|
||||
s := &EtcdServer{
|
||||
cfg: &ServerConfig{},
|
||||
r: raftNode{
|
||||
Node: n,
|
||||
storage: &storageRecorder{},
|
||||
|
Loading…
x
Reference in New Issue
Block a user