def handle_proposal(my_info, proposal):
    apply_proposal_to_ds(my_info, proposal)
    accept_msg = Accept(11, my_info.pid, proposal.view, proposal.seq)
    print("Made a Accept with view:{0} seq:{1}".format(proposal.view,
                                                       proposal.seq))
    # *** SYNC TO DISK
    send_to_all_servers(accept_msg, my_info.all_hosts)
def send_proposals(my_info):
    # Maybe we don't need the seq in myINfo?
    # my_info.seq = my_info.last_proposed + 1
    seq = my_info.last_proposed + 1

    if seq in my_info.global_history:
        if my_info.global_history[seq]['Globally_Ordered_Update'] is not None:
            my_info.last_proposed = my_info.last_proposed + 1
            send_proposals(my_info)

    if seq in my_info.global_history:
        if my_info.global_history[seq]['Proposal'] is not None:
            u = my_info.global_history[seq]['Proposal'].update
        elif not my_info.update_queue:
            return
        else:
            u = my_info.update_queue.pop()
    elif not my_info.update_queue:
        return
    else:
        u = my_info.update_queue.pop()

    proposal = Proposal(9, my_info.pid, my_info.last_installed, seq, u)
    print("Made a Proposal with view:{0} seq:{1} for update:{2}".format(
        my_info.last_installed, seq, u.update))
    apply_proposal_to_ds(my_info, proposal)
    my_info.last_proposed = seq
    my_info.seq = seq
    # **SYNC to disk
    write_to_file(my_info)
    print("Sending proposal to everyone now...")
    send_to_all_servers(proposal, my_info.all_hosts)
def shift_to_leader_election(view, all_hosts, my_info):
    # print("Shifted to leader election")
    my_info.state = LEADER_ELECTION
    clear_data_structures_for_vc(my_info)
    my_info.last_attempted = view
    vc = View_Change(2, my_info.pid, my_info.last_attempted)
    # print("Sending vc messages to everyone...")
    send_to_all_servers(vc, all_hosts)
    apply_vc_to_data_structures(vc, my_info)
Exemplo n.º 4
0
def thread_send_vc_proof(my_info, last_installed_queue, last_installed_view):
    # Send VC Proof messages to everyone
    # if my_info.last_installed == my_info.last_attempted:
    if not last_installed_queue.empty():
        last_installed = last_installed_queue.get()
    else:
        last_installed = last_installed_view
    # print("IN VC_PROOF SEND: Sending a vc_proof message with last_installed as:{0}".format(last_installed))
    vc_proof = VC_Proof(3, my_info.pid, last_installed)
    send_to_all_servers(vc_proof, all_hosts)
    threading.Timer(10.0, thread_send_vc_proof, args=(my_info, last_installed_queue, my_info.last_installed)).start()
def shift_to_prepare_phase(my_info, all_hosts):
    # print("In prepare phase, getting ready to send prepare to all servers...")
    my_info.last_installed = my_info.last_attempted
    prepare_msg = Prepare_Message(7, my_info.pid, my_info.last_installed,
                                  my_info.local_aru)
    update_prepare_to_data_structures(prepare_msg, my_info)
    data_list = construct_data_list(my_info, my_info.local_aru)
    prepare_ok = Prepare_OK(8, my_info.pid, my_info.last_installed, data_list)
    my_info.prepare_oks[my_info.pid] = prepare_ok
    my_info.last_enqueued.clear()
    write_to_file(my_info)
    send_to_all_servers(prepare_msg, all_hosts)
Exemplo n.º 6
0
def handleProposal(proposal_message,server_info,all_hosts):

	#apply proposal message to Data Structure
	applyProposalToDS(proposal_message,server_info)

	#construct Accept message
	acceptMessage = Accept(11,server_info.pid,proposal_message.view,proposal_message.seq)

	## synch to disc ##
	## write central data or proposal message?
	## writeToFile()

	#Send accept message to all Servers
	send_to_all_servers(acceptMessage,all_hosts)
def send_periodic_reconciliation_message(my_info):
    reconciliation_message = Periodic_Reconciliation(16, my_info.pid,
                                                     my_info.local_aru)
    send_to_all_servers(reconciliation_message, my_info.all_hosts)