Skip to content

Commit

Permalink
Merge pull request ceph#25262 from aclamk/wip-kvstore-tool-dump
Browse files Browse the repository at this point in the history
ceph-kvstore-tool: dump fixes

Reviewed-by: Sage Weil <[email protected]>
  • Loading branch information
tchaikov authored Dec 5, 2018
2 parents 52e4315 + b2a8751 commit d80000f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
3 changes: 3 additions & 0 deletions doc/man/8/ceph-kvstore-tool.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ which are as follows:
:command:`list-crc [prefix]`
Print CRC of all KV pairs stored with the URL encoded prefix.

:command:`dump [prefix]`
Print key and value of all KV pairs stored with the URL encoded prefix.

:command:`exists <prefix> [key]`
Check if there is any KV pair stored with the URL encoded prefix. If key
is also specified, check for the key with the prefix instead.
Expand Down
1 change: 1 addition & 0 deletions src/test/cli/ceph-kvstore-tool/help.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Commands:
list [prefix]
list-crc [prefix]
dump [prefix]
exists <prefix> [key]
get <prefix> <key> [out <file>]
crc <prefix> <key>
Expand Down
27 changes: 23 additions & 4 deletions src/tools/ceph_kvstore_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class StoreTool

uint32_t traverse(const string &prefix,
const bool do_crc,
const bool do_value_dump,
ostream *out) {
KeyValueDB::WholeSpaceIterator iter = db->get_wholespace_iterator();

Expand Down Expand Up @@ -119,14 +120,22 @@ class StoreTool
}
if (out)
*out << std::endl;
if (out && do_value_dump) {
bufferptr bp = iter->value_as_ptr();
bufferlist value;
value.append(bp);
ostringstream os;
value.hexdump(os);
std::cout << os.str() << std::endl;
}
iter->next();
}

return crc;
}

void list(const string &prefix, const bool do_crc) {
traverse(prefix, do_crc, &std::cout);
void list(const string &prefix, const bool do_crc, const bool do_value_dump) {
traverse(prefix, do_crc, do_value_dump, &std::cout);
}

bool exists(const string &prefix) {
Expand Down Expand Up @@ -297,6 +306,7 @@ void usage(const char *pname)
<< "Commands:\n"
<< " list [prefix]\n"
<< " list-crc [prefix]\n"
<< " dump [prefix]\n"
<< " exists <prefix> [key]\n"
<< " get <prefix> <key> [out <file>]\n"
<< " crc <prefix> <key>\n"
Expand Down Expand Up @@ -336,6 +346,10 @@ int main(int argc, const char *argv[])
CINIT_FLAG_NO_DEFAULT_CONFIG_FILE);
common_init_finish(g_ceph_context);

ceph_assert((int)args.size() < argc);
for(size_t i=0; i<args.size(); i++)
argv[i+1] = args[i];
argc = args.size() + 1;

if (args.size() < 3) {
usage(argv[0]);
Expand Down Expand Up @@ -374,8 +388,13 @@ int main(int argc, const char *argv[])
prefix = url_unescape(argv[4]);

bool do_crc = (cmd == "list-crc");
st.list(prefix, do_crc, false);

st.list(prefix, do_crc);
} else if (cmd == "dump") {
string prefix;
if (argc > 4)
prefix = url_unescape(argv[4]);
st.list(prefix, false, true);

} else if (cmd == "exists") {
string key;
Expand Down Expand Up @@ -576,7 +595,7 @@ int main(int argc, const char *argv[])
return 1;
}
std::ofstream fs(argv[4]);
uint32_t crc = st.traverse(string(), true, &fs);
uint32_t crc = st.traverse(string(), true, false, &fs);
std::cout << "store at '" << argv[4] << "' crc " << crc << std::endl;

} else if (cmd == "compact") {
Expand Down

0 comments on commit d80000f

Please sign in to comment.