From: Sage Weil Date: Fri, 19 May 2017 20:38:58 +0000 (-0400) Subject: ceph-kvstore-tool: implement 'rm' and 'rm-prefix' commands X-Git-Tag: ses5-milestone6~8^2~19^2~46 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=87a993a93f5b9d85d0fe4be7140befff49894ac4;p=ceph.git ceph-kvstore-tool: implement 'rm' and 'rm-prefix' commands Signed-off-by: Sage Weil --- diff --git a/src/tools/ceph_kvstore_tool.cc b/src/tools/ceph_kvstore_tool.cc index a7384f75347..6d7ef7313ff 100644 --- a/src/tools/ceph_kvstore_tool.cc +++ b/src/tools/ceph_kvstore_tool.cc @@ -167,6 +167,27 @@ class StoreTool return (ret == 0); } + bool rm(const string& prefix, const string& key) { + assert(!prefix.empty()); + assert(!key.empty()); + + KeyValueDB::Transaction tx = db->get_transaction(); + tx->rmkey(prefix, key); + int ret = db->submit_transaction_sync(tx); + + return (ret == 0); + } + + bool rm_prefix(const string& prefix) { + assert(!prefix.empty()); + + KeyValueDB::Transaction tx = db->get_transaction(); + tx->rmkeys_by_prefix(prefix); + int ret = db->submit_transaction_sync(tx); + + return (ret == 0); + } + int copy_store_to(string type, const string &other_path, const int num_keys_per_tx) { @@ -255,6 +276,8 @@ void usage(const char *pname) << " crc \n" << " get-size [ ]\n" << " set [ver |in ]\n" + << " rm \n" + << " rm-prefix \n" << " store-copy [num-keys-per-tx]\n" << " store-crc \n" << " compact\n" @@ -434,6 +457,35 @@ int main(int argc, const char *argv[]) << url_escape(prefix) << "," << url_escape(key) << ")" << std::endl; return 1; } + } else if (cmd == "rm") { + if (argc < 6) { + usage(argv[0]); + return 1; + } + string prefix(url_unescape(argv[4])); + string key(url_unescape(argv[5])); + + bool ret = st.rm(prefix, key); + if (!ret) { + std::cerr << "error removing (" + << url_escape(prefix) << "," << url_escape(key) << ")" + << std::endl; + return 1; + } + } else if (cmd == "rm-prefix") { + if (argc < 5) { + usage(argv[0]); + return 1; + } + string prefix(url_unescape(argv[4])); + + bool ret = st.rm_prefix(prefix); + if (!ret) { + std::cerr << "error removing prefix (" + << url_escape(prefix) << ")" + << std::endl; + return 1; + } } else if (cmd == "store-copy") { int num_keys_per_tx = 128; // magic number that just feels right. if (argc < 5) {