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


Golang paxosrpc.AcceptReply類代碼示例

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


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

示例1: RecvAccept

// When a node receive an accept message
// It will compare the highest number it has seen with the number in the message
// If the number in the message is higher, accept the message and update the information
// If not, set status as reject
func (pn *paxosNode) RecvAccept(args *paxosrpc.AcceptArgs, reply *paxosrpc.AcceptReply) error {
	recvKey := args.Key
	recvNum := args.N

	pn.propNum.propNumLock.Lock()
	pn.acceptValue.acceptMapLock.Lock()
	defer pn.acceptValue.acceptMapLock.Unlock()
	defer pn.propNum.propNumLock.Unlock()

	if propNum, ok := pn.propNum.propNum[recvKey]; ok {
		if recvNum < propNum {
			reply.Status = paxosrpc.Reject
		} else {
			pn.propNum.propNum[recvKey] = recvNum
			pn.acceptValue.acceptValue[recvKey] = args.V
			pn.acceptValue.acceptNum[recvKey] = args.N
			reply.Status = paxosrpc.OK
		}
	} else {
		pn.propNum.propNum[recvKey] = recvNum
		pn.acceptValue.acceptValue[recvKey] = args.V
		pn.acceptValue.acceptNum[recvKey] = args.N
		reply.Status = paxosrpc.OK
	}
	return nil
}
開發者ID:mallocanswer,項目名稱:Draw-Together,代碼行數:30,代碼來源:paxos_impl.go

示例2: RecvAccept

func (pn *paxosNode) RecvAccept(args *paxosrpc.AcceptArgs, reply *paxosrpc.AcceptReply) error {
	if _, ok := pn.highestSeen[args.Key]; !ok {
		pn.highestSeen[args.Key] = -1
	}

	if pn.highestSeen[args.Key] > args.N {
		reply.Status = paxosrpc.Reject
		return nil
	}
	pn.highestSeen[args.Key] = args.N
	pn.na[args.Key] = args.N
	pn.va[args.Key] = args.V
	reply.Status = paxosrpc.OK
	return nil
}
開發者ID:bwoka,項目名稱:p3,代碼行數:15,代碼來源:paxos_impl.go

示例3: RecvAccept

// recieve accept request
func (pn *paxosNode) RecvAccept(args *paxosrpc.AcceptArgs, reply *paxosrpc.AcceptReply) error {
	key := args.Key
	number := args.N
	value := args.V

	np := pn.npMap[key]

	// decide give the vote or not
	if number >= np {
		pn.vaMap[key] = value
		pn.naMap[key] = number
		reply.Status = paxosrpc.OK
	} else {
		reply.Status = paxosrpc.Reject
	}
	return nil
}
開發者ID:YuchengZ,項目名稱:CodingSample,代碼行數:18,代碼來源:paxos_impl.go

示例4: RecvAccept

func (pn *paxosNode) RecvAccept(args *paxosrpc.AcceptArgs, reply *paxosrpc.AcceptReply) error {
	// update current logic time
	if pn.logicTime <= args.N/pn.timeFactor {
		pn.logicTime = args.N/pn.timeFactor + 1
	}

	// check if accept the prepare rpc
	if args.N < pn.nhMap[args.Key] {
		reply.Status = paxosrpc.Reject
	} else {
		pn.nhMap[args.Key] = args.N
		pn.naMap[args.Key] = args.N
		pn.vaMap[args.Key] = args.V
		reply.Status = paxosrpc.OK
	}
	return nil
}
開發者ID:wentianqi7,項目名稱:15640-distributed-systems,代碼行數:17,代碼來源:paxos_impl.go

示例5: RecvAccept

func (pn *paxosNode) RecvAccept(args *paxosrpc.AcceptArgs, reply *paxosrpc.AcceptReply) error {
	key := args.Key
	N := args.N
	V := args.V
	N_h, ok := pn.maxpropMap[key]
	//pn.acceptMutex.Lock()
	//prop, ok := pn.acceptMap[key]
	//pn.acceptMutex.Unlock()
	if ok && N < N_h {
		reply.Status = paxosrpc.Reject
	} else {
		reply.Status = paxosrpc.OK
		p := proposal{N, V}
		pn.maxpropMap[key] = N
		pn.acceptMap[key] = &p
	}
	return nil

}
開發者ID:jbuckman,項目名稱:p3-440,代碼行數:19,代碼來源:paxos_impl.go

示例6: RecvAccept

func (pn *paxosNode) RecvAccept(args *paxosrpc.AcceptArgs, reply *paxosrpc.AcceptReply) error {
	key := args.Key
	N := args.N
	V := args.V

	// fmt.Println("recvaccept", pn.nodeID, args.Key, args.N, args.V)
	// find key mutex or create one
	pn.mutex.Lock()
	if pn.keyValueMutex[key] == nil {
		pn.keyValueMutex[key] = &sync.Mutex{}
	}
	pn.mutex.Unlock()
	// lock current key mutex
	pn.keyValueMutex[key].Lock()
	defer pn.keyValueMutex[key].Unlock()
	if pn.keyValue[key] == nil {
		pn.keyValue[key] = &value{
			Key:   key,
			Value: nil,
			N_a:   -1,
			N_h:   -1,
			my_n:  -1,
		}
	}
	// get value
	value := pn.keyValue[key]
	N_h := value.N_h
	// assign reply values
	if N < N_h {
		reply.Status = paxosrpc.Reject
	} else {
		reply.Status = paxosrpc.OK
		value.N_a = N
		// TODO
		value.N_h = N
		value.Value = V
		pn.keyValue[key] = value
	}
	return nil
}
開發者ID:thuhujin,項目名稱:Paxos,代碼行數:40,代碼來源:paxos_impl.go

示例7: RecvAccept

// Receive an Accept message from another Paxos Node. The message contains
// the key whose value is being proposed by the node sending the accept
// message. This function should respond with Status OK if the prepare is
// accepted and Reject otherwise.
func (pn *paxosNode) RecvAccept(args *paxosrpc.AcceptArgs, reply *paxosrpc.AcceptReply) error {
	// Upon receiving <accept, n, V>
	// If n < Nh
	//     reply with <accept-reject>
	// else
	//    Na = n; Va = V; Nh = n
	//     reply with <accept-ok>
	key := args.Key
	n := args.N
	v := args.V
	pxi := pn.getInstance(key)
	pxi.mu.Lock()
	defer pxi.mu.Unlock()
	if n < pxi.Nh {
		reply.Status = paxosrpc.Reject
	} else {
		pxi.Nh = n
		pxi.Na = n
		pxi.Va = v
		reply.Status = paxosrpc.OK
	}

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


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