func (this *Paxos) doUpdateLearner(change *thispb.LearnerChange) error { if this.chosenValue != nil { return nil } if !this.wal.IsRecovering() { walRecord := thispb.WALRecord{} walRecord.LearnerChange = change _, errQueue := wal.QueueChangeProto(this.wal, this.uid, &walRecord) if errQueue != nil { this.Errorf("could not write learner change record: %v", errQueue) return errQueue } } if change.ChosenValue != nil { this.chosenValue = change.GetChosenValue() this.Infof("consensus result learned from proposer is %s", this.chosenValue) if this.watch != nil { this.watch.ConsensusUpdate(this.uid, -1, this.chosenValue) } return nil } acceptor := change.GetVotedAcceptor() for index := range change.VotedBallotList { ballot := change.VotedBallotList[index] value := change.VotedValueList[index] this.ballotValueMap[ballot] = value acceptorSet, found := this.ballotAcceptorsMap[ballot] if !found { acceptorSet = make(map[string]struct{}) this.ballotAcceptorsMap[ballot] = acceptorSet } acceptorSet[acceptor] = struct{}{} if len(acceptorSet) >= this.MajoritySize() { this.chosenValue = value this.Infof("consensus result learned through votes is %s", value) if this.watch != nil { this.watch.ConsensusUpdate(this.uid, -1, this.chosenValue) } } } return nil }