// RecoverChange updates election state from a change record. func (this *Election) RecoverChange(lsn wal.LSN, 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.RecoverChange(lsn, uid, data) } this.Errorf("change 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 change record: %v", err) return err } switch { case walRecord.ConfigChange != nil: this.doRestoreConfig(walRecord.GetConfigChange()) return nil case walRecord.CommitteeChange != nil: if !this.InCommittee() { this.Errorf("found committee change when instance is not a member") return errs.ErrCorrupt } return this.doUpdateCommittee(walRecord.GetCommitteeChange()) case walRecord.ElectionChange != nil: return this.doUpdateElection(walRecord.GetElectionChange()) default: this.Errorf("invalid/unknown change record %s", walRecord) return errs.ErrInvalid } return nil }