Beispiel #1
0
func (s *Server) generateViewSequenceWithConsensus(associatedView *view.View, seq ViewSeq) {
	assertOnlyUpdatedViews(associatedView, seq)

	if associatedView.GetProcessPosition(s.thisProcess) == CONSENSUS_LEADER_PROCESS_POSITION {
		consensus.Propose(associatedView, s.thisProcess, &seq)
	}
	log.Println("Waiting for consensus resolution")
	value := <-consensus.GetConsensusResultChan(associatedView)

	// get startReconfigurationTime to compute reconfiguration duration
	//if startReconfigurationTime.IsZero() || startReconfigurationTime.Sub(time.Now()) > 20*time.Second {
	//startReconfigurationTime = consensus.GetConsensusStartTime(associatedView)
	//log.Println("starttime :", startReconfigurationTime)
	//}

	result, ok := value.(*ViewSeq)
	if !ok {
		log.Fatalf("FATAL: consensus on generateViewSequenceWithConsensus got %T %v\n", value, value)
	}
	log.Println("Consensus result received")

	s.generatedViewSeqChan <- generatedViewSeq{
		AssociatedView: associatedView,
		ViewSeq:        *result,
	}
}
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
}