Skip to content

Commit

Permalink
Multiget LDB Followup
Browse files Browse the repository at this point in the history
  • Loading branch information
jaykorean committed Feb 5, 2024
1 parent 1a885fe commit 7ee31ed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions tools/ldb_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2876,6 +2876,8 @@ void GetCommand::DoCommand() {
if (st.ok()) {
fprintf(stdout, "%s\n",
(is_value_hex_ ? StringToHex(value) : value).c_str());
} else if (st.IsNotFound()) {
fprintf(stdout, "Key not found\n");
} else {
std::stringstream oss;
oss << "Get failed: " << st.ToString();
Expand Down Expand Up @@ -2906,7 +2908,6 @@ void MultiGetCommand::Help(std::string& ret) {
ret.append(" ");
ret.append(MultiGetCommand::Name());
ret.append(" <key_1> <key_2> <key_3> ...");
ret.append(" [--" + ARG_TTL + "]");
ret.append("\n");
}

Expand All @@ -2928,8 +2929,12 @@ void MultiGetCommand::DoCommand() {
bool failed = false;
for (size_t i = 0; i < num_keys; ++i) {
if (statuses[i].ok()) {
fprintf(stdout, is_value_hex_ ? "0x%s\n" : "%s\n",
fprintf(stdout, is_value_hex_ ? "%s%s0x%s\n" : "%s%s%s\n",
(is_key_hex_ ? StringToHex(keys_[i]) : keys_[i]).c_str(), DELIM,
values[i].ToString(is_value_hex_).c_str());
} else if (statuses[i].IsNotFound()) {
fprintf(stdout, "Key not found: %s\n",
(is_key_hex_ ? StringToHex(keys_[i]) : keys_[i]).c_str());
} else {
fprintf(stderr, "Status for key %s: %s\n",
(is_key_hex_ ? StringToHex(keys_[i]) : keys_[i]).c_str(),
Expand Down
6 changes: 5 additions & 1 deletion tools/ldb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ def testSimpleStringPutGet(self):
self.assertRunOK("put x2 y2", "OK")
self.assertRunOK("get x1", "y1")
self.assertRunOK("get x2", "y2")
self.assertRunFAIL("get x3")
self.assertRunOK("multi_get x1 x2", "x1 ==> y1\nx2 ==> y2")
self.assertRunOK("get x3", "Key not found")
self.assertRunOK("multi_get x3", "Key not found: x3")

self.assertRunFAIL("put_entity x4")
self.assertRunFAIL("put_entity x4 cv1")
Expand Down Expand Up @@ -311,6 +313,8 @@ def testHexPutGet(self):
self.assertRunOK("get --hex 0x6131", "0x6231")
self.assertRunOK("get a2", "b2")
self.assertRunOK("get --hex 0x6132", "0x6232")
self.assertRunOK("multi_get --hex 0x6131 0x6132", "0x6131 ==> 0x6231\n0x6132 ==> 0x6232")
self.assertRunOK("multi_get --hex 0x6131 0xBEEF", "0x6131 ==> 0x6231\nKey not found: 0xBEEF")
self.assertRunOK("get --key_hex 0x6132", "b2")
self.assertRunOK("get --key_hex --value_hex 0x6132", "0x6232")
self.assertRunOK("get --value_hex a2", "0x6232")
Expand Down
2 changes: 2 additions & 0 deletions tools/ldb_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//
#include "rocksdb/ldb_tool.h"

#include "ldb_cmd_impl.h"
#include "rocksdb/utilities/ldb_cmd.h"
#include "tools/ldb_cmd_impl.h"

Expand Down Expand Up @@ -90,6 +91,7 @@ void LDBCommandRunner::PrintHelp(const LDBOptions& ldb_options,
ret.append("Data Access Commands:\n");
PutCommand::Help(ret);
GetCommand::Help(ret);
MultiGetCommand::Help(ret);
BatchPutCommand::Help(ret);
ScanCommand::Help(ret);
DeleteCommand::Help(ret);
Expand Down

0 comments on commit 7ee31ed

Please sign in to comment.