diff options
author | Amitay Isaacs <amitay@gmail.com> | 2012-12-17 14:46:14 +1100 |
---|---|---|
committer | Amitay Isaacs <amitay@gmail.com> | 2013-01-09 13:18:33 +1100 |
commit | d8a3ec42c16b584eff5baaea572e34579c0f58a5 (patch) | |
tree | 257ff35dec6f23189dd6afad79dad052254dcd85 | |
parent | 9eeb94c5c01f3a5ed679d54cb656243267907453 (diff) | |
download | samba-d8a3ec42c16b584eff5baaea572e34579c0f58a5.tar.gz samba-d8a3ec42c16b584eff5baaea572e34579c0f58a5.tar.xz samba-d8a3ec42c16b584eff5baaea572e34579c0f58a5.zip |
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)
-rw-r--r-- | ctdb/tools/ctdb.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index a974fb2f26..f1d5d9911f 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -3934,6 +3934,72 @@ static int control_pstore(struct ctdb_context *ctdb, int argc, const char **argv } /* + * 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 */ static int control_chktcpport(struct ctdb_context *ctdb, int argc, const char **argv) @@ -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>" }, |