• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang paxosrpc.AcceptReply类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang paxosrpc.GetValueReply类代码示例发布时间:2022-05-23
下一篇:
Golang treegen.TestTree函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap