summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRonnie Sahlberg <ronniesahlberg@gmail.com>2011-11-28 16:30:46 +1100
committerRonnie Sahlberg <ronniesahlberg@gmail.com>2011-11-30 08:48:14 +1100
commit3cbff2edd82ddc8f1d44696e35cf6e8b355cf6ae (patch)
tree0ca0880c2a8e23cd471b2b4b4404efbd6e7b40c4
parent3e2c40c5900f93cf691087041e62a375a27d9ce0 (diff)
downloadsamba-3cbff2edd82ddc8f1d44696e35cf6e8b355cf6ae.tar.gz
samba-3cbff2edd82ddc8f1d44696e35cf6e8b355cf6ae.tar.xz
samba-3cbff2edd82ddc8f1d44696e35cf6e8b355cf6ae.zip
LibCTDB: add get persistent db seqnum control
(This used to be ctdb commit 6e96a62494bbb2c7b0682ebf0c2115dd2f44f7af)
-rw-r--r--ctdb/include/ctdb.h52
-rw-r--r--ctdb/libctdb/control.c40
-rw-r--r--ctdb/libctdb/sync.c18
-rw-r--r--ctdb/tools/ctdb.c27
4 files changed, 137 insertions, 0 deletions
diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h
index 35ccf83e32..43ab192c0f 100644
--- a/ctdb/include/ctdb.h
+++ b/ctdb/include/ctdb.h
@@ -510,6 +510,35 @@ bool ctdb_getpnn_recv(struct ctdb_connection *ctdb,
/**
+ * ctdb_getdbseqnum_send - read the sequence number off a db
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ * @destnode: the destination node (see below)
+ * @dbid: database id
+ * @callback: the callback when ctdb replies to our message (typesafe)
+ * @cbdata: the argument to callback()
+ *
+ * There are several special values for destnode, detailed in
+ * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
+ * local ctdbd.
+ */
+struct ctdb_request *
+ctdb_getdbseqnum_send(struct ctdb_connection *ctdb,
+ uint32_t destnode,
+ uint32_t dbid,
+ ctdb_callback_t callback,
+ void *cbdata);
+/**
+ * ctdb_getdbseqnum_recv - read the sequence number off a database
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ * @req: the completed request.
+ * @seqnum: a pointer to the seqnum to fill in
+ *
+ * This returns false if something went wrong, or otherwise fills in pnn.
+ */
+bool ctdb_getdbseqnum_recv(struct ctdb_connection *ctdb,
+ struct ctdb_request *req, uint64_t *seqnum);
+
+/**
* ctdb_getnodemap_send - read the nodemap number from a node.
* @ctdb: the ctdb_connection from ctdb_connect.
* @destnode: the destination node (see below)
@@ -738,6 +767,25 @@ bool ctdb_getpnn(struct ctdb_connection *ctdb,
uint32_t *pnn);
/**
+ * ctdb_getdbseqnum - read the seqnum of a database
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ * @destnode: the destination node (see below)
+ * @dbid: database id
+ * @seqnum: sequence number for the database
+ *
+ * There are several special values for destnode, detailed in
+ * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the
+ * local ctdbd.
+ *
+ * Returns true and fills in *pnn on success.
+ */
+bool
+ctdb_getdbseqnum(struct ctdb_connection *ctdb,
+ uint32_t destnode,
+ uint32_t dbid,
+ uint64_t *seqnum);
+
+/**
* ctdb_getrecmaster - read the recovery master of a node (synchronous)
* @ctdb: the ctdb_connection from ctdb_connect.
* @destnode: the destination node (see below)
@@ -890,4 +938,8 @@ void ctdb_free_publicips(struct ctdb_all_public_ips *ips);
ctdb_getpublicips_send((ctdb), (destnode), \
ctdb_sendcb((cb), (cbdata)), (cbdata))
+#define ctdb_getdbseqnum_send(ctdb, destnode, dbid, cb, cbdata) \
+ ctdb_getdbseqnum_send((ctdb), (destnode), (dbid), \
+ ctdb_sendcb((cb), (cbdata)), (cbdata))
+
#endif
diff --git a/ctdb/libctdb/control.c b/ctdb/libctdb/control.c
index 48add207c7..70c8e51950 100644
--- a/ctdb/libctdb/control.c
+++ b/ctdb/libctdb/control.c
@@ -27,6 +27,7 @@
#undef ctdb_getpnn_send
#undef ctdb_getnodemap_send
#undef ctdb_getpublicips_send
+#undef ctdb_getdbseqnum_send
bool ctdb_getrecmaster_recv(struct ctdb_connection *ctdb,
struct ctdb_request *req, uint32_t *recmaster)
@@ -200,3 +201,42 @@ void ctdb_free_publicips(struct ctdb_all_public_ips *ips)
}
free(ips);
}
+
+bool ctdb_getdbseqnum_recv(struct ctdb_connection *ctdb,
+ struct ctdb_request *req, uint64_t *seqnum)
+{
+ struct ctdb_reply_control *reply;
+
+ reply = unpack_reply_control(req, CTDB_CONTROL_GET_DB_SEQNUM);
+ if (!reply) {
+ return false;
+ }
+ if (reply->status == -1) {
+ DEBUG(ctdb, LOG_ERR, "ctdb_getdbseqnum_recv: status -1");
+ return false;
+ }
+
+ if (reply->datalen != sizeof(uint64_t)) {
+ DEBUG(ctdb, LOG_ERR, "ctdb_getdbseqnum wrong size of data was %d but expected %d bytes", reply->datalen, (int)sizeof(uint64_t));
+ return false;
+ }
+
+ *seqnum = *((uint64_t *)reply->data);
+
+ return true;
+}
+
+struct ctdb_request *ctdb_getdbseqnum_send(struct ctdb_connection *ctdb,
+ uint32_t destnode,
+ uint32_t dbid,
+ ctdb_callback_t callback,
+ void *private_data)
+{
+ uint64_t indata;
+
+ *((uint32_t *)&indata) = dbid;
+
+ return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_DB_SEQNUM,
+ destnode, &indata, sizeof(uint64_t),
+ callback, private_data);
+}
diff --git a/ctdb/libctdb/sync.c b/ctdb/libctdb/sync.c
index f957514e0d..7c9949464b 100644
--- a/ctdb/libctdb/sync.c
+++ b/ctdb/libctdb/sync.c
@@ -244,3 +244,21 @@ struct ctdb_lock *ctdb_readrecordlock(struct ctdb_connection *ctdb,
}
return rrl.lock;
}
+
+bool ctdb_getdbseqnum(struct ctdb_connection *ctdb,
+ uint32_t destnode, uint32_t dbid,
+ uint64_t *seqnum)
+{
+ struct ctdb_request *req;
+ bool done = false;
+ bool ret = false;
+
+ req = synchronous(ctdb,
+ ctdb_getdbseqnum_send(ctdb, destnode, dbid, set, &done),
+ &done);
+ if (req != NULL) {
+ ret = ctdb_getdbseqnum_recv(ctdb, req, seqnum);
+ ctdb_request_free(req);
+ }
+ return ret;
+}
diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c
index 06e2a0b5d1..9899b7dc54 100644
--- a/ctdb/tools/ctdb.c
+++ b/ctdb/tools/ctdb.c
@@ -4132,6 +4132,32 @@ static int control_setdbreadonly(struct ctdb_context *ctdb, int argc, const char
}
/*
+ get db seqnum
+ */
+static int control_getdbseqnum(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+ bool ret;
+ uint32_t db_id;
+ uint64_t seqnum;
+
+ if (argc < 1) {
+ usage();
+ }
+
+ db_id = strtoul(argv[0], NULL, 0);
+
+ ret = ctdb_getdbseqnum(ctdb_connection, options.pnn, db_id, &seqnum);
+ if (!ret) {
+ DEBUG(DEBUG_ERR, ("Unable to get seqnum from node."));
+ return -1;
+ }
+
+ printf("Sequence number:%lld\n", (long long)seqnum);
+
+ return 0;
+}
+
+/*
run an eventscript on a node
*/
static int control_eventscript(struct ctdb_context *ctdb, int argc, const char **argv)
@@ -5141,6 +5167,7 @@ static const struct {
{ "readkey", control_readkey, true, false, "read the content off a database key", "<tdb-file> <key>" },
{ "writekey", control_writekey, true, false, "write to a database key", "<tdb-file> <key> <value>" },
{ "checktcpport", control_chktcpport, false, true, "check if a service is bound to a specific tcp port or not", "<port>" },
+ { "getdbseqnum", control_getdbseqnum, false, false, "get the sequence number off a database", "<dbid>" },
};
/*