etcdserver: recover cluster when receiving newer snapshot

This commit is contained in:
Yicheng Qin 2014-11-14 11:45:03 -08:00
parent dfaa7290c4
commit 77433ff6da
3 changed files with 14 additions and 0 deletions

View File

@ -267,6 +267,10 @@ func (c *Cluster) SetID(id types.ID) { c.id = id }
func (c *Cluster) SetStore(st store.Store) { c.store = st }
func (c *Cluster) Recover() {
c.members, c.removed = membersFromStore(c.store)
}
// ValidateConfigurationChange takes a proposed ConfChange and
// ensures that it is still valid.
func (c *Cluster) ValidateConfigurationChange(cc raftpb.ConfChange) error {

View File

@ -354,6 +354,7 @@ func (s *EtcdServer) run() {
if err := s.store.Recovery(rd.Snapshot.Data); err != nil {
log.Panicf("recovery store error: %v", err)
}
s.Cluster.Recover()
appliedi = rd.Snapshot.Index
}
// TODO(bmizerany): do this in the background, but take

View File

@ -901,11 +901,14 @@ func TestRecvSnapshot(t *testing.T) {
n := newReadyNode()
st := &storeRecorder{}
p := &storageRecorder{}
cl := newCluster("abc")
cl.SetStore(store.New())
s := &EtcdServer{
store: st,
sender: &nopSender{},
storage: p,
node: n,
Cluster: cl,
}
s.start()
@ -930,11 +933,14 @@ func TestRecvSnapshot(t *testing.T) {
func TestRecvSlowSnapshot(t *testing.T) {
n := newReadyNode()
st := &storeRecorder{}
cl := newCluster("abc")
cl.SetStore(store.New())
s := &EtcdServer{
store: st,
sender: &nopSender{},
storage: &storageRecorder{},
node: n,
Cluster: cl,
}
s.start()
@ -958,11 +964,14 @@ func TestRecvSlowSnapshot(t *testing.T) {
func TestApplySnapshotAndCommittedEntries(t *testing.T) {
n := newReadyNode()
st := &storeRecorder{}
cl := newCluster("abc")
cl.SetStore(store.New())
s := &EtcdServer{
store: st,
sender: &nopSender{},
storage: &storageRecorder{},
node: n,
Cluster: cl,
}
s.start()