// RecoverCheckpoint restores last known election state from a checkpoint // record. func (this *Election) RecoverCheckpoint(uid string, data []byte) error { if uid != this.uid { // Check if uid belongs to one of our paxos instances. if this.IsPaxosUID(uid) { paxos, errGet := this.doGetPaxosInstance(uid) if errGet != nil { this.Errorf("could not find paxos instance for %s: %v", uid, errGet) return errGet } return paxos.RecoverCheckpoint(uid, data) } this.Errorf("checkpoint record doesn't belong to this instance") return errs.ErrInvalid } walRecord := thispb.WALRecord{} if err := proto.Unmarshal(data, &walRecord); err != nil { this.Errorf("could not parse checkpoint wal record: %v", err) return err } if walRecord.Checkpoint == nil { this.Errorf("checkpoint record has no data") return errs.ErrCorrupt } checkpoint := walRecord.GetCheckpoint() this.doRestoreConfig(checkpoint.GetConfiguration()) if this.InCommittee() { if checkpoint.CommitteeState == nil { this.Errorf("committee member checkpoint has no election state") return errs.ErrCorrupt } this.doRestoreCommittee(checkpoint.GetCommitteeState()) } this.doRestoreElection(checkpoint.GetElectionState()) return nil }