Esempio n. 1
0
File: paxos.go Progetto: bvk/ascent
func (this *Paxos) doRestoreLearner(state *thispb.LearnerState) {
	if state.ChosenValue != nil {
		this.chosenValue = state.GetChosenValue()
		return
	}

	for index := range state.VotedBallotList {
		ballot := state.VotedBallotList[index]
		value := state.VotedValueList[index]
		acceptor := state.VotedAcceptorList[index]

		// Ballot numbers can repeat in the list, but corresponding value is stored
		// only once. So, we may find nils in the state.VotedValueList.
		if value != nil {
			this.ballotValueMap[ballot] = value
		}

		acceptorSet, found := this.ballotAcceptorsMap[ballot]
		if !found {
			acceptorSet = make(map[string]struct{})
			this.ballotAcceptorsMap[ballot] = acceptorSet
		}
		acceptorSet[acceptor] = struct{}{}
	}
}
Esempio n. 2
0
File: paxos.go Progetto: bvk/ascent
func (this *Paxos) doSaveLearner(state *thispb.LearnerState) {
	if this.chosenValue != nil {
		state.ChosenValue = append([]byte{}, this.chosenValue...)
		return
	}

	for ballot, acceptorSet := range this.ballotAcceptorsMap {
		votedValue := append([]byte{}, this.ballotValueMap[ballot]...)
		for acceptor := range acceptorSet {
			state.VotedBallotList = append(state.VotedBallotList, ballot)
			state.VotedAcceptorList = append(state.VotedAcceptorList, acceptor)
			state.VotedValueList = append(state.VotedValueList, votedValue)

			// Store only one copy of the ballot value for each unique ballot.
			votedValue = nil
		}
	}
}