Example #1
0
// ConsensusUpdate implements paxos.Watcher interface.
func (this *Election) ConsensusUpdate(uid string, index int64, value []byte) {
	round := this.ElectionRoundFromPaxosUID(uid)
	if round <= this.CurrentRound() {
		return
	}
	winner := string(value)

	lock, errLock := this.ctlr.LockAll()
	if errLock != nil {
		return
	}
	defer lock.Unlock()

	change := thispb.ElectionChange{}
	change.ElectionRound = proto.Int64(round)
	change.ElectionWinner = proto.String(winner)
	if err := this.doUpdateElection(&change); err != nil {
		this.Fatalf("could not update new election round status: %v", err)
	}

	if this.InCommittee() {
		change := thispb.CommitteeChange{}
		change.NewElectionRound = proto.Int64(round)
		change.NewElectionWinner = proto.String(winner)
		if err := this.doUpdateCommittee(&change); err != nil {
			this.Fatalf("could not update committee with new election status: %v",
				err)
		}
	}
}