void 
vh_shutdown() {
    //Delete event
    event_del(&leader_msg_event);

    //Close socket and free receiver
    udp_receiver_destroy(for_leader);
    
    //All values in pending could not be delivered yet.
    // Notify the respective clients
    vh_value_wrapper * vw;
    while ((vw = vh_get_next_pending()) != NULL) {
        vh_notify_client(-1, vw);
        PAX_FREE(vw);        
    }
}
Example #2
0
static void
leader_execute_p2(p_inst_info * ii) {
    
    if(ii->p1_value == NULL && ii->p2_value == NULL) {
        //Happens when p1 completes without value        
        //Assign a p2_value and execute
        ii->p2_value = vh_get_next_pending();
        assert(ii->p2_value != NULL);
        
    } else if (ii->p1_value != NULL) {
        //Only p1 value is present, MUST execute p2 with it
        //Save it as p2 value and execute
        ii->p2_value = ii->p1_value;
        ii->p1_value = NULL;
        ii->p1_value_ballot = 0;
        
    } else if (ii->p2_value != NULL) {
        // Only p2 valye is present
        //Do phase 2 with it
        
    } else {
        // There are both p1 and p2 value
        //Compare them
        if(vh_value_compare(ii->p1_value, ii->p2_value) == 0) {
            // Same value, just delete p1_value
            PAX_FREE(ii->p1_value);
            ii->p1_value = NULL;
            ii->p1_value_ballot = 0;
        } else {
            // Different values
            // p2_value is pushed back to pending list
            vh_push_back_value(ii->p2_value);
            // Must execute p2 with p1 value
            ii->p2_value = ii->p1_value;
            ii->p1_value = NULL;
            ii->p1_value_ballot = 0;            
        }
    }
    //Change instance status
    ii->status = p2_pending;

    //Send the accept request
    sendbuf_add_accept_req(to_acceptors, ii->iid, ii->my_ballot, ii->p2_value->value, ii->p2_value->value_size);
    
    //Set the deadline for this instance
    leader_set_expiration(ii, P2_TIMEOUT_INTERVAL);
}