当前位置: 首页>>代码示例>>Golang>>正文


Golang PrepareReply.V_a方法代码示例

本文整理汇总了Golang中github.com/cmu440-F15/paxosapp/rpc/paxosrpc.PrepareReply.V_a方法的典型用法代码示例。如果您正苦于以下问题:Golang PrepareReply.V_a方法的具体用法?Golang PrepareReply.V_a怎么用?Golang PrepareReply.V_a使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cmu440-F15/paxosapp/rpc/paxosrpc.PrepareReply的用法示例。


在下文中一共展示了PrepareReply.V_a方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: RecvPrepare

// It will check whether the key is in the storage
// If so, return the value and set status as KeyFound
// If not, set status as Key Not Found
func (pn *paxosNode) RecvPrepare(args *paxosrpc.PrepareArgs, reply *paxosrpc.PrepareReply) error {
	recvKey := args.Key
	recvNum := args.N

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

	if propNum, ok := pn.propNum.propNum[recvKey]; ok {
		if recvNum < propNum {
			reply.Status = paxosrpc.Reject
			reply.N_a = -1
		} else {
			reply.Status = paxosrpc.OK
			pn.propNum.propNum[recvKey] = recvNum
			pn.acceptValue.acceptMapLock.Lock()
			if acc_v, ok := pn.acceptValue.acceptValue[recvKey]; ok {
				reply.V_a = acc_v
				reply.N_a = pn.acceptValue.acceptNum[recvKey]
			} else {
				reply.V_a = nil
				reply.N_a = -1
			}
			pn.acceptValue.acceptMapLock.Unlock()
		}
	} else {
		pn.propNum.propNum[recvKey] = recvNum
		reply.Status = paxosrpc.OK
		reply.N_a = -1
	}
	return nil
}
开发者ID:mallocanswer,项目名称:Draw-Together,代码行数:34,代码来源:paxos_impl.go

示例2: RecvPrepare

// Receive a Prepare message from another Paxos Node. The message contains
// the key whose value is being proposed by the node sending the prepare
// message. This function should respond with Status OK if the prepare is
// accepted and Reject otherwise.
func (pn *paxosNode) RecvPrepare(args *paxosrpc.PrepareArgs, reply *paxosrpc.PrepareReply) error {
	// Upon receiving <Prepare, n, V>
	// If n < Nh
	//     reply with <accept-reject, Na, Va>
	// else
	//    Na = n; Va = V; Nh = n
	//     reply with <accept-ok>
	key := args.Key
	n := args.N
	pxi := pn.getInstance(key)
	pxi.mu.Lock()
	defer pxi.mu.Unlock()
	//reject if request is with a proposal number less than the highest seen by this node for this key
	if n < pxi.Nh {
		reply.Status = paxosrpc.Reject
		reply.N_a = pxi.Na
		reply.V_a = pxi.Va
	} else {
		pxi.Nh = n
		reply.Status = paxosrpc.OK
		reply.N_a = pxi.Na
		reply.V_a = pxi.Va
		if reply.V_a == nil {
			reply.N_a = -1
		}
	}

	return nil
}
开发者ID:harouwu,项目名称:p3,代码行数:33,代码来源:paxos_impl.go

示例3: RecvPrepare

// recieve prepare request
func (pn *paxosNode) RecvPrepare(args *paxosrpc.PrepareArgs, reply *paxosrpc.PrepareReply) error {
	key := args.Key
	number := args.N
	value, ok := pn.vaMap[key]
	// first see if the key is a new key or not
	if !ok {
		value = nil
	}
	nk, ok := pn.naMap[key]
	if !ok {
		nk = -1
	}

	np, ok := pn.npMap[key]

	if !ok {
		np = -1
		pn.npMap[key] = np
	}

	// do prepare, decide give the vote or not
	if number > np {
		pn.npMap[key] = number
		reply.Status = paxosrpc.OK

		reply.N_a = nk
		reply.V_a = value
	} else {
		reply.Status = paxosrpc.Reject
	}
	return nil
}
开发者ID:YuchengZ,项目名称:CodingSample,代码行数:33,代码来源:paxos_impl.go

示例4: RecvPrepare

func (pn *paxosNode) RecvPrepare(args *paxosrpc.PrepareArgs, reply *paxosrpc.PrepareReply) error {
	if _, ok := pn.highestSeen[args.Key]; !ok {
		pn.highestSeen[args.Key] = -1
	}
	if pn.highestSeen[args.Key] > args.N {
		reply.Status = paxosrpc.Reject
		reply.N_a = -1
		reply.V_a = nil

		return nil
	}
	if _, ok := pn.na[args.Key]; !ok {
		pn.na[args.Key] = -1
		pn.va[args.Key] = nil
	}
	pn.highestSeen[args.Key] = args.N
	reply.Status = paxosrpc.OK
	reply.N_a = pn.na[args.Key]
	reply.V_a = pn.va[args.Key]

	return nil
}
开发者ID:bwoka,项目名称:p3,代码行数:22,代码来源:paxos_impl.go

示例5: RecvPrepare

func (pn *paxosNode) RecvPrepare(args *paxosrpc.PrepareArgs, reply *paxosrpc.PrepareReply) error {
	key := args.Key
	N := args.N
	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 {
		pn.maxpropMap[key] = N
		reply.Status = paxosrpc.OK
		prop, ok := pn.acceptMap[key]
		if ok {
			reply.N_a = prop.N
			reply.V_a = prop.V
		} else {
			reply.N_a = -1
			reply.V_a = nil
		}
	}
	return nil
}
开发者ID:jbuckman,项目名称:p3-440,代码行数:23,代码来源:paxos_impl.go

示例6: RecvPrepare

func (pn *paxosNode) RecvPrepare(args *paxosrpc.PrepareArgs, reply *paxosrpc.PrepareReply) error {
	key := args.Key
	N := args.N

	// fmt.Println("recvprepare", pn.nodeID, args.N, args.Key)
	// 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()
	_, ok := pn.keyValue[key]
	if !ok {
		// fmt.Println("key not found", key)
		pn.keyValue[key] = &value{
			Key:   key,
			Value: nil,
			N_a:   -1,
			N_h:   -1,
			my_n:  -1,
		}
	} else {
		// fmt.Println("key found", key)
	}
	// get value
	value := pn.keyValue[key]
	// fmt.Println("recv prepare, before update", "my_n:", value.my_n, "my N_h:", value.N_h, "N:", N, "nodeID:", pn.nodeID)
	N_h := value.N_h
	// N_a := value.N_a
	// V_a := value.Value
	// assign reply values
	if N > N_h {
		reply.Status = paxosrpc.OK
		value.N_h = N
		// value.N_a = N
		pn.keyValue[key] = value
	} else {
		reply.Status = paxosrpc.Reject
	}
	reply.N_a = value.N_a
	reply.V_a = value.Value
	pn.keyValueMutex[key].Unlock()
	// fmt.Println("recvprepare unlock return", pn.nodeID, args.N, args.Key)

	return nil
}
开发者ID:thuhujin,项目名称:Paxos,代码行数:48,代码来源:paxos_impl.go

示例7: RecvPrepare

func (pn *paxosNode) RecvPrepare(args *paxosrpc.PrepareArgs, reply *paxosrpc.PrepareReply) 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
		reply.N_a = pn.naMap[args.Key]
		reply.V_a = pn.vaMap[args.Key]
		reply.Status = paxosrpc.OK
	}
	return nil
}
开发者ID:wentianqi7,项目名称:15640-distributed-systems,代码行数:17,代码来源:paxos_impl.go


注:本文中的github.com/cmu440-F15/paxosapp/rpc/paxosrpc.PrepareReply.V_a方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。