1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-08 04:58:40 +03:00

LibCTDB: add get persistent db seqnum control

(This used to be ctdb commit 6e96a62494bbb2c7b0682ebf0c2115dd2f44f7af)
This commit is contained in:
Ronnie Sahlberg 2011-11-28 16:30:46 +11:00
parent 3e2c40c590
commit 3cbff2edd8
4 changed files with 137 additions and 0 deletions

View File

@ -509,6 +509,35 @@ bool ctdb_getpnn_recv(struct ctdb_connection *ctdb,
struct ctdb_request *req, uint32_t *pnn);
/**
* 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.
@ -737,6 +766,25 @@ bool ctdb_getpnn(struct ctdb_connection *ctdb,
uint32_t destnode,
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.
@ -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

View File

@ -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);
}

View File

@ -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;
}

View File

@ -4131,6 +4131,32 @@ static int control_setdbreadonly(struct ctdb_context *ctdb, int argc, const char
return 0;
}
/*
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
*/
@ -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>" },
};
/*