Пример #1
0
func (i *instance) OneATxnVotesReceived(proposal *msgs.TxnVoteProposal, promise *msgs.TxnVotePromise) {
	promise.SetRoundNumber(proposal.RoundNumber())
	roundNumber := paxosNumber(proposal.RoundNumber())
	if roundNumber >= i.promiseNum {
		i.promiseNum = roundNumber
		if i.accepted == nil {
			promise.SetFreeChoice()
		} else {
			promise.SetAccepted()
			accepted := promise.Accepted()
			accepted.SetRoundNumber(uint64(i.acceptedNum))
			accepted.SetBallot(*i.accepted)
		}
	} else {
		promise.SetRoundNumberTooLow(uint32(i.promiseNum >> 32))
	}
}
Пример #2
0
func (oneB *proposalOneB) oneBTxnVotesReceived(sender common.RMId, promise *msgs.TxnVotePromise) {
	roundNumber := paxosNumber(promise.RoundNumber())
	if oneB.currentState != oneB || roundNumber < oneB.currentRoundNumber {
		return
	}
	switch promise.Which() {
	case msgs.TXNVOTEPROMISE_ROUNDNUMBERTOOLOW:
		roundNumber = paxosNumber((uint64(promise.RoundNumberTooLow()+1) << 32) | uint64(oneB.proposerManager.RMId))
		if roundNumber > oneB.currentRoundNumber {
			oneB.currentRoundNumber = roundNumber
			oneB.oneASender.instanceComplete(oneB.proposalInstance)
			oneB.oneASender = nil
			oneB.nextState(&oneB.proposalOneA)
			return
		}
	case msgs.TXNVOTEPROMISE_FREECHOICE:
		// do nothing
	case msgs.TXNVOTEPROMISE_ACCEPTED:
		accepted := promise.Accepted()
		if roundNumber = paxosNumber(accepted.RoundNumber()); roundNumber > oneB.winningRound {
			oneB.winningRound = roundNumber
			ballot := accepted.Ballot()
			oneB.winningBallot = &ballot
		}
	default:
		panic(fmt.Sprintf("Unexpected promise type: %v", promise.Which()))
	}
	found := false
	for _, rmId := range oneB.promisesReceivedFrom {
		if found = rmId == sender; found {
			break
		}
	}
	if !found {
		oneB.promisesReceivedFrom = append(oneB.promisesReceivedFrom, sender)
		if len(oneB.promisesReceivedFrom) == oneB.fInc {
			oneB.oneASender.instanceComplete(oneB.proposalInstance)
			oneB.oneASender = nil
			oneB.nextState(nil)
		}
	}
}