mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcd: clean up snap
This commit is contained in:
parent
a28dc4559b
commit
5fdc124578
@ -152,24 +152,22 @@ func newParticipant(c *conf.Config, client *v2client, peerHub *peerHub, tickDura
|
||||
log.Printf("id=%x participant.snapload err=%s\n", p.id, err)
|
||||
return nil, err
|
||||
}
|
||||
var logIndex int64
|
||||
if s != nil {
|
||||
logIndex = s.Index
|
||||
}
|
||||
n, err := wal.Read(walDir, logIndex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.id = n.Id
|
||||
p.node.Node = raft.Recover(s, n.Id, n.Ents, n.State, defaultHeartbeat, defaultElection)
|
||||
p.apply(p.node.Next())
|
||||
log.Printf("id=%x participant.load path=%s snap=%+v state=\"%+v\" len(ents)=%d", p.id, p.cfg.DataDir, s, n.State, len(n.Ents))
|
||||
var snapIndex int64
|
||||
if s != nil {
|
||||
if err := p.Recovery(s.Data); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.Printf("id=%x participant.store.recovered index=%d\n", p.id, s.Index)
|
||||
snapIndex = s.Index
|
||||
}
|
||||
n, err := wal.Read(walDir, snapIndex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.id = n.Id
|
||||
p.node.Node = raft.Recover(n.Id, s, n.Ents, n.State, defaultHeartbeat, defaultElection)
|
||||
p.apply(p.node.Next())
|
||||
log.Printf("id=%x participant.load path=%s snap=%+v state=\"%+v\" len(ents)=%d", p.id, p.cfg.DataDir, s, n.State, len(n.Ents))
|
||||
if w, err = wal.Open(walDir); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ func New(id int64, heartbeat, election tick) *Node {
|
||||
return n
|
||||
}
|
||||
|
||||
func Recover(s *Snapshot, id int64, ents []Entry, state State, heartbeat, election tick) *Node {
|
||||
func Recover(id int64, s *Snapshot, ents []Entry, state State, heartbeat, election tick) *Node {
|
||||
n := New(id, heartbeat, election)
|
||||
if s != nil {
|
||||
n.sm.restore(*s)
|
||||
|
@ -192,7 +192,7 @@ func TestRecover(t *testing.T) {
|
||||
ents := []Entry{{Term: 1}, {Term: 2}, {Term: 3}}
|
||||
state := State{Term: 500, Vote: 1, Commit: 3}
|
||||
|
||||
n := Recover(nil, 0, ents, state, defaultHeartbeat, defaultElection)
|
||||
n := Recover(0, nil, ents, state, defaultHeartbeat, defaultElection)
|
||||
if g := n.Next(); !reflect.DeepEqual(g, ents) {
|
||||
t.Errorf("ents = %+v, want %+v", g, ents)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user