Ejemplo n.º 1
0
def receiveAccepted(accepted):
    global acceptedAccepted
    acceptedAccepted.append(accepted)

    # Require a majority
    if len(acceptedAccepted) >= majority:
        # If we have majority, check if any of the acc-messages has a proposal ID higher than the local
        # If so, restart proposal
        for accepted in acceptedAccepted:
            if accepted['proposalID'] > proposalID:
                acceptedAccepted = []  # resets the list
                return "RESTART"
        acceptedAccepted = []
        acceptor.receiveDecide(myValue)
        return myValue
    return None
Ejemplo n.º 2
0
def receiveAccepted(accepted):
	global acceptedAccepted
	acceptedAccepted.append(accepted)

	# Require a majority
	if len(acceptedAccepted) >= majority: 
		# If we have majority, check if any of the acc-messages has a proposal ID higher than the local
		# If so, restart proposal
		for accepted in acceptedAccepted:
			if accepted['proposalID'] > proposalID:
				acceptedAccepted = []	# resets the list
				return "RESTART"
		acceptedAccepted = []
		acceptor.receiveDecide(myValue)
		return myValue
	return None
Ejemplo n.º 3
0
                                        {'value': reply}))  #reply is a string

                                    if not posts:
                                        paxosRunning = False
                                    else:
                                        post = posts.pop(0)
                                        proposemessage = json.dumps(
                                            proposer.prepare(post))
                                        broadcast("PROPOSE:" + proposemessage)

                            # Else if we have received a decide-message, a value has been decided, forward
                            # to acceptor which stores the value in the log
                            elif data[0:7] == "DECIDE:":
                                result = data[7:]  #result is a string
                                post = json.loads(result)['value']
                                acceptor.receiveDecide(post)

                else:
                    # If we have received a read-message return the log as a string
                    if receivedData[0:4] == "READ":
                        result = acceptor.receiveRead()
                        s.send(result)

                    # Else if we have received a end-message, end this connection
                    elif receivedData[0:3] == "END":
                        s.send('GOODBYE')
                        connections.remove(s)
                        s.close()
                        print 'Removed'
                        break
Ejemplo n.º 4
0
									if not posts:
										paxosRunning = False
									else:
										post = posts.pop(0)
										proposemessage = json.dumps(proposer.prepare(post))
										broadcast("PROPOSE:"+proposemessage)



							# Else if we have received a decide-message, a value has been decided, forward
							# to acceptor which stores the value in the log
							elif data[0:7] == "DECIDE:":
								result = data[7:] #result is a string
								post = json.loads(result)['value']
								acceptor.receiveDecide(post)

				else:
					# If we have received a read-message return the log as a string
					if receivedData[0:4] == "READ":
						result = acceptor.receiveRead()
						s.send(result)


					# Else if we have received a end-message, end this connection
					elif receivedData[0:3] == "END":
						s.send('GOODBYE')
						connections.remove(s)
						s.close()
						print 'Removed'
						break