當前位置: 首頁>>代碼示例>>Golang>>正文


Golang paxosrpc.ProposalNumberReply類代碼示例

本文整理匯總了Golang中github.com/cmu440-F15/paxosapp/rpc/paxosrpc.ProposalNumberReply的典型用法代碼示例。如果您正苦於以下問題:Golang ProposalNumberReply類的具體用法?Golang ProposalNumberReply怎麽用?Golang ProposalNumberReply使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ProposalNumberReply類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: GetNextProposalNumber

func (pn *paxosNode) GetNextProposalNumber(args *paxosrpc.ProposalNumberArgs, reply *paxosrpc.ProposalNumberReply) error {
	pn.propNumLock.Lock()
	defer pn.propNumLock.Unlock()

	reply.N = pn.nodePropNum
	pn.nodePropNum += pn.numNodes
	return nil
}
開發者ID:mallocanswer,項目名稱:Draw-Together,代碼行數:8,代碼來源:paxos_impl.go

示例2: GetNextProposalNumber

func (pn *paxosNode) GetNextProposalNumber(args *paxosrpc.ProposalNumberArgs, reply *paxosrpc.ProposalNumberReply) error {
	key := args.Key
	var n int
	if m, found := pn.highestSeen[key]; found {
		n = (m/pn.numNodes+1)*pn.numNodes + pn.nodeID
	} else {
		n = pn.nodeID
	}
	pn.highestSeen[key] = n
	reply.N = n
	return nil
}
開發者ID:bwoka,項目名稱:p3,代碼行數:12,代碼來源:paxos_impl.go

示例3: GetNextProposalNumber

// GetNextProposalNumber generates a proposal number which will be passed to
// Propose. Proposal numbers should not repeat, and for a particular node
// they should be strictly increasing.
func (pn *paxosNode) GetNextProposalNumber(args *paxosrpc.ProposalNumberArgs, reply *paxosrpc.ProposalNumberReply) error {
	// Will just give the Max([Nh/k]*k + id , )
	key := args.Key
	pxi := pn.getInstance(key)

	pxi.mu.RLock()
	defer pxi.mu.RUnlock()

	replyN := (pxi.Nh/pn.numNodes+1)*pn.numNodes + pn.id
	reply.N = replyN

	return nil
}
開發者ID:harouwu,項目名稱:p3,代碼行數:16,代碼來源:paxos_impl.go

示例4: GetNextProposalNumber

// This function is used to generate the next proposal number given the user input
func (pn *paxosNode) GetNextProposalNumber(args *paxosrpc.ProposalNumberArgs, reply *paxosrpc.ProposalNumberReply) error {
	fmt.Println("get number")
	key := args.Key
	pNumber, ok := pn.pNumberMap[key]
	if !ok {
		pNumber = -1
	}

	newNumber := pNumber + 1
	reply.N = newNumber*pn.numNodes + pn.srvId
	pn.pNumberMap[key] = newNumber
	fmt.Println("getnumber: ", reply.N)
	return nil
}
開發者ID:YuchengZ,項目名稱:CodingSample,代碼行數:15,代碼來源:paxos_impl.go

示例5: GetNextProposalNumber

func (pn *paxosNode) GetNextProposalNumber(args *paxosrpc.ProposalNumberArgs, reply *paxosrpc.ProposalNumberReply) error {
	// just increment the clock and calculate the proposal number
	N_my, ok1 := pn.clockMap[args.Key]
	N_h, ok2 := pn.maxpropMap[args.Key]
	highest_time := 0
	if ok1 && ok2 {
		if N_my > N_h/pn.numNodes {
			highest_time = N_my
		} else {
			highest_time = N_h / pn.numNodes
		}
	} else if ok1 {
		highest_time = N_my
	} else if ok2 {
		highest_time = N_h / pn.numNodes
	}
	pn.clockMap[args.Key] = highest_time + 1
	reply.N = pn.clockMap[args.Key]*pn.numNodes + pn.id
	return nil
}
開發者ID:jbuckman,項目名稱:p3-440,代碼行數:20,代碼來源:paxos_impl.go

示例6: GetNextProposalNumber

func (pn *paxosNode) GetNextProposalNumber(args *paxosrpc.ProposalNumberArgs, reply *paxosrpc.ProposalNumberReply) error {
	reply.N = pn.logicTime*pn.timeFactor + pn.id
	return nil
}
開發者ID:wentianqi7,項目名稱:15640-distributed-systems,代碼行數:4,代碼來源:paxos_impl.go

示例7: GetNextProposalNumber

func (pn *paxosNode) GetNextProposalNumber(args *paxosrpc.ProposalNumberArgs, reply *paxosrpc.ProposalNumberReply) error {
	key := args.Key
	pn.mutex.Lock()
	if pn.keyValueMutex[key] == nil {
		pn.keyValueMutex[key] = &sync.Mutex{}
	}
	pn.mutex.Unlock()
	// lock current key mutex
	pn.keyValueMutex[key].Lock()

	if pn.keyValue[key] == nil {
		pn.keyValue[key] = &value{
			Key:   key,
			Value: nil,
			N_a:   -1,
			N_h:   -1,
			my_n:  -1,
		}
	}

	val := pn.keyValue[key]
	my_n := val.my_n
	N_h := val.N_h
	// reply.N = math.Max(my_n, N_h) + 1
	if my_n > N_h {
		reply.N = my_n
	} else {
		reply.N = N_h
	}
	// fmt.Println("GetNextProposalNumber", reply.N, my_n, N_h)
	reply.N = (reply.N+pn.numNodes-pn.nodeID)/pn.numNodes*pn.numNodes + pn.nodeID
	pn.keyValueMutex[key].Unlock()

	// fmt.Println("my_n", my_n, "N_h", N_h, "replyN", reply.N)
	tempValue := pn.keyValue[args.Key]
	tempValue.my_n = reply.N
	pn.keyValue[args.Key] = tempValue

	if pn.savedkeyValue[key] == nil {
		pn.savedkeyValue[key] = &value{
			Key:   args.Key,
			Value: nil,
			N_a:   -1,
			N_h:   -1,
			my_n:  -1,
		}
	}
	retChan := make(chan int, 1)
	// proposalNumberArgs := &paxosrpc.ProposalNumberArgs{
	// 	Key: args.Key,
	// }
	// proposalNumberReply := &paxosrpc.ProposalNumberReply{}
	// pn.GetNextProposalNumber(proposalNumberArgs, proposalNumberReply)
	// fmt.Println("get new proposal number", proposalNumberReply.N)
	newArgs := &paxosrpc.ProposeArgs{
		Key: args.Key,
		N:   reply.N,
		V:   nil,
	}
	// fmt.Println("Prepare phase")
	for nodeID, hostPort := range pn.hostMap {
		pn.ProposeByNode(nodeID, hostPort, newArgs, retChan)
		<-retChan
	}
	return nil
}
開發者ID:thuhujin,項目名稱:Paxos,代碼行數:66,代碼來源:paxos_impl.go


注:本文中的github.com/cmu440-F15/paxosapp/rpc/paxosrpc.ProposalNumberReply類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。