/***********************
* GET RECOVERY MASTER *
***********************/
-static void
-ctdb_getrecmaster_recv_cb(struct ctdb_client_control_state *state)
-{
- struct ctdb_control_cb_data *cb_data = state->async.private_data;
- ctdb_getrecmaster_cb callback = (ctdb_getrecmaster_cb)cb_data->callback;
-
- if (state->state != CTDB_CONTROL_DONE) {
- DEBUG(DEBUG_ERR, (__location__ " ctdb_getrecmaster_recv_cb failed with state:%d\n", state->state));
- callback(-1, 0, cb_data->private_data);
- return;
- }
-
- callback(0, state->status, cb_data->private_data);
-}
-
ctdb_handle *
ctdb_getrecmaster_send(struct ctdb_context *ctdb,
- uint32_t destnode,
- ctdb_getrecmaster_cb callback,
- void *private_data)
+ uint32_t destnode)
{
struct ctdb_client_control_state *state;
- struct ctdb_control_cb_data *cb_data;
state = ctdb_control_send(ctdb, destnode, 0,
CTDB_CONTROL_GET_RECMASTER, 0, tdb_null,
return NULL;
}
- if (callback != NULL) {
- cb_data = talloc(state, struct ctdb_control_cb_data);
- cb_data->callback = callback;
- cb_data->private_data = private_data;
-
- state->async.fn = ctdb_getrecmaster_recv_cb;
- state->async.private_data = cb_data;
- }
-
return (ctdb_handle *)state;
}
{
struct ctdb_client_control_state *state = talloc_get_type(handle, struct ctdb_client_control_state);
int ret;
- int32_t res;
- ret = ctdb_control_recv(ctdb, state, state, NULL, &res, NULL);
+ ret = ctdb_control_recv(ctdb, state, state, NULL, NULL, NULL);
if (ret != 0) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_getrecmaster_recv failed\n"));
return -1;
}
if (recmaster != NULL) {
- *recmaster = (uint32_t)res;
+ *recmaster = (uint32_t)state->status;
}
return 0;
{
struct ctdb_client_control_state *state;
- state = ctdb_getrecmaster_send(ctdb, destnode, NULL, NULL);
+ state = ctdb_getrecmaster_send(ctdb, destnode);
if (state == NULL) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_getrecmaster_send() failed.\n"));
return -1;
printf("status:%d pnn:%d\n", status, pnn);
}
-void rm_cb(int32_t status, int32_t recmaster, void *private_data)
+void rm_cb(int32_t status, struct ctdb_context *ctdb, ctdb_handle *handle, void *private_data)
{
- printf("status:%d recmaster:%d\n", status, recmaster);
+ uint32_t rm;
+ int ret;
+
+ if (status != 0) {
+ printf("Error reading RECMASTER\n");
+ return;
+ }
+
+ ret = ctdb_getrecmaster_recv(ctdb, handle, &rm);
+ if (ret != 0) {
+ printf("Failed to read getpnn reply\n");
+ return;
+ }
+
+ printf("GETRECMASTER ASYNC: status:%d recmaster:%d\n", status, rm);
}
+
/*
* example on how to first read(non-existing recortds are implicitely created
* on demand) a record and change it in the callback.
ctdb_handle *handle;
struct pollfd pfd;
int ret;
+ uint32_t recmaster;
TDB_DATA msg;
key.dptr = "Test Record";
+ /*
+ * ASYNC call with callback to read the recmaster
+ * this is the preferred way to use libctdb
+ */
+ handle = ctdb_getrecmaster_send(ctdb, CTDB_CURRENT_NODE);
+ if (handle == NULL) {
+ printf("Failed to send get_recmaster control\n");
+ exit(10);
+ }
+ ret = ctdb_set_callback(handle, rm_cb, NULL);
+ if (ret != 0) {
+ printf("Failed to set callback for get_recmaster\n");
+ ctdb_free(handle);
+ exit(10);
+ }
+
+ /*
+ * SEMI-SYNC call with callback to read the recmaster
+ * calls the blocking *_recv() function.
+ * Avoid this mode for performance critical tasks
+ */
+ handle = ctdb_getrecmaster_send(ctdb, CTDB_CURRENT_NODE);
+ if (handle == NULL) {
+ printf("Failed to send get_recmaster control\n");
+ exit(10);
+ }
+ ret = ctdb_getrecmaster_recv(ctdb, handle, &recmaster);
+ if (ret != 0) {
+ printf("Failed to receive response to getrecmaster\n");
+ ctdb_free(handle);
+ exit(10);
+ }
+ printf("GETRECMASTER SEMI-SYNC: status:%d recmaster:%d\n", ret, recmaster);
+
+
+ /*
+ * SYNC call with callback to read the recmaster
+ * calls the blocking sync function.
+ * Avoid this mode for performance critical tasks
+ */
+ ret = ctdb_getrecmaster(ctdb, CTDB_CURRENT_NODE, &recmaster);
+ if (ret != 0) {
+ printf("Failed to receive response to getrecmaster\n");
+ exit(10);
+ }
+ printf("GETRECMASTER SYNC: status:%d recmaster:%d\n", ret, recmaster);
+
+
+
handle = ctdb_getpnn_send(ctdb, CTDB_CURRENT_NODE);
if (handle == NULL) {
}
-
-
handle = ctdb_readrecordlock_send(ctdb, ctdb_db_context, key, rrl_cb, NULL);
if (handle == NULL) {
printf("Failed to send READRECORDLOCK\n");