[SCM] CTDB repository - branch master updated - 2b0bd6c302545f2533a7a67dfc6bb5f9f60799f7

Ronnie Sahlberg sahlberg at samba.org
Wed Jul 16 02:43:18 GMT 2008


The branch, master has been updated
       via  2b0bd6c302545f2533a7a67dfc6bb5f9f60799f7 (commit)
      from  2fe52c7979ecd28250ec4ac195d3c3999916e573 (commit)

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


- Log -----------------------------------------------------------------
commit 2b0bd6c302545f2533a7a67dfc6bb5f9f60799f7
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Jul 16 12:23:18 2008 +1000

    change how we filter out "empty" records in the traversecode
    so that we output the same list of keys in "catdb" as "tdbdump".
    
    when traversing a persistent database, as an optimization, only
    traverse on the local node (and thus skip checking if we are
    dmaster or not). If the local node is not part of the vnnmap and thus
    would not be guaranteed to have an uptodate persistent database
    we instead traverse it on one of the other nodes that are in the vnnmap.

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

Summary of changes:
 client/ctdb_client.c   |    5 ++-
 server/ctdb_traverse.c |   71 ++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 60 insertions(+), 16 deletions(-)


Changeset truncated at 500 lines:

diff --git a/client/ctdb_client.c b/client/ctdb_client.c
index ed999f2..544f5d1 100644
--- a/client/ctdb_client.c
+++ b/client/ctdb_client.c
@@ -1847,6 +1847,7 @@ int ctdb_traverse(struct ctdb_db_context *ctdb_db, ctdb_traverse_func fn, void *
 	return state.count;
 }
 
+#define ISASCII(x) ((x>31)&&(x<128))
 /*
   called on each key during a catdb
  */
@@ -1861,7 +1862,7 @@ static int dumpdb_fn(struct ctdb_context *ctdb, TDB_DATA key, TDB_DATA data, voi
 
 	fprintf(f, "key(%u) = \"", (unsigned)key.dsize);
 	for (i=0;i<key.dsize;i++) {
-		if (isascii(key.dptr[i])) {
+		if (ISASCII(key.dptr[i])) {
 			fprintf(f, "%c", key.dptr[i]);
 		} else {
 			fprintf(f, "\\%02X", key.dptr[i]);
@@ -1871,7 +1872,7 @@ static int dumpdb_fn(struct ctdb_context *ctdb, TDB_DATA key, TDB_DATA data, voi
 
 	fprintf(f, "data(%u) = \"", (unsigned)data.dsize);
 	for (i=sizeof(*h);i<data.dsize;i++) {
-		if (isascii(data.dptr[i])) {
+		if (ISASCII(data.dptr[i])) {
 			fprintf(f, "%c", data.dptr[i]);
 		} else {
 			fprintf(f, "\\%02X", data.dptr[i]);
diff --git a/server/ctdb_traverse.c b/server/ctdb_traverse.c
index 10895ed..35ae318 100644
--- a/server/ctdb_traverse.c
+++ b/server/ctdb_traverse.c
@@ -87,11 +87,19 @@ static int ctdb_traverse_local_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DAT
 	struct ctdb_rec_data *d;
 	struct ctdb_ltdb_header *hdr;
 
-	/* filter out non-authoritative and zero-length records */
+	
 	hdr = (struct ctdb_ltdb_header *)data.dptr;
-	if (data.dsize <= sizeof(struct ctdb_ltdb_header) ||
-	    hdr->dmaster != h->ctdb_db->ctdb->pnn) {
-		return 0;
+
+	if (h->ctdb_db->persistent == 0) {
+		/* filter out zero-length records */
+		if (data.dsize <= sizeof(struct ctdb_ltdb_header)) {
+			return 0;
+		}
+
+		/* filter out non-authoritative records */
+		if (hdr->dmaster != h->ctdb_db->ctdb->pnn) {
+			return 0;
+		}
 	}
 
 	d = ctdb_marshall_record(h, 0, key, NULL, data);
@@ -174,6 +182,7 @@ static struct ctdb_traverse_local_handle *ctdb_traverse_local(struct ctdb_db_con
 
 struct ctdb_traverse_all_handle {
 	struct ctdb_context *ctdb;
+	struct ctdb_db_context *ctdb_db;
 	uint32_t reqid;
 	ctdb_traverse_fn_t callback;
 	void *private_data;
@@ -224,17 +233,19 @@ static struct ctdb_traverse_all_handle *ctdb_daemon_traverse_all(struct ctdb_db_
 	int ret;
 	TDB_DATA data;
 	struct ctdb_traverse_all r;
+	uint32_t destination;
 
 	state = talloc(ctdb_db, struct ctdb_traverse_all_handle);
 	if (state == NULL) {
 		return NULL;
 	}
 
-	state->ctdb = ctdb;
-	state->reqid = ctdb_reqid_new(ctdb_db->ctdb, state);
-	state->callback = callback;
+	state->ctdb         = ctdb;
+	state->ctdb_db      = ctdb_db;
+	state->reqid        = ctdb_reqid_new(ctdb_db->ctdb, state);
+	state->callback     = callback;
 	state->private_data = private_data;
-	state->null_count = 0;
+	state->null_count   = 0;
 	
 	talloc_set_destructor(state, ctdb_traverse_all_destructor);
 
@@ -245,10 +256,37 @@ static struct ctdb_traverse_all_handle *ctdb_daemon_traverse_all(struct ctdb_db_
 	data.dptr = (uint8_t *)&r;
 	data.dsize = sizeof(r);
 
-	/* tell all the nodes in the cluster to start sending records to this node */
-	ret = ctdb_daemon_send_control(ctdb, CTDB_BROADCAST_VNNMAP, 0, 
-				       CTDB_CONTROL_TRAVERSE_ALL,
-				       0, CTDB_CTRL_FLAG_NOREPLY, data, NULL, NULL);
+	if (ctdb_db->persistent == 0) {
+		/* normal database, traverse all nodes */	  
+		destination = CTDB_BROADCAST_VNNMAP;
+	} else {
+		int i;
+		/* persistent database, traverse one node, preferably
+		 * the local one
+		 */
+		destination = ctdb->pnn;
+		/* check we are in the vnnmap */
+		for (i=0; i < ctdb->vnn_map->size; i++) {
+			if (ctdb->vnn_map->map[i] == ctdb->pnn) {
+				break;
+			}
+		}
+		/* if we are not in the vnn map we just pick the first
+		 * node instead
+		 */
+		if (i == ctdb->vnn_map->size) {
+			destination = ctdb->vnn_map->map[0];
+		}
+	}
+
+	/* tell all the nodes in the cluster to start sending records to this
+	 * node, or if it is a persistent database, just tell the local
+	 * node
+	 */
+	ret = ctdb_daemon_send_control(ctdb, destination, 0, 
+			       CTDB_CONTROL_TRAVERSE_ALL,
+			       0, CTDB_CTRL_FLAG_NOREPLY, data, NULL, NULL);
+
 	if (ret != 0) {
 		talloc_free(state);
 		return NULL;
@@ -371,8 +409,13 @@ int32_t ctdb_control_traverse_data(struct ctdb_context *ctdb, TDB_DATA data, TDB
 
 	if (key.dsize == 0 && data.dsize == 0) {
 		state->null_count++;
-		if (state->null_count != ctdb_get_num_active_nodes(ctdb)) {
-			return 0;
+		/* Persistent databases are only scanned on one node (the local
+		 * node)
+		 */
+		if (state->ctdb_db->persistent == 0) {
+			if (state->null_count != ctdb_get_num_active_nodes(ctdb)) {
+				return 0;
+			}
 		}
 	}
 


-- 
CTDB repository


More information about the samba-cvs mailing list