Cluster_Attach

This sample demonstrates how to re-attach a node to a cluster using mco_cluster_attach(). The nodes begin and work together, then each node detaches and performs local database updates; then reconnects to the cluster.

How to Run

In a console window run:

 
    cluster_attach 2 0
     

Then in a second console window run:

 
    cluster_attach 2 1
 

But it is more instructive to run one instance in your development environment debugger, stepping through the code.

Pertinent code

 
    /* enables WRITE transaction  and create objects in detached database */
    mco_cluster_detach(db);
    {
        mco_trans_h t;
        Record rec;
        mco_trans_start(db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t);
        Record_new(t, &rec);
        Record_key_put(&rec, N_OBJECTS * 100 + cl_info.node_id);
        Record_value_put(&rec, 0);
        mco_trans_commit(t);
    }
    print_database(db, "Database content after local modifications : ");
    sample_sleep(1000);
 
    /* re-attach to cluster */
    rc = mco_cluster_attach(db, &cl_params);
            
    ...
    printf("Re-attached to cluster\n");
    sample_start_connected_task(&listener_task, ClusterListener, db_name, 0); /* restart listener thread */
     
    update_database(db, RUN_TIME / 2);
     
    /* stop cluster, wait for listener thread, print database content & statistic */
    mco_cluster_stop(db);
    sample_join_task(&listener_task);
    mco_cluster_info(db, &cl_info);
    print_database(db, "Database content after second mco_cluster_stop() (the same for all nodes) : ");
    printf("Bytes sent %" INT8_FORMAT "u, received %" INT8_FORMAT "u\n", cl_info.bytes_sent, cl_info.bytes_recv);
    ...
 

Related Topics Link IconRelated Topics