Ejemplo n.º 1
0
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
}
Ejemplo n.º 2
0
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
}
Ejemplo n.º 3
0
// 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
}
Ejemplo n.º 4
0
// 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
}
Ejemplo n.º 5
0
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
}
func (pn *paxosNode) GetNextProposalNumber(args *paxosrpc.ProposalNumberArgs, reply *paxosrpc.ProposalNumberReply) error {
	reply.N = pn.logicTime*pn.timeFactor + pn.id
	return nil
}
Ejemplo n.º 7
0
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
}