diff options
author | Joao Eduardo Luis <joao.luis@inktank.com> | 2013-08-12 10:26:29 -0700 |
---|---|---|
committer | Joao Eduardo Luis <joao.luis@inktank.com> | 2013-08-12 10:26:29 -0700 |
commit | 6aba8f48dd0cc2774b97d0bd376e752788a334be (patch) | |
tree | bb87934c6130905be3294d3cdf144bbd19bc5600 | |
parent | ef036bd4bc0e79bff8a5805800fbdeb0cc2db6ae (diff) | |
download | ceph-6aba8f48dd0cc2774b97d0bd376e752788a334be.tar.gz |
ceph_test_store_tool: add 'set prefix key' featurewip-store-tool
Allow reading from a file. See --help for more info.
Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/test/ObjectMap/test_store_tool/test_store_tool.cc | 56 |
2 files changed, 53 insertions, 5 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index a9bbde32686..33663698ddf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1249,7 +1249,7 @@ ceph_test_keyvaluedb_iterators_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS} ${ bin_DEBUGPROGRAMS += ceph_test_keyvaluedb_iterators ceph_test_store_tool_SOURCES = test/ObjectMap/test_store_tool/test_store_tool.cc \ - os/LevelDBStore.cc + os/LevelDBStore.cc common/strtol.cc ceph_test_store_tool_LDFLAGS = ${AM_LDFLAGS} ceph_test_store_tool_LDADD = $(LIBOS_LDA) $(LIBGLOBAL_LDA) ceph_test_store_tool_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS} diff --git a/src/test/ObjectMap/test_store_tool/test_store_tool.cc b/src/test/ObjectMap/test_store_tool/test_store_tool.cc index ace91220df6..9146db89aaa 100644 --- a/src/test/ObjectMap/test_store_tool/test_store_tool.cc +++ b/src/test/ObjectMap/test_store_tool/test_store_tool.cc @@ -24,6 +24,7 @@ #include "common/errno.h" #include "common/safe_io.h" #include "common/config.h" +#include "common/strtol.h" using namespace std; @@ -79,7 +80,7 @@ class StoreTool assert(!prefix.empty() && !key.empty()); map<string,bufferlist> result; - set<string> keys; + std::set<std::string> keys; keys.insert(key); db->get(prefix, keys, &result); @@ -90,6 +91,18 @@ class StoreTool exists = false; return bufferlist(); } + + bool set(const string &prefix, const string &key, bufferlist &val) { + assert(!prefix.empty()); + assert(!key.empty()); + assert(val.length() > 0); + + KeyValueDB::Transaction tx = db->get_transaction(); + tx->set(prefix, key, val); + int ret = db->submit_transaction_sync(tx); + + return (ret == 0); + } }; void usage(const char *pname) @@ -100,7 +113,7 @@ void usage(const char *pname) << " list [prefix]\n" << " exists <prefix> [key]\n" << " get <prefix> <key>\n" - << " verify <store path>\n" + << " set <prefix> <key> [ver <N>|in <file>]\n" << std::endl; } @@ -171,8 +184,43 @@ int main(int argc, const char *argv[]) bl.hexdump(os); std::cout << os.str() << std::endl; - } else if (cmd == "verify") { - assert(0); + } else if (cmd == "set") { + if (argc < 7) { + usage(argv[0]); + return 1; + } + string prefix(argv[3]); + string key(argv[4]); + string subcmd(argv[5]); + + bufferlist val; + string errstr; + if (subcmd == "ver") { + version_t v = (version_t) strict_strtoll(argv[6], 10, &errstr); + if (!errstr.empty()) { + std::cerr << "error reading version: " << errstr << std::endl; + return 1; + } + ::encode(v, val); + } else if (subcmd == "in") { + int ret = val.read_file(argv[6], &errstr); + if (ret < 0 || !errstr.empty()) { + std::cerr << "error reading file: " << errstr << std::endl; + return 1; + } + } else { + std::cerr << "unrecognized subcommand '" << subcmd << "'" << std::endl; + usage(argv[0]); + return 1; + } + + bool ret = st.set(prefix, key, val); + if (!ret) { + std::cerr << "error setting (" + << prefix << "," << key << ")" << std::endl; + return 1; + } + } else { std::cerr << "Unrecognized command: " << cmd << std::endl; return 1; |