This sample demonstrates how to re-attach a node to a cluster using
mco_cluster_attach(). The nodes begin and work together. Each node then detaches, performs local database updates, and reconnects to the cluster.
In a console window, run:
cluster_attach 2 0Then, in a second console window, run:
cluster_attach 2 1It is more instructive to run one instance in your development environment debugger, stepping through the code.
/* Enable a write transaction and create objects in the 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 the cluster, wait for the listener thread, and print database content and statistics. */ 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); ...