mirror of
https://github.com/samba-team/samba.git
synced 2025-03-01 04:58:35 +03:00
tools/ctdb: Add pdelete command to delete a record from persistent database
Signed-off-by: Amitay Isaacs <amitay@gmail.com> (This used to be ctdb commit d23adec89b69e7c6f96c8e1417ef4ca4c9edc57e)
This commit is contained in:
parent
9eeb94c5c0
commit
d8a3ec42c1
@ -3933,6 +3933,72 @@ static int control_pstore(struct ctdb_context *ctdb, int argc, const char **argv
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* delete a record from a persistent database
|
||||
*/
|
||||
static int control_pdelete(struct ctdb_context *ctdb, int argc, const char **argv)
|
||||
{
|
||||
const char *db_name;
|
||||
struct ctdb_db_context *ctdb_db;
|
||||
TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
|
||||
struct ctdb_transaction_handle *h;
|
||||
TDB_DATA key;
|
||||
int ret;
|
||||
bool persistent;
|
||||
|
||||
if (argc < 2) {
|
||||
talloc_free(tmp_ctx);
|
||||
usage();
|
||||
}
|
||||
|
||||
db_name = argv[0];
|
||||
|
||||
if (db_exists(ctdb, db_name, &persistent)) {
|
||||
DEBUG(DEBUG_ERR, ("Database '%s' does not exist\n", db_name));
|
||||
talloc_free(tmp_ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!persistent) {
|
||||
DEBUG(DEBUG_ERR, ("Database '%s' is not persistent\n", db_name));
|
||||
talloc_free(tmp_ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), db_name, persistent, 0);
|
||||
if (ctdb_db == NULL) {
|
||||
DEBUG(DEBUG_ERR, ("Unable to attach to database '%s'\n", db_name));
|
||||
talloc_free(tmp_ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
h = ctdb_transaction_start(ctdb_db, tmp_ctx);
|
||||
if (h == NULL) {
|
||||
DEBUG(DEBUG_ERR, ("Failed to start transaction on database %s\n", db_name));
|
||||
talloc_free(tmp_ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
key.dptr = discard_const(argv[1]);
|
||||
key.dsize = strlen(argv[1]);
|
||||
ret = ctdb_transaction_store(h, key, tdb_null);
|
||||
if (ret != 0) {
|
||||
DEBUG(DEBUG_ERR, ("Failed to delete record\n"));
|
||||
talloc_free(tmp_ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = ctdb_transaction_commit(h);
|
||||
if (ret != 0) {
|
||||
DEBUG(DEBUG_ERR, ("Failed to commit transaction\n"));
|
||||
talloc_free(tmp_ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
talloc_free(tmp_ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
check if a service is bound to a port or not
|
||||
*/
|
||||
@ -5878,6 +5944,7 @@ static const struct {
|
||||
{ "sync", control_ipreallocate, false, false, "wait until ctdbd has synced all state changes" },
|
||||
{ "pfetch", control_pfetch, false, false, "fetch a record from a persistent database", "<db> <key> [<file>]" },
|
||||
{ "pstore", control_pstore, false, false, "write a record to a persistent database", "<db> <key> <file containing record>" },
|
||||
{ "pdelete", control_pdelete, false, false, "delete a record from a persistent database", "<db> <key>" },
|
||||
{ "tfetch", control_tfetch, false, true, "fetch a record from a [c]tdb-file [-v]", "<tdb-file> <key> [<file>]" },
|
||||
{ "tstore", control_tstore, false, true, "store a record (including ltdb header)", "<tdb-file> <key> <data+header>" },
|
||||
{ "readkey", control_readkey, true, false, "read the content off a database key", "<tdb-file> <key>" },
|
||||
|
Loading…
x
Reference in New Issue
Block a user