Skip to content

Commit 3725100

Browse files
authored
fix: Allow JSON.DEBUG HELP to work without key parameter (#5919)
1 parent 7112f15 commit 3725100

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/server/json_family.cc

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "server/error.h"
3030
#include "server/journal/journal.h"
3131
#include "server/search/doc_index.h"
32+
#include "server/sharding.h"
3233
#include "server/string_family.h"
3334
#include "server/tiered_storage.h"
3435
#include "server/transaction.h"
@@ -1738,11 +1739,15 @@ void JsonFamily::Debug(CmdArgList args, const CommandContext& cmd_cntx) {
17381739

17391740
WrappedJsonPath json_path = GET_OR_SEND_UNEXPECTED(ParseJsonPath(path));
17401741

1741-
auto cb = [&](Transaction* t, EngineShard* shard) {
1742-
return OpMemory(t->GetOpArgs(shard), key, json_path);
1742+
ShardId sid = Shard(key, shard_set->size());
1743+
auto cb = [&]() {
1744+
EngineShard* shard = EngineShard::tlocal();
1745+
DbContext db_cntx{cmd_cntx.conn_cntx->ns, cmd_cntx.conn_cntx->conn_state.db_index};
1746+
OpArgs op_args{shard, nullptr, db_cntx};
1747+
return OpMemory(op_args, key, json_path);
17431748
};
17441749

1745-
auto result = cmd_cntx.tx->ScheduleSingleHopT(std::move(cb));
1750+
auto result = shard_set->Await(sid, std::move(cb));
17461751
auto* rb = static_cast<RedisReplyBuilder*>(builder);
17471752
reply_generic::Send(result, rb);
17481753
return;
@@ -1755,11 +1760,15 @@ void JsonFamily::Debug(CmdArgList args, const CommandContext& cmd_cntx) {
17551760

17561761
WrappedJsonPath json_path = GET_OR_SEND_UNEXPECTED(ParseJsonPath(path));
17571762

1758-
auto cb = [&](Transaction* t, EngineShard* shard) {
1759-
return OpFields(t->GetOpArgs(shard), key, json_path);
1763+
ShardId sid = Shard(key, shard_set->size());
1764+
auto cb = [&]() {
1765+
EngineShard* shard = EngineShard::tlocal();
1766+
DbContext db_cntx{cmd_cntx.conn_cntx->ns, cmd_cntx.conn_cntx->conn_state.db_index};
1767+
OpArgs op_args{shard, nullptr, db_cntx};
1768+
return OpFields(op_args, key, json_path);
17601769
};
17611770

1762-
auto result = cmd_cntx.tx->ScheduleSingleHopT(std::move(cb));
1771+
auto result = shard_set->Await(sid, std::move(cb));
17631772
auto* rb = static_cast<RedisReplyBuilder*>(builder);
17641773
reply_generic::Send(result, rb);
17651774
return;
@@ -2221,8 +2230,7 @@ void JsonFamily::Register(CommandRegistry* registry) {
22212230
*registry << CI{"JSON.ARRAPPEND", CO::WRITE | CO::DENYOOM | CO::FAST, -4, 1, 1, acl::JSON}.HFUNC(
22222231
ArrAppend);
22232232
*registry << CI{"JSON.ARRINDEX", CO::READONLY | CO::FAST, -4, 1, 1, acl::JSON}.HFUNC(ArrIndex);
2224-
// TODO: Support negative first_key index to revive the debug sub-command
2225-
*registry << CI{"JSON.DEBUG", CO::READONLY | CO::FAST, -3, 2, 2, acl::JSON}.HFUNC(Debug)
2233+
*registry << CI{"JSON.DEBUG", CO::READONLY | CO::FAST, -2, 0, 0, acl::JSON}.HFUNC(Debug)
22262234
<< CI{"JSON.RESP", CO::READONLY | CO::FAST, -2, 1, 1, acl::JSON}.HFUNC(Resp)
22272235
<< CI{"JSON.SET", CO::WRITE | CO::DENYOOM | CO::FAST, -4, 1, 1, acl::JSON}.HFUNC(Set)
22282236
<< CI{"JSON.MSET", kMsetFlags, -4, 1, -1, acl::JSON}.HFUNC(MSet)

src/server/json_family_test.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,6 +2632,16 @@ TEST_F(JsonFamilyTest, MGetLegacy) {
26322632
EXPECT_THAT(resp.GetVec(), ElementsAre(R"(3)", R"(6)"));
26332633
}
26342634

2635+
TEST_F(JsonFamilyTest, DebugHelp) {
2636+
auto resp = Run({"JSON.DEBUG", "HELP"});
2637+
ASSERT_EQ(RespExpr::ARRAY, resp.type);
2638+
EXPECT_EQ(resp.GetVec().size(), 3);
2639+
2640+
EXPECT_THAT(resp.GetVec()[0].GetString(), HasSubstr("MEMORY"));
2641+
EXPECT_THAT(resp.GetVec()[1].GetString(), HasSubstr("FIELDS"));
2642+
EXPECT_THAT(resp.GetVec()[2].GetString(), HasSubstr("HELP"));
2643+
}
2644+
26352645
TEST_F(JsonFamilyTest, DebugFields) {
26362646
string json = R"(
26372647
[1, 2.3, "foo", true, null, {}, [], {"a":1, "b":2}, [1,2,3]]

0 commit comments

Comments
 (0)