[PATCH] ctdb: show lmaster in ctdb cat[t]db

Ralph Böhme slow at samba.org
Tue Sep 11 06:24:17 UTC 2018


Hi!

A few times when trying to understand how a record was bouncing around between 
nodes, I found it helpful to have a patched ctdb catdb that show the lmaster of 
a record.

# ctdb catdb test_per_rec_persistency.tdb
key(3) = "foo"
dmaster: 0
lmaster: 1
rsn: 2
flags: 0x00000000
data(3) = "bar"

Dumped 1 records

Would this be useful upstream?

Patch attached, please review & push if happy.

-slow

-- 
Ralph Boehme, Samba Team       https://samba.org/
Samba Developer, SerNet GmbH   https://sernet.de/en/samba/
GPG Key Fingerprint:           FAE2 C608 8A24 2520 51C5
                               59E4 AA1E 9B71 2639 9E46
-------------- next part --------------
From 37b0f45422cbb422d97566b1a1088dc4628a3795 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Tue, 7 Nov 2017 10:06:28 +0100
Subject: [PATCH] ctdb: ctdb cat[t]db show lmaster

Signed-off-by: Ralph Boehme <slow at samba.org>
---
 ctdb/tools/ctdb.c | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c
index 0652a205dbd..8cf0eba82e7 100644
--- a/ctdb/tools/ctdb.c
+++ b/ctdb/tools/ctdb.c
@@ -2037,6 +2037,7 @@ static int control_getdbstatus(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
 }
 
 struct dump_record_state {
+	struct ctdb_context *ctdb;
 	uint32_t count;
 };
 
@@ -2057,9 +2058,14 @@ static void dump_tdb_data(const char *name, TDB_DATA val)
 	fprintf(stdout, "\"\n");
 }
 
-static void dump_ltdb_header(struct ctdb_ltdb_header *header)
+static void dump_ltdb_header(struct ctdb_context *ctdb,
+			     struct ctdb_ltdb_header *header,
+			     TDB_DATA key)
 {
+	uint32_t hash = tdb_jenkins_hash(&key);
+
 	fprintf(stdout, "dmaster: %u\n", header->dmaster);
+	fprintf(stdout, "lmaster: %u\n", hash % ctdb->nodemap->num);
 	fprintf(stdout, "rsn: %" PRIu64 "\n", header->rsn);
 	fprintf(stdout, "flags: 0x%08x", header->flags);
 	if (header->flags & CTDB_REC_FLAG_MIGRATED_WITH_DATA) {
@@ -2096,7 +2102,7 @@ static int dump_record(uint32_t reqid, struct ctdb_ltdb_header *header,
 	state->count += 1;
 
 	dump_tdb_data("key", key);
-	dump_ltdb_header(header);
+	dump_ltdb_header(state->ctdb, header, key);
 	dump_tdb_data("data", data);
 	fprintf(stdout, "\n");
 
@@ -2106,6 +2112,7 @@ static int dump_record(uint32_t reqid, struct ctdb_ltdb_header *header,
 static int control_catdb(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
 			 int argc, const char **argv)
 {
+	struct ctdb_node_map *nodemap = NULL;
 	struct ctdb_db_context *db;
 	const char *db_name;
 	uint32_t db_id;
@@ -2117,6 +2124,11 @@ static int control_catdb(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
 		usage("catdb");
 	}
 
+	nodemap = get_nodemap(ctdb, false);
+	if (nodemap == NULL) {
+		return 1;
+	}
+
 	if (! db_exists(mem_ctx, ctdb, argv[0], &db_id, &db_name, &db_flags)) {
 		return 1;
 	}
@@ -2128,6 +2140,7 @@ static int control_catdb(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
 		return ret;
 	}
 
+	state.ctdb = ctdb;
 	state.count = 0;
 
 	ret = ctdb_db_traverse(mem_ctx, ctdb->ev, ctdb->client, db,
@@ -2142,6 +2155,7 @@ static int control_catdb(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
 static int control_cattdb(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
 			  int argc, const char **argv)
 {
+	struct ctdb_node_map *nodemap = NULL;
 	struct ctdb_db_context *db;
 	const char *db_name;
 	uint32_t db_id;
@@ -2153,6 +2167,11 @@ static int control_cattdb(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
 		usage("catdb");
 	}
 
+	nodemap = get_nodemap(ctdb, false);
+	if (nodemap == NULL) {
+		return 1;
+	}
+
 	if (! db_exists(mem_ctx, ctdb, argv[0], &db_id, &db_name, &db_flags)) {
 		return 1;
 	}
@@ -2164,6 +2183,7 @@ static int control_cattdb(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
 		return ret;
 	}
 
+	state.ctdb = ctdb;
 	state.count = 0;
 	ret = ctdb_db_traverse_local(db, true, true, dump_record, &state);
 
@@ -5140,6 +5160,7 @@ static int control_ptrans(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
 static int control_tfetch(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
 			  int argc, const char **argv)
 {
+	struct ctdb_node_map *nodemap = NULL;
 	struct tdb_context *tdb;
 	TDB_DATA key, data;
 	struct ctdb_ltdb_header header;
@@ -5149,6 +5170,11 @@ static int control_tfetch(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
 		usage("tfetch");
 	}
 
+	nodemap = get_nodemap(ctdb, false);
+	if (nodemap == NULL) {
+		return 1;
+	}
+
 	tdb = tdb_open(argv[0], 0, 0, O_RDWR, 0);
 	if (tdb == NULL) {
 		fprintf(stderr, "Failed to open TDB file %s\n", argv[0]);
@@ -5205,7 +5231,7 @@ static int control_tfetch(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
 		return 1;
 	}
 
-	dump_ltdb_header(&header);
+	dump_ltdb_header(ctdb, &header, key);
 	dump_tdb_data("data", data);
 
 	return 0;
-- 
2.13.6



More information about the samba-technical mailing list