Esempio n. 1
0
static void
leader_shutdown() {
    LOG(0, ("Proposer %d dropping leadership\n", this_proposer_id));

    evtimer_del(&p1_check_event);
    evtimer_del(&p2_check_event);
    
#ifdef LEADER_EVENTS_UPDATE_INTERVAL
    evtimer_del(&print_events_event);
#endif

    //Iterate over currently open instances 
    p_inst_info * ii;
    unsigned int i;
    for(i = current_iid; i <= p1_info.highest_open; i++) {
        ii = GET_PRO_INSTANCE(i);
        
        if(ii->status != p2_completed && ii->p2_value != NULL) {
            // A value was assigned to this instance, but it did 
            // not complete. Send back to the pending list for now
            vh_push_back_value(ii->p2_value);
            ii->p2_value = NULL;
        }
        //Clear all instances
        pro_clear_instance_info(ii);
    }
        
    //This will clear all values in the pending list
    // and notify the respective clients
    vh_shutdown();
}
Esempio n. 2
0
/*-------------------------------------------------------------------------*/
static void 
leader_deliver(char * value, size_t size, iid_t iid, ballot_t ballot, int proposer) {
    UNUSED_ARG(ballot);
    UNUSED_ARG(proposer);
    LOG(DBG, ("Instance %lu delivered to Leader\n", iid));

    //Verify that the value is the one found or associated
    p_inst_info * ii = GET_PRO_INSTANCE(iid);
    //Instance not even initialized, skip
    if(ii->iid != iid) {
        return;
    }
    
    if(ii->status == p1_pending) {
        p1_info.pending_count -= 1;
    }
    
    if(p2_info.next_unused_iid == iid) {
        p2_info.next_unused_iid += 1;
    }
    
    int opened_by_me = (ii->status == p1_pending && ii->p2_value != NULL) ||
        (ii->status == p1_ready && ii->p2_value != NULL) ||
        (ii->status == p2_pending);
    if(opened_by_me) {
        p2_info.open_count -= 1;
    }

    int my_val = (ii->p2_value != NULL) &&
        (ii->p2_value->value_size == size) &&
        (memcmp(value, ii->p2_value->value, size) == 0);

    if(my_val) {
    //Our value accepted, notify client that submitted it
        vh_notify_client(0, ii->p2_value);
    } else if(ii->p2_value != NULL) {
    //Different value accepted, push back our value
        vh_push_back_value(ii->p2_value);
        ii->p2_value = NULL;
    } else {
        //We assigned no value to this instance, 
        //it comes from somebody else??
    }

    //Clear current instance
    pro_clear_instance_info(ii);
    
    //If enough instances are ready to 
    // be opened, start phase2 for them
    leader_open_instances_p2_new();
}
Esempio n. 3
0
//Initialize structures
static int 
init_pro_structs() {
    //Check array size
    if ((PROPOSER_ARRAY_SIZE & (PROPOSER_ARRAY_SIZE -1)) != 0) {
        printf("Error: PROPOSER_ARRAY_SIZE is not a power of 2\n");
        return PROPOSER_ERROR;        
    }
    if (PROPOSER_ARRAY_SIZE <= PROPOSER_PREEXEC_WIN_SIZE) {
        printf("Error: PROPOSER_ARRAY_SIZE = %d is too small\n",
            PROPOSER_ARRAY_SIZE);
        return PROPOSER_ERROR;
    }
    
    // Clear the state array
    memset(proposer_state, 0, (sizeof(p_inst_info) * PROPOSER_ARRAY_SIZE));
    size_t i;
    for(i = 0; i < PROPOSER_ARRAY_SIZE; i++) {
        pro_clear_instance_info(&proposer_state[i]);
    }
    return 0;

}