Rev 693: more optimisations to recovery in http://samba.org/~tridge/ctdb

tridge at samba.org tridge at samba.org
Wed Jan 2 11:44:53 GMT 2008


------------------------------------------------------------
revno: 693
revision-id:tridge at samba.org-20080102114446-ci6yp94r12pwnfto
parent: tridge at samba.org-20080102010655-cettt5oz0v8mujmt
committer: Andrew Tridgell <tridge at samba.org>
branch nick: tridge.kantana
timestamp: Wed 2008-01-02 22:44:46 +1100
message:
  more optimisations to recovery
modified:
  server/ctdb_recover.c          ctdb_recover.c-20070503002147-admmfgt1oj6gexfo-1
  server/ctdb_recoverd.c         recoverd.c-20070503213540-bvxuyd9jm1f7ig90-1
  tests/ctdb_store.c             ctdb_store.c-20070617011248-7ze8iaf75dwi0tk0-1
=== modified file 'server/ctdb_recover.c'
--- a/server/ctdb_recover.c	2007-12-02 23:19:24 +0000
+++ b/server/ctdb_recover.c	2008-01-02 11:44:46 +0000
@@ -332,10 +332,24 @@
 		   if the rsn values are equal */
 		if (header.rsn < hdr->rsn ||
 		    (header.dmaster != ctdb->pnn && header.rsn == hdr->rsn)) {
-			ret = ctdb_ltdb_store(ctdb_db, key, hdr, data);
-			if (ret != 0) {
-				DEBUG(0, (__location__ " Unable to store record\n"));
-				goto failed;
+			/* this is a push optimisation - we can skip writing the record if:
+
+			       1) this is not a persistent db
+			   AND 2) we are not the recmaster
+			   AND 3) we don't hold the record currently
+			   AND 4) we won't hold the new record
+			*/
+			if (!ctdb_db->persistent &&
+			    ctdb->recovery_master != ctdb->pnn &&
+			    header.dmaster != ctdb->pnn &&
+			    hdr->dmaster != ctdb->pnn) {
+				DEBUG(5,("Skipping push of record\n"));
+			} else {
+				ret = ctdb_ltdb_store(ctdb_db, key, hdr, data);
+				if (ret != 0) {
+					DEBUG(0, (__location__ " Unable to store record\n"));
+					goto failed;
+				}
 			}
 		}
 
@@ -360,6 +374,11 @@
 	struct ctdb_ltdb_header *header = (struct ctdb_ltdb_header *)data.dptr;
 	int ret;
 
+	/* skip if already correct */
+	if (header->dmaster == *dmaster) {
+		return 0;
+	}
+
 	header->dmaster = *dmaster;
 
 	ret = tdb_store(tdb, key, data, TDB_REPLACE);

=== modified file 'server/ctdb_recoverd.c'
--- a/server/ctdb_recoverd.c	2007-12-26 23:07:01 +0000
+++ b/server/ctdb_recoverd.c	2008-01-02 11:44:46 +0000
@@ -504,25 +504,19 @@
 /*
   change the dmaster on all databases to point to us
  */
-static int update_dmaster_on_all_databases(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap, 
-					   uint32_t pnn, struct ctdb_dbid_map *dbmap, TALLOC_CTX *mem_ctx)
+static int update_dmaster_on_our_databases(struct ctdb_context *ctdb, uint32_t pnn, 
+					   struct ctdb_dbid_map *dbmap, TALLOC_CTX *mem_ctx)
 {
-	int i, j, ret;
+	int i, ret;
 
 	/* update dmaster to point to this node for all databases/nodes */
 	for (i=0;i<dbmap->num;i++) {
-		for (j=0; j<nodemap->num; j++) {
-			/* dont repoint nodes that are unavailable */
-			if (nodemap->nodes[j].flags & NODE_FLAGS_INACTIVE) {
-				continue;
-			}
-			ret = ctdb_ctrl_setdmaster(ctdb, CONTROL_TIMEOUT(), nodemap->nodes[j].pnn, 
-						   ctdb, dbmap->dbs[i].dbid, pnn);
-			if (ret != 0) {
-				DEBUG(0, (__location__ " Unable to set dmaster for node %u db:0x%08x\n", 
-					  nodemap->nodes[j].pnn, dbmap->dbs[i].dbid));
-				return -1;
-			}
+		ret = ctdb_ctrl_setdmaster(ctdb, CONTROL_TIMEOUT(), pnn, 
+					   ctdb, dbmap->dbs[i].dbid, pnn);
+		if (ret != 0) {
+			DEBUG(0, (__location__ " Unable to set dmaster for node %u db:0x%08x\n", 
+				  pnn, dbmap->dbs[i].dbid));
+			return -1;
 		}
 	}
 
@@ -1004,6 +998,18 @@
 
 	DEBUG(1, (__location__ " Recovery - pulled remote databases\n"));
 
+	/* repoint all local database records to the local node as
+	   being dmaster
+	 */
+	ret = update_dmaster_on_our_databases(ctdb, pnn, dbmap, mem_ctx);
+	if (ret != 0) {
+		DEBUG(0, (__location__ " Unable to update dmaster on all databases\n"));
+		return -1;
+	}
+
+	DEBUG(1, (__location__ " Recovery - updated dmaster on all databases\n"));
+
+
 	/* push all local databases to the remote nodes */
 	ret = push_all_local_databases(ctdb, nodemap, pnn, dbmap, mem_ctx);
 	if (ret != 0) {
@@ -1047,17 +1053,6 @@
 
 	DEBUG(1, (__location__ " Recovery - updated recmaster\n"));
 
-	/* repoint all local and remote database records to the local
-	   node as being dmaster
-	 */
-	ret = update_dmaster_on_all_databases(ctdb, nodemap, pnn, dbmap, mem_ctx);
-	if (ret != 0) {
-		DEBUG(0, (__location__ " Unable to update dmaster on all databases\n"));
-		return -1;
-	}
-
-	DEBUG(1, (__location__ " Recovery - updated dmaster on all databases\n"));
-
 	/*
 	  update all nodes to have the same flags that we have
 	 */

=== modified file 'tests/ctdb_store.c'
--- a/tests/ctdb_store.c	2007-09-21 02:24:02 +0000
+++ b/tests/ctdb_store.c	2008-01-02 11:44:46 +0000
@@ -28,7 +28,7 @@
 #include <time.h>
 
 static int num_records = 10;
-
+static int base_rec;
 
 static void store_records(struct ctdb_context *ctdb, struct event_context *ev)
 {
@@ -43,7 +43,8 @@
 
 	printf("creating %d records\n", num_records);
 	for (i=0;i<num_records;i++) {
-		key.dptr = (uint8_t *)&i;
+		int r = base_rec + i;
+		key.dptr = (uint8_t *)&r;
 		key.dsize = sizeof(uint32_t); 
 
 		h = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, &data);
@@ -71,7 +72,8 @@
 	printf("fetching all %d records\n", num_records);
 	while (1) {
 		for (i=0;i<num_records;i++) {
-			key.dptr = (uint8_t *)&i;
+			int r = base_rec + i;
+			key.dptr = (uint8_t *)&r;
 			key.dsize = sizeof(uint32_t); 
 
 			h = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, &data);
@@ -103,6 +105,7 @@
 		POPT_AUTOHELP
 		POPT_CTDB_CMDLINE
 		{ "num-records", 'r', POPT_ARG_INT, &num_records, 0, "num_records", "integer" },
+		{ "base-rec", 'b', POPT_ARG_INT, &base_rec, 0, "base_rec", "integer" },
 		POPT_TABLEEND
 	};
 	int opt;



More information about the samba-cvs mailing list