Add a new control CTDB_GET_DB_SEQNUM - fetch a persistent db's sequence number.
authorMichael Adam <obnox@samba.org>
Fri, 11 Dec 2009 14:31:02 +0000 (15:31 +0100)
committerMichael Adam <obnox@samba.org>
Fri, 11 Dec 2009 23:45:39 +0000 (00:45 +0100)
Michael

include/ctdb_private.h
server/ctdb_control.c
server/ctdb_persistent.c

index da0c7563e1f1c977cc202660f3543d2b48c4e21c..e4f4aba091497cf7f54dab5f343f93aa44f00080 100644 (file)
@@ -626,6 +626,7 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS          = 0,
                    CTDB_CONTROL_GET_LOG                 = 117,
                    CTDB_CONTROL_CLEAR_LOG               = 118,
                    CTDB_CONTROL_TRANS3_COMMIT           = 119,
+                   CTDB_CONTROL_GET_DB_SEQNUM           = 120,
 };     
 
 /*
@@ -1537,4 +1538,8 @@ struct ctdb_log_state *ctdb_fork_with_logging(TALLOC_CTX *mem_ctx,
 int32_t ctdb_control_process_exists(struct ctdb_context *ctdb, pid_t pid);
 struct ctdb_client *ctdb_find_client_by_pid(struct ctdb_context *ctdb, pid_t pid);
 
+int32_t ctdb_control_get_db_seqnum(struct ctdb_context *ctdb,
+                                  TDB_DATA indata,
+                                  TDB_DATA *outdata);
+
 #endif
index 9cc5591d3d75f861c4e3aa08de174c9ac94db92b..3382fae39aac964481068c369021b3588dc13437 100644 (file)
@@ -556,6 +556,10 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
        case CTDB_CONTROL_CLEAR_LOG:
                return ctdb_control_clear_log(ctdb);
 
+       case CTDB_CONTROL_GET_DB_SEQNUM:
+               CHECK_CONTROL_DATA_SIZE(sizeof(uint64_t));
+               return ctdb_control_get_db_seqnum(ctdb, indata, outdata);
+
        default:
                DEBUG(DEBUG_CRIT,(__location__ " Unknown CTDB control opcode %u\n", opcode));
                return -1;
index c075a5d86a8bc9ebfcba3635eae374399d5e1f09..59ddadb042fe7eed63c01593139db4b3bf60ad4e 100644 (file)
@@ -815,4 +815,70 @@ int32_t ctdb_control_persistent_store(struct ctdb_context *ctdb,
        return ctdb_control_trans2_commit(ctdb, c, ctdb_marshall_finish(m), async_reply);
 }
 
+static int32_t ctdb_get_db_seqnum(struct ctdb_context *ctdb,
+                                 uint32_t db_id,
+                                 uint64_t *seqnum)
+{
+       int32_t ret;
+       struct ctdb_db_context *ctdb_db;
+       const char *keyname = CTDB_DB_SEQNUM_KEY;
+       TDB_DATA key;
+       TDB_DATA data;
+       TALLOC_CTX *mem_ctx = talloc_new(ctdb);
+
+       ctdb_db = find_ctdb_db(ctdb, db_id);
+       if (!ctdb_db) {
+               DEBUG(DEBUG_ERR,(__location__ " Unknown db 0x%08x\n", db_id));
+               ret = -1;
+               goto done;
+       }
+
+       key.dptr = (uint8_t *)discard_const(keyname);
+       key.dsize = strlen(keyname) + 1;
+
+       ret = (int32_t)ctdb_ltdb_fetch(ctdb_db, key, NULL, mem_ctx, &data);
+       if (ret != 0) {
+               goto done;
+       }
+
+       if (data.dsize != sizeof(uint64_t)) {
+               *seqnum = 0;
+               goto done;
+       }
+
+       *seqnum = *(uint64_t *)data.dptr;
 
+done:
+       talloc_free(mem_ctx);
+       return ret;
+}
+
+/**
+ * Get the sequence number of a persistent database.
+ */
+int32_t ctdb_control_get_db_seqnum(struct ctdb_context *ctdb,
+                                  TDB_DATA indata,
+                                  TDB_DATA *outdata)
+{
+       uint32_t db_id;
+       int32_t ret;
+       uint64_t seqnum;
+
+       db_id = *(uint32_t *)indata.dptr;
+       ret = ctdb_get_db_seqnum(ctdb, db_id, &seqnum);
+       if (ret != 0) {
+               goto done;
+       }
+
+       outdata->dsize = sizeof(uint64_t);
+       outdata->dptr = (uint8_t *)talloc_zero(outdata, uint64_t);
+       if (outdata->dptr == NULL) {
+               ret = -1;
+               goto done;
+       }
+
+       *(outdata->dptr) = seqnum;
+
+done:
+       return ret;
+}