コード例 #1
0
ファイル: paxos.go プロジェクト: bvk/ascent
func (this *Paxos) doUpdateConfig(change *thispb.Configuration) error {
	if !this.wal.IsRecovering() {
		record := thispb.WALRecord{}
		record.ConfigChange = change
		_, errQueue := wal.QueueChangeProto(this.wal, this.uid, &record)
		if errQueue != nil {
			this.Errorf("could not append config change wal record: %v", errQueue)
			return errQueue
		}
	}

	this.doRestoreConfig(change)
	return nil
}
コード例 #2
0
ファイル: paxos.go プロジェクト: bvk/ascent
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
}
コード例 #3
0
ファイル: election.go プロジェクト: bvk/ascent
func (this *Election) doUpdateElection(change *thispb.ElectionChange) error {
	if !this.wal.IsRecovering() {
		walRecord := thispb.WALRecord{}
		walRecord.ElectionChange = change
		_, errQueue := wal.QueueChangeProto(this.wal, this.uid, &walRecord)
		if errQueue != nil {
			this.Errorf("could not write election change wal record: %v", errQueue)
			return errQueue
		}
	}

	atomic.StoreInt64(&this.currentRound, change.GetElectionRound())
	this.currentWinner = change.GetElectionWinner()
	return nil
}