Beispiel #1
0
func getOrCreateConsensus(associatedView *view.View) consensusInstance {
	consensusTableMu.Lock()
	defer consensusTableMu.Unlock()

	ci, ok := consensusTable[associatedView.NumberOfUpdates()]
	if !ok {
		ci = consensusInstance{associatedView: associatedView, taskChan: make(chan consensusTask, CHANNEL_DEFAULT_BUFFER_SIZE), callbackLearnChan: make(chan interface{}, 1)}
		//ci.startTime = time.Now()
		consensusTable[associatedView.NumberOfUpdates()] = ci
		log.Println("Created consensus instance:", ci)

		go consensusWorker(ci)
	}
	return ci
}
Beispiel #2
0
// getNextProposalNumber to be used by this process. This function is a stage of the Propose funcion.
func getNextProposalNumber(associatedView *view.View, thisProcess view.Process) (proposalNumber int) {
	if associatedView.NumberOfMembers() == 0 {
		log.Fatalln("associatedView is empty")
	}

	thisProcessPosition := associatedView.GetProcessPosition(thisProcess)

	lastProposalNumber, err := getLastProposalNumber(associatedView.NumberOfUpdates())
	if err != nil {
		proposalNumber = associatedView.NumberOfMembers() + thisProcessPosition
	} else {
		proposalNumber = (lastProposalNumber - (lastProposalNumber % associatedView.NumberOfMembers()) + associatedView.NumberOfMembers()) + thisProcessPosition
	}

	saveProposalNumberOnStorage(associatedView.NumberOfUpdates(), proposalNumber)
	return
}