[SCM] CTDB repository - branch libctdb updated - ctdb-1.0.114-112-ge9418d9

Ronnie Sahlberg sahlberg at samba.org
Mon May 17 19:26:24 MDT 2010


The branch, libctdb has been updated
       via  e9418d95052490b0d8de98cb4c37b74f25ea8842 (commit)
      from  d61fbb5c91b1780208fc24318a2fc7cbeaefebf4 (commit)

http://gitweb.samba.org/?p=sahlberg/ctdb.git;a=shortlog;h=libctdb


- Log -----------------------------------------------------------------
commit e9418d95052490b0d8de98cb4c37b74f25ea8842
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Tue May 18 11:24:39 2010 +1000

    make the getrecovery master control use the new generic set_callback
    api and remove the callback argument from the _send() signature
    
    Update the example tst.c function to show the three different modes to talk to ctdb

-----------------------------------------------------------------------

Summary of changes:
 include/ctdb.h    |    4 +--
 libctdb/libctdb.c |   36 +++------------------------
 libctdb/tst.c     |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 72 insertions(+), 39 deletions(-)


Changeset truncated at 500 lines:

diff --git a/include/ctdb.h b/include/ctdb.h
index 980e855..86886e5 100644
--- a/include/ctdb.h
+++ b/include/ctdb.h
@@ -242,9 +242,7 @@ typedef void (*ctdb_getrecmaster_cb)(int32_t status, int32_t recmaster, void *pr
 
 ctdb_handle *
 ctdb_getrecmaster_send(struct ctdb_context *ctdb,
-			uint32_t destnode,
-			ctdb_getrecmaster_cb callback,
-			void *private_data);
+		       uint32_t destnode);
 int ctdb_getrecmaster_recv(struct ctdb_context *ctdb,
 			ctdb_handle *handle,
 			uint32_t *recmaster);
diff --git a/libctdb/libctdb.c b/libctdb/libctdb.c
index a17ad14..e4a5ea6 100644
--- a/libctdb/libctdb.c
+++ b/libctdb/libctdb.c
@@ -292,29 +292,11 @@ int ctdb_getpnn(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *pnn)
 /***********************
  * 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, 
@@ -325,15 +307,6 @@ ctdb_getrecmaster_send(struct ctdb_context *ctdb,
 		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;
 }
 
@@ -341,16 +314,15 @@ int ctdb_getrecmaster_recv(struct ctdb_context *ctdb, ctdb_handle *handle, uint3
 {
 	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;
@@ -360,7 +332,7 @@ int ctdb_getrecmaster(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *re
 {
 	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;
diff --git a/libctdb/tst.c b/libctdb/tst.c
index f8e8f7f..d3db133 100644
--- a/libctdb/tst.c
+++ b/libctdb/tst.c
@@ -34,11 +34,26 @@ void pnn_cb(int32_t status, struct ctdb_context *ctdb, ctdb_handle *handle, void
 	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.
@@ -86,6 +101,7 @@ int main(int argc, char *argv[])
 	ctdb_handle *handle;
 	struct pollfd pfd;
 	int ret;
+	uint32_t recmaster;
 	TDB_DATA msg;
 
 	key.dptr  = "Test Record";
@@ -126,6 +142,55 @@ int main(int argc, char *argv[])
 
 
 
+	/*
+	 * 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) {
@@ -140,8 +205,6 @@ int main(int argc, char *argv[])
 	}
 
 
-
-
 	handle = ctdb_readrecordlock_send(ctdb, ctdb_db_context, key, rrl_cb, NULL);
 	if (handle == NULL) {
 		printf("Failed to send READRECORDLOCK\n");


-- 
CTDB repository


More information about the samba-cvs mailing list