当前位置: 首页>>代码示例>>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;未经允许,请勿转载。