From 0a7695a546705d6599ad45a89dde078c0b456fdb Mon Sep 17 00:00:00 2001 From: Roman Gershman Date: Fri, 12 Dec 2025 13:49:59 +0200 Subject: [PATCH] chore: reduce boilerplate by removing redundant function declarations Signed-off-by: Roman Gershman --- src/server/bloom_family.cc | 16 ++--- src/server/bloom_family.h | 11 --- src/server/hset_family.cc | 38 +++++----- src/server/hset_family.h | 20 ------ src/server/list_family.cc | 44 ++++++------ src/server/list_family.h | 27 ------- src/server/stream_family.cc | 32 ++++----- src/server/stream_family.h | 24 ------- src/server/string_family.cc | 56 +++++++-------- src/server/string_family.h | 29 -------- src/server/zset_family.cc | 138 +++++++++++++++++++----------------- src/server/zset_family.h | 37 ---------- 12 files changed, 166 insertions(+), 306 deletions(-) diff --git a/src/server/bloom_family.cc b/src/server/bloom_family.cc index 3c92e255ea9c..c08087fe2933 100644 --- a/src/server/bloom_family.cc +++ b/src/server/bloom_family.cc @@ -87,9 +87,7 @@ OpResult OpExists(const OpArgs& op_args, string_view key, CmdArgLi return result; } -} // namespace - -void BloomFamily::Reserve(CmdArgList args, CommandContext* cmd_cntx) { +void CmdReserve(CmdArgList args, CommandContext* cmd_cntx) { CmdArgParser parser(args); string_view key = parser.Next(); SbfParams params; @@ -113,7 +111,7 @@ void BloomFamily::Reserve(CmdArgList args, CommandContext* cmd_cntx) { return rb->SendError(res); } -void BloomFamily::Add(CmdArgList args, CommandContext* cmd_cntx) { +void CmdAdd(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); args.remove_prefix(1); @@ -133,7 +131,7 @@ void BloomFamily::Add(CmdArgList args, CommandContext* cmd_cntx) { return cmd_cntx->rb->SendError(status); } -void BloomFamily::Exists(CmdArgList args, CommandContext* cmd_cntx) { +void CmdExists(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); args.remove_prefix(1); const auto cb = [&](Transaction* t, EngineShard* shard) { @@ -144,7 +142,7 @@ void BloomFamily::Exists(CmdArgList args, CommandContext* cmd_cntx) { return cmd_cntx->rb->SendLong(res ? res->front() : 0); } -void BloomFamily::MAdd(CmdArgList args, CommandContext* cmd_cntx) { +void CmdMAdd(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); args.remove_prefix(1); @@ -169,7 +167,7 @@ void BloomFamily::MAdd(CmdArgList args, CommandContext* cmd_cntx) { } } -void BloomFamily::MExists(CmdArgList args, CommandContext* cmd_cntx) { +void CmdMExists(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); args.remove_prefix(1); @@ -186,9 +184,11 @@ void BloomFamily::MExists(CmdArgList args, CommandContext* cmd_cntx) { } } +} // namespace + using CI = CommandId; -#define HFUNC(x) SetHandler(&BloomFamily::x) +#define HFUNC(x) SetHandler(&Cmd##x) void BloomFamily::Register(CommandRegistry* registry) { registry->StartFamily(); diff --git a/src/server/bloom_family.h b/src/server/bloom_family.h index ff3913fee768..fd07bba3e817 100644 --- a/src/server/bloom_family.h +++ b/src/server/bloom_family.h @@ -6,10 +6,6 @@ #include "server/common.h" -namespace facade { -class SinkReplyBuilder; -} // namespace facade - namespace dfly { class CommandRegistry; @@ -20,13 +16,6 @@ class BloomFamily { static void Register(CommandRegistry* registry); private: - using SinkReplyBuilder = facade::SinkReplyBuilder; - - static void Reserve(CmdArgList args, CommandContext* cmd_cntx); - static void Add(CmdArgList args, CommandContext* cmd_cntx); - static void MAdd(CmdArgList args, CommandContext* cmd_cntx); - static void Exists(CmdArgList args, CommandContext* cmd_cntx); - static void MExists(CmdArgList args, CommandContext* cmd_cntx); }; } // namespace dfly diff --git a/src/server/hset_family.cc b/src/server/hset_family.cc index c638d6fe9882..00e63c93fdf3 100644 --- a/src/server/hset_family.cc +++ b/src/server/hset_family.cc @@ -609,9 +609,7 @@ struct HSetReplies { facade::SinkReplyBuilder* rb; }; -} // namespace - -void HSetFamily::HDel(CmdArgList args, CommandContext* cmd_cntx) { +void CmdHDel(CmdArgList args, CommandContext* cmd_cntx) { auto cb = [&](HMapWrap& hw) -> OpResult { unsigned deleted = 0; for (string_view s : args.subspan(1)) @@ -621,7 +619,7 @@ void HSetFamily::HDel(CmdArgList args, CommandContext* cmd_cntx) { HSetReplies{cmd_cntx->rb}.Send(cmd_cntx->tx->ScheduleSingleHopT(WrapW(cb))); } -void HSetFamily::HExpire(CmdArgList args, CommandContext* cmd_cntx) { +void CmdHExpire(CmdArgList args, CommandContext* cmd_cntx) { CmdArgParser parser{args}; using MinMaxTtl = FInt<0, (1 << 26)>; auto [key, ttl_sec] = parser.Next(); @@ -666,7 +664,7 @@ void HSetFamily::HExpire(CmdArgList args, CommandContext* cmd_cntx) { }; } -void HSetFamily::HGet(CmdArgList args, CommandContext* cmd_cntx) { +void CmdHGet(CmdArgList args, CommandContext* cmd_cntx) { auto cb = [field = args[1]](const HMapWrap& hw) -> OpResult { if (auto it = hw.Find(field); it) return string{it->second}; @@ -685,7 +683,7 @@ void HSetFamily::HGet(CmdArgList args, CommandContext* cmd_cntx) { }; } -void HSetFamily::HMGet(CmdArgList args, CommandContext* cmd_cntx) { +void CmdHMGet(CmdArgList args, CommandContext* cmd_cntx) { auto fields = args.subspan(1); auto cb = [fields](const HMapWrap& hw) { return OpHMGet(hw, fields); }; @@ -707,7 +705,7 @@ void HSetFamily::HMGet(CmdArgList args, CommandContext* cmd_cntx) { }; } -void HSetFamily::HStrLen(CmdArgList args, CommandContext* cmd_cntx) { +void CmdHStrLen(CmdArgList args, CommandContext* cmd_cntx) { auto cb = [field = ArgS(args, 1)](const HMapWrap& hw) -> OpResult { if (auto it = hw.Find(field); it) return it->second.length(); @@ -716,19 +714,19 @@ void HSetFamily::HStrLen(CmdArgList args, CommandContext* cmd_cntx) { HSetReplies{cmd_cntx->rb}.Send(ExecuteRO(cmd_cntx->tx, cb)); } -void HSetFamily::HLen(CmdArgList args, CommandContext* cmd_cntx) { +void CmdHLen(CmdArgList args, CommandContext* cmd_cntx) { auto cb = [](const HMapWrap& hw) -> OpResult { return hw.Length(); }; HSetReplies{cmd_cntx->rb}.Send(ExecuteRO(cmd_cntx->tx, cb)); } -void HSetFamily::HExists(CmdArgList args, CommandContext* cmd_cntx) { +void CmdHExists(CmdArgList args, CommandContext* cmd_cntx) { auto cb = [field = args[1]](const HMapWrap& hw) -> OpResult { return hw.Find(field) ? 1 : 0; }; HSetReplies{cmd_cntx->rb}.Send(ExecuteRO(cmd_cntx->tx, cb)); } -void HSetFamily::HIncrBy(CmdArgList args, CommandContext* cmd_cntx) { +void CmdHIncrBy(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); string_view field = ArgS(args, 1); string_view incrs = ArgS(args, 2); @@ -763,7 +761,7 @@ void HSetFamily::HIncrBy(CmdArgList args, CommandContext* cmd_cntx) { } } -void HSetFamily::HIncrByFloat(CmdArgList args, CommandContext* cmd_cntx) { +void CmdHIncrByFloat(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); string_view field = ArgS(args, 1); string_view incrs = ArgS(args, 2); @@ -796,19 +794,19 @@ void HSetFamily::HIncrByFloat(CmdArgList args, CommandContext* cmd_cntx) { } } -void HSetFamily::HKeys(CmdArgList args, CommandContext* cmd_cntx) { +void CmdHKeys(CmdArgList args, CommandContext* cmd_cntx) { HGetGeneric(args, FIELDS, cmd_cntx->tx, cmd_cntx->rb); } -void HSetFamily::HVals(CmdArgList args, CommandContext* cmd_cntx) { +void CmdHVals(CmdArgList args, CommandContext* cmd_cntx) { HGetGeneric(args, VALUES, cmd_cntx->tx, cmd_cntx->rb); } -void HSetFamily::HGetAll(CmdArgList args, CommandContext* cmd_cntx) { +void CmdHGetAll(CmdArgList args, CommandContext* cmd_cntx) { HGetGeneric(args, GetAllMode::FIELDS | GetAllMode::VALUES, cmd_cntx->tx, cmd_cntx->rb); } -void HSetFamily::HScan(CmdArgList args, CommandContext* cmd_cntx) { +void CmdHScan(CmdArgList args, CommandContext* cmd_cntx) { std::string_view token = ArgS(args, 1); uint64_t cursor = 0; auto* rb = static_cast(cmd_cntx->rb); @@ -847,7 +845,7 @@ void HSetFamily::HScan(CmdArgList args, CommandContext* cmd_cntx) { } } -void HSetFamily::HSet(CmdArgList args, CommandContext* cmd_cntx) { +void CmdHSet(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); string_view cmd{cmd_cntx->cid->name()}; @@ -870,7 +868,7 @@ void HSetFamily::HSet(CmdArgList args, CommandContext* cmd_cntx) { } } -void HSetFamily::HSetNx(CmdArgList args, CommandContext* cmd_cntx) { +void CmdHSetNx(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); auto cb = [&](Transaction* t, EngineShard* shard) { @@ -887,7 +885,7 @@ void StrVecEmplaceBack(StringVec& str_vec, const listpackEntry& lp) { str_vec.emplace_back(absl::StrCat(lp.lval)); } -void HSetFamily::HRandField(CmdArgList args, CommandContext* cmd_cntx) { +void CmdHRandField(CmdArgList args, CommandContext* cmd_cntx) { auto* rb = static_cast(cmd_cntx->rb); if (args.size() > 3) { DVLOG(1) << "Wrong number of command arguments: " << args.size(); @@ -1020,9 +1018,11 @@ void HSetFamily::HRandField(CmdArgList args, CommandContext* cmd_cntx) { } } +} // namespace + using CI = CommandId; -#define HFUNC(x) SetHandler(&HSetFamily::x) +#define HFUNC(x) SetHandler(&Cmd##x) void HSetFamily::Register(CommandRegistry* registry) { registry->StartFamily(acl::HASH); diff --git a/src/server/hset_family.h b/src/server/hset_family.h index b3175e0e4207..34fe3660e935 100644 --- a/src/server/hset_family.h +++ b/src/server/hset_family.h @@ -30,26 +30,6 @@ class HSetFamily { static std::vector SetFieldsExpireTime(const OpArgs& op_args, uint32_t ttl_sec, ExpireFlags flags, std::string_view key, CmdArgList values, PrimeValue* pv); - - private: - using SinkReplyBuilder = facade::SinkReplyBuilder; - - static void HExpire(CmdArgList args, CommandContext* cmd_cntx); - static void HDel(CmdArgList args, CommandContext* cmd_cntx); - static void HLen(CmdArgList args, CommandContext* cmd_cntx); - static void HExists(CmdArgList args, CommandContext* cmd_cntx); - static void HGet(CmdArgList args, CommandContext* cmd_cntx); - static void HMGet(CmdArgList args, CommandContext* cmd_cntx); - static void HIncrBy(CmdArgList args, CommandContext* cmd_cntx); - static void HKeys(CmdArgList args, CommandContext* cmd_cntx); - static void HVals(CmdArgList args, CommandContext* cmd_cntx); - static void HGetAll(CmdArgList args, CommandContext* cmd_cntx); - static void HIncrByFloat(CmdArgList args, CommandContext* cmd_cntx); - static void HScan(CmdArgList args, CommandContext* cmd_cntx); - static void HSet(CmdArgList args, CommandContext* cmd_cntx); - static void HSetNx(CmdArgList args, CommandContext* cmd_cntx); - static void HStrLen(CmdArgList args, CommandContext* cmd_cntx); - static void HRandField(CmdArgList args, CommandContext* cmd_cntx); }; } // namespace dfly diff --git a/src/server/list_family.cc b/src/server/list_family.cc index 5aa2eec08522..2e8fc3bb3059 100644 --- a/src/server/list_family.cc +++ b/src/server/list_family.cc @@ -925,9 +925,7 @@ optional> GetFirstNonEmptyKeyFound(EngineShard* shard, T return result; } -} // namespace - -void ListFamily::LMPop(CmdArgList args, CommandContext* cmd_cntx) { +void CmdLMPop(CmdArgList args, CommandContext* cmd_cntx) { auto* response_builder = static_cast(cmd_cntx->rb); CmdArgParser parser{args}; @@ -1009,7 +1007,7 @@ void ListFamily::LMPop(CmdArgList args, CommandContext* cmd_cntx) { } } -void ListFamily::BLMPop(CmdArgList args, CommandContext* cmd_cntx) { +void CmdBLMPop(CmdArgList args, CommandContext* cmd_cntx) { auto* response_builder = static_cast(cmd_cntx->rb); CmdArgParser parser{args}; @@ -1050,31 +1048,31 @@ void ListFamily::BLMPop(CmdArgList args, CommandContext* cmd_cntx) { } } -void ListFamily::LPush(CmdArgList args, CommandContext* cmd_cntx) { +void CmdLPush(CmdArgList args, CommandContext* cmd_cntx) { return PushGeneric(ListDir::LEFT, false, args, cmd_cntx->tx, cmd_cntx->rb); } -void ListFamily::LPushX(CmdArgList args, CommandContext* cmd_cntx) { +void CmdLPushX(CmdArgList args, CommandContext* cmd_cntx) { return PushGeneric(ListDir::LEFT, true, args, cmd_cntx->tx, cmd_cntx->rb); } -void ListFamily::LPop(CmdArgList args, CommandContext* cmd_cntx) { +void CmdLPop(CmdArgList args, CommandContext* cmd_cntx) { return PopGeneric(ListDir::LEFT, args, cmd_cntx->tx, cmd_cntx->rb); } -void ListFamily::RPush(CmdArgList args, CommandContext* cmd_cntx) { +void CmdRPush(CmdArgList args, CommandContext* cmd_cntx) { return PushGeneric(ListDir::RIGHT, false, args, cmd_cntx->tx, cmd_cntx->rb); } -void ListFamily::RPushX(CmdArgList args, CommandContext* cmd_cntx) { +void CmdRPushX(CmdArgList args, CommandContext* cmd_cntx) { return PushGeneric(ListDir::RIGHT, true, args, cmd_cntx->tx, cmd_cntx->rb); } -void ListFamily::RPop(CmdArgList args, CommandContext* cmd_cntx) { +void CmdRPop(CmdArgList args, CommandContext* cmd_cntx) { return PopGeneric(ListDir::RIGHT, args, cmd_cntx->tx, cmd_cntx->rb); } -void ListFamily::LLen(CmdArgList args, CommandContext* cmd_cntx) { +void CmdLLen(CmdArgList args, CommandContext* cmd_cntx) { auto key = ArgS(args, 0); auto cb = [&](Transaction* t, EngineShard* shard) { return OpLen(t->GetOpArgs(shard), key); }; OpResult result = cmd_cntx->tx->ScheduleSingleHopT(std::move(cb)); @@ -1087,7 +1085,7 @@ void ListFamily::LLen(CmdArgList args, CommandContext* cmd_cntx) { } } -void ListFamily::LPos(CmdArgList args, CommandContext* cmd_cntx) { +void CmdLPos(CmdArgList args, CommandContext* cmd_cntx) { facade::CmdArgParser parser{args}; auto [key, elem] = parser.Next(); @@ -1147,7 +1145,7 @@ void ListFamily::LPos(CmdArgList args, CommandContext* cmd_cntx) { } } -void ListFamily::LIndex(CmdArgList args, CommandContext* cmd_cntx) { +void CmdLIndex(CmdArgList args, CommandContext* cmd_cntx) { std::string_view key = ArgS(args, 0); std::string_view index_str = ArgS(args, 1); int32_t index; @@ -1173,7 +1171,7 @@ void ListFamily::LIndex(CmdArgList args, CommandContext* cmd_cntx) { } /* LINSERT (BEFORE|AFTER) */ -void ListFamily::LInsert(CmdArgList args, CommandContext* cmd_cntx) { +void CmdLInsert(CmdArgList args, CommandContext* cmd_cntx) { facade::CmdArgParser parser{args}; string_view key = parser.Next(); InsertParam where = parser.MapNext("AFTER", INSERT_AFTER, "BEFORE", INSERT_BEFORE); @@ -1196,7 +1194,7 @@ void ListFamily::LInsert(CmdArgList args, CommandContext* cmd_cntx) { rb->SendError(result.status()); } -void ListFamily::LTrim(CmdArgList args, CommandContext* cmd_cntx) { +void CmdLTrim(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); string_view s_str = ArgS(args, 1); string_view e_str = ArgS(args, 2); @@ -1216,7 +1214,7 @@ void ListFamily::LTrim(CmdArgList args, CommandContext* cmd_cntx) { cmd_cntx->rb->SendError(st); } -void ListFamily::LRange(CmdArgList args, CommandContext* cmd_cntx) { +void CmdLRange(CmdArgList args, CommandContext* cmd_cntx) { std::string_view key = ArgS(args, 0); std::string_view s_str = ArgS(args, 1); std::string_view e_str = ArgS(args, 2); @@ -1241,7 +1239,7 @@ void ListFamily::LRange(CmdArgList args, CommandContext* cmd_cntx) { } // lrem key 5 foo, will remove foo elements from the list if exists at most 5 times. -void ListFamily::LRem(CmdArgList args, CommandContext* cmd_cntx) { +void CmdLRem(CmdArgList args, CommandContext* cmd_cntx) { std::string_view key = ArgS(args, 0); std::string_view index_str = ArgS(args, 1); std::string_view elem = ArgS(args, 2); @@ -1262,7 +1260,7 @@ void ListFamily::LRem(CmdArgList args, CommandContext* cmd_cntx) { cmd_cntx->rb->SendError(result.status()); } -void ListFamily::LSet(CmdArgList args, CommandContext* cmd_cntx) { +void CmdLSet(CmdArgList args, CommandContext* cmd_cntx) { std::string_view key = ArgS(args, 0); std::string_view index_str = ArgS(args, 1); std::string_view elem = ArgS(args, 2); @@ -1284,15 +1282,15 @@ void ListFamily::LSet(CmdArgList args, CommandContext* cmd_cntx) { } } -void ListFamily::BLPop(CmdArgList args, CommandContext* cmd_cntx) { +void CmdBLPop(CmdArgList args, CommandContext* cmd_cntx) { BPopGeneric(ListDir::LEFT, args, cmd_cntx->tx, cmd_cntx->rb, cmd_cntx->conn_cntx); } -void ListFamily::BRPop(CmdArgList args, CommandContext* cmd_cntx) { +void CmdBRPop(CmdArgList args, CommandContext* cmd_cntx) { BPopGeneric(ListDir::RIGHT, args, cmd_cntx->tx, cmd_cntx->rb, cmd_cntx->conn_cntx); } -void ListFamily::LMove(CmdArgList args, CommandContext* cmd_cntx) { +void CmdLMove(CmdArgList args, CommandContext* cmd_cntx) { facade::CmdArgParser parser{args}; auto [src, dest] = parser.Next(); ListDir src_dir = ParseDir(&parser); @@ -1304,9 +1302,11 @@ void ListFamily::LMove(CmdArgList args, CommandContext* cmd_cntx) { MoveGeneric(src, dest, src_dir, dest_dir, cmd_cntx->tx, cmd_cntx->rb); } +} // namespace + using CI = CommandId; -#define HFUNC(x) SetHandler(&ListFamily::x) +#define HFUNC(x) SetHandler(&Cmd##x) void ListFamily::Register(CommandRegistry* registry) { registry->StartFamily(acl::LIST); diff --git a/src/server/list_family.h b/src/server/list_family.h index 5b913535792c..cffe49f73dd0 100644 --- a/src/server/list_family.h +++ b/src/server/list_family.h @@ -7,10 +7,6 @@ #include "facade/op_status.h" #include "server/common.h" -namespace facade { -class SinkReplyBuilder; -} // namespace facade - namespace dfly { using facade::OpResult; @@ -21,29 +17,6 @@ struct CommandContext; class ListFamily { public: static void Register(CommandRegistry* registry); - - private: - using SinkReplyBuilder = facade::SinkReplyBuilder; - - static void LPush(CmdArgList args, CommandContext* cmd_cntx); - static void LPushX(CmdArgList args, CommandContext* cmd_cntx); - static void RPush(CmdArgList args, CommandContext* cmd_cntx); - static void RPushX(CmdArgList args, CommandContext* cmd_cntx); - static void LPop(CmdArgList args, CommandContext* cmd_cntx); - static void RPop(CmdArgList args, CommandContext* cmd_cntx); - static void BLPop(CmdArgList args, CommandContext* cmd_cntx); - static void BRPop(CmdArgList args, CommandContext* cmd_cntx); - static void LMPop(CmdArgList args, CommandContext* cmd_cntx); - static void BLMPop(CmdArgList args, CommandContext* cmd_cntx); - static void LLen(CmdArgList args, CommandContext* cmd_cntx); - static void LPos(CmdArgList args, CommandContext* cmd_cntx); - static void LIndex(CmdArgList args, CommandContext* cmd_cntx); - static void LInsert(CmdArgList args, CommandContext* cmd_cntx); - static void LTrim(CmdArgList args, CommandContext* cmd_cntx); - static void LRange(CmdArgList args, CommandContext* cmd_cntx); - static void LRem(CmdArgList args, CommandContext* cmd_cntx); - static void LSet(CmdArgList args, CommandContext* cmd_cntx); - static void LMove(CmdArgList args, CommandContext* cmd_cntx); }; } // namespace dfly diff --git a/src/server/stream_family.cc b/src/server/stream_family.cc index b27d65f59b81..deb14488b5eb 100644 --- a/src/server/stream_family.cc +++ b/src/server/stream_family.cc @@ -2673,7 +2673,7 @@ bool ParseXpendingOptions(CmdArgList& args, PendingOpts& opts, SinkReplyBuilder* } // namespace -void StreamFamily::XAdd(CmdArgList args, CommandContext* cmd_cntx) { +void CmdXAdd(CmdArgList args, CommandContext* cmd_cntx) { CmdArgParser parser{args}; auto* rb = static_cast(cmd_cntx->rb); @@ -2787,7 +2787,7 @@ bool ParseXclaimOptions(CmdArgList& args, ClaimOpts& opts, SinkReplyBuilder* bui return true; } -void StreamFamily::XClaim(CmdArgList args, CommandContext* cmd_cntx) { +void CmdXClaim(CmdArgList args, CommandContext* cmd_cntx) { ClaimOpts opts; string_view key = ArgS(args, 0); opts.group = ArgS(args, 1); @@ -2832,7 +2832,7 @@ void StreamFamily::XClaim(CmdArgList args, CommandContext* cmd_cntx) { StreamReplies{cmd_cntx->rb}.SendClaimInfo(result.value()); } -void StreamFamily::XDel(CmdArgList args, CommandContext* cmd_cntx) { +void CmdXDel(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); args.remove_prefix(1); @@ -2859,7 +2859,7 @@ void StreamFamily::XDel(CmdArgList args, CommandContext* cmd_cntx) { cmd_cntx->rb->SendError(result.status()); } -void StreamFamily::XGroup(CmdArgList args, CommandContext* cmd_cntx) { +void CmdXGroup(CmdArgList args, CommandContext* cmd_cntx) { facade::CmdArgParser parser{args}; auto sub_cmd_func = parser.MapNext("HELP", &HelpSubCmd, "CREATE", &CreateGroup, "DESTROY", @@ -2872,7 +2872,7 @@ void StreamFamily::XGroup(CmdArgList args, CommandContext* cmd_cntx) { sub_cmd_func(&parser, cmd_cntx->tx, cmd_cntx->rb); } -void StreamFamily::XInfo(CmdArgList args, CommandContext* cmd_cntx) { +void CmdXInfo(CmdArgList args, CommandContext* cmd_cntx) { auto* rb = static_cast(cmd_cntx->rb); string sub_cmd = absl::AsciiStrToUpper(ArgS(args, 0)); @@ -3130,7 +3130,7 @@ void StreamFamily::XInfo(CmdArgList args, CommandContext* cmd_cntx) { return rb->SendError(UnknownSubCmd(sub_cmd, "XINFO")); } -void StreamFamily::XLen(CmdArgList args, CommandContext* cmd_cntx) { +void CmdXLen(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); auto cb = [&](Transaction* t, EngineShard* shard) { return OpLen(t->GetOpArgs(shard), key); }; @@ -3142,7 +3142,7 @@ void StreamFamily::XLen(CmdArgList args, CommandContext* cmd_cntx) { return cmd_cntx->rb->SendError(result.status()); } -void StreamFamily::XPending(CmdArgList args, CommandContext* cmd_cntx) { +void CmdXPending(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); PendingOpts opts; opts.group_name = ArgS(args, 1); @@ -3200,7 +3200,7 @@ void StreamFamily::XPending(CmdArgList args, CommandContext* cmd_cntx) { } } -void StreamFamily::XRange(CmdArgList args, CommandContext* cmd_cntx) { +void CmdXRange(CmdArgList args, CommandContext* cmd_cntx) { string_view key = args[0]; string_view start = args[1]; string_view end = args[2]; @@ -3208,7 +3208,7 @@ void StreamFamily::XRange(CmdArgList args, CommandContext* cmd_cntx) { XRangeGeneric(key, start, end, args.subspan(3), false, cmd_cntx->tx, cmd_cntx->rb); } -void StreamFamily::XRevRange(CmdArgList args, CommandContext* cmd_cntx) { +void CmdXRevRange(CmdArgList args, CommandContext* cmd_cntx) { string_view key = args[0]; string_view start = args[1]; string_view end = args[2]; @@ -3278,15 +3278,15 @@ variant HasEntries2(const OpArgs& op_args, string_view return streamCompareID(&last_id, &requested_sitem.id.val) >= 0; } -void StreamFamily::XRead(CmdArgList args, CommandContext* cmd_cntx) { +void CmdXRead(CmdArgList args, CommandContext* cmd_cntx) { return XReadGeneric2(args, false, cmd_cntx->tx, cmd_cntx->rb, cmd_cntx->conn_cntx); } -void StreamFamily::XReadGroup(CmdArgList args, CommandContext* cmd_cntx) { +void CmdXReadGroup(CmdArgList args, CommandContext* cmd_cntx) { return XReadGeneric2(args, true, cmd_cntx->tx, cmd_cntx->rb, cmd_cntx->conn_cntx); } -void StreamFamily::XSetId(CmdArgList args, CommandContext* cmd_cntx) { +void CmdXSetId(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); string_view idstr = ArgS(args, 1); @@ -3308,7 +3308,7 @@ void StreamFamily::XSetId(CmdArgList args, CommandContext* cmd_cntx) { return cmd_cntx->rb->SendError(reply); } -void StreamFamily::XTrim(CmdArgList args, CommandContext* cmd_cntx) { +void CmdXTrim(CmdArgList args, CommandContext* cmd_cntx) { CmdArgParser parser{args}; auto* rb = static_cast(cmd_cntx->rb); @@ -3341,7 +3341,7 @@ void StreamFamily::XTrim(CmdArgList args, CommandContext* cmd_cntx) { } } -void StreamFamily::XAck(CmdArgList args, CommandContext* cmd_cntx) { +void CmdXAck(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); string_view group = ArgS(args, 1); args.remove_prefix(2); @@ -3368,7 +3368,7 @@ void StreamFamily::XAck(CmdArgList args, CommandContext* cmd_cntx) { cmd_cntx->rb->SendError(result.status()); } -void StreamFamily::XAutoClaim(CmdArgList args, CommandContext* cmd_cntx) { +void CmdXAutoClaim(CmdArgList args, CommandContext* cmd_cntx) { ClaimOpts opts; string_view key = ArgS(args, 0); opts.group = ArgS(args, 1); @@ -3440,7 +3440,7 @@ void StreamFamily::XAutoClaim(CmdArgList args, CommandContext* cmd_cntx) { StreamReplies{rb}.SendIDs(cresult.deleted_ids); } -#define HFUNC(x) SetHandler(&StreamFamily::x) +#define HFUNC(x) SetHandler(&Cmd##x) namespace acl { constexpr uint32_t kXAdd = WRITE | STREAM | FAST; diff --git a/src/server/stream_family.h b/src/server/stream_family.h index 2af9064fa01e..c99e7352a034 100644 --- a/src/server/stream_family.h +++ b/src/server/stream_family.h @@ -6,14 +6,9 @@ #include "server/common.h" -namespace facade { -class SinkReplyBuilder; -} // namespace facade - namespace dfly { class CommandRegistry; -struct CommandContext; class CompactObj; using PrimeValue = CompactObj; @@ -31,25 +26,6 @@ class StreamMemTracker { class StreamFamily { public: static void Register(CommandRegistry* registry); - - private: - using SinkReplyBuilder = facade::SinkReplyBuilder; - - static void XAdd(CmdArgList args, CommandContext* cmd_cntx); - static void XClaim(CmdArgList args, CommandContext* cmd_cntx); - static void XDel(CmdArgList args, CommandContext* cmd_cntx); - static void XGroup(CmdArgList args, CommandContext* cmd_cntx); - static void XInfo(CmdArgList args, CommandContext* cmd_cntx); - static void XLen(CmdArgList args, CommandContext* cmd_cntx); - static void XPending(CmdArgList args, CommandContext* cmd_cntx); - static void XRevRange(CmdArgList args, CommandContext* cmd_cntx); - static void XRange(CmdArgList args, CommandContext* cmd_cntx); - static void XRead(CmdArgList args, CommandContext* cmd_cntx); - static void XReadGroup(CmdArgList args, CommandContext* cmd_cntx); - static void XSetId(CmdArgList args, CommandContext* cmd_cntx); - static void XTrim(CmdArgList args, CommandContext* cmd_cntx); - static void XAck(CmdArgList args, CommandContext* cmd_cntx); - static void XAutoClaim(CmdArgList args, CommandContext* cmd_cntx); }; } // namespace dfly diff --git a/src/server/string_family.cc b/src/server/string_family.cc index 77187d758bc2..3f442c834f81 100644 --- a/src/server/string_family.cc +++ b/src/server/string_family.cc @@ -112,7 +112,7 @@ class SetCmd { bool explicit_journal_; // call RecordJournal (auto journaling disabled) }; -size_t SetRange(std::string* value, size_t start, std::string_view range) { +size_t SetRangeInternal(std::string* value, size_t start, std::string_view range) { value->resize(max(value->size(), start + range.size())); memcpy(value->data() + start, range.data(), range.size()); return value->size(); @@ -157,7 +157,7 @@ OpResult> OpSetRange(const OpArgs& op_args, string_view key, return {op_args.shard->tiered_storage()->Modify( op_args.db_cntx.db_index, key, res.it->second, [start = start, range = string(range)](std::string* s) { - return SetRange(s, start, range); + return SetRangeInternal(s, start, range); })}; } else { string value; @@ -165,7 +165,7 @@ OpResult> OpSetRange(const OpArgs& op_args, string_view key, if (!res.is_new) value = res.it->second.ToString(); - size_t len = SetRange(&value, start, range); + size_t len = SetRangeInternal(&value, start, range); res.it->second.SetValue(value); return {len}; } @@ -812,8 +812,6 @@ MGetResponse OpGAT(BlockingCounter wait_bc, AggregateError* err, uint8_t fetch_m return CollectKeys(std::move(wait_bc), err, fetch_mask, t, shard, std::move(find_op)); } -} // namespace - OpStatus SetCmd::Set(const SetParams& params, string_view key, string_view value) { auto& db_slice = op_args_.GetDbSlice(); @@ -984,7 +982,7 @@ OpStatus SetCmd::CachePrevIfNeeded(const SetCmd::SetParams& params, DbSlice::Ite return OpStatus::OK; } -void StringFamily::Set(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdSet(CmdArgList args, CommandContext* cmnd_cntx) { facade::CmdArgParser parser{args}; auto [key, value] = parser.Next(); @@ -1092,7 +1090,7 @@ void StringFamily::Set(CmdArgList args, CommandContext* cmnd_cntx) { } /// (P)SETEX key seconds (milliseconds) value -void StringFamily::SetExGeneric(CmdArgList args, CommandContext* cmd_cntx) { +void CmdSetExGeneric(CmdArgList args, CommandContext* cmd_cntx) { string_view cmd_name = cmd_cntx->cid->name(); CmdArgParser parser{args}; @@ -1122,7 +1120,7 @@ void StringFamily::SetExGeneric(CmdArgList args, CommandContext* cmd_cntx) { builder->SendError(SetGeneric(sparams, key, value, *cmd_cntx)); } -void StringFamily::SetNx(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdSetNx(CmdArgList args, CommandContext* cmnd_cntx) { string_view key = ArgS(args, 0); string_view value = ArgS(args, 1); @@ -1142,7 +1140,7 @@ void StringFamily::SetNx(CmdArgList args, CommandContext* cmnd_cntx) { } } -void StringFamily::Get(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdGet(CmdArgList args, CommandContext* cmnd_cntx) { auto cb = [key = ArgS(args, 0)](Transaction* tx, EngineShard* es) -> OpResult { auto it_res = tx->GetDbSlice(es->shard_id()).FindReadOnly(tx->GetDbContext(), key, OBJ_STRING); if (!it_res.ok()) @@ -1154,7 +1152,7 @@ void StringFamily::Get(CmdArgList args, CommandContext* cmnd_cntx) { GetReplies{cmnd_cntx->rb}.Send(cmnd_cntx->tx->ScheduleSingleHopT(cb)); } -void StringFamily::GetDel(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdGetDel(CmdArgList args, CommandContext* cmnd_cntx) { auto cb = [key = ArgS(args, 0)](Transaction* tx, EngineShard* es) -> OpResult { auto& db_slice = tx->GetDbSlice(es->shard_id()); auto it_res = db_slice.FindMutable(tx->GetDbContext(), key, OBJ_STRING); @@ -1169,7 +1167,7 @@ void StringFamily::GetDel(CmdArgList args, CommandContext* cmnd_cntx) { GetReplies{cmnd_cntx->rb}.Send(cmnd_cntx->tx->ScheduleSingleHopT(cb)); } -void StringFamily::GetSet(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdGetSet(CmdArgList args, CommandContext* cmnd_cntx) { string_view key = ArgS(args, 0); string_view value = ArgS(args, 1); @@ -1182,15 +1180,15 @@ void StringFamily::GetSet(CmdArgList args, CommandContext* cmnd_cntx) { GetReplies{cmnd_cntx->rb}.Send(std::move(prev)); } -void StringFamily::Append(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdAppend(CmdArgList args, CommandContext* cmnd_cntx) { ExtendGeneric(args, false, cmnd_cntx->tx, cmnd_cntx->rb); } -void StringFamily::Prepend(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdPrepend(CmdArgList args, CommandContext* cmnd_cntx) { ExtendGeneric(args, true, cmnd_cntx->tx, cmnd_cntx->rb); } -void StringFamily::GetEx(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdGetEx(CmdArgList args, CommandContext* cmnd_cntx) { CmdArgParser parser{args}; string_view key = parser.Next(); @@ -1258,12 +1256,12 @@ void StringFamily::GetEx(CmdArgList args, CommandContext* cmnd_cntx) { GetReplies{cmnd_cntx->rb}.Send(cmnd_cntx->tx->ScheduleSingleHopT(cb)); } -void StringFamily::Incr(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdIncr(CmdArgList args, CommandContext* cmnd_cntx) { string_view key = ArgS(args, 0); return IncrByGeneric(key, 1, cmnd_cntx->tx, cmnd_cntx->rb); } -void StringFamily::IncrBy(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdIncrBy(CmdArgList args, CommandContext* cmnd_cntx) { string_view key = ArgS(args, 0); string_view sval = ArgS(args, 1); int64_t val; @@ -1274,7 +1272,7 @@ void StringFamily::IncrBy(CmdArgList args, CommandContext* cmnd_cntx) { return IncrByGeneric(key, val, cmnd_cntx->tx, cmnd_cntx->rb); } -void StringFamily::IncrByFloat(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdIncrByFloat(CmdArgList args, CommandContext* cmnd_cntx) { string_view key = ArgS(args, 0); string_view sval = ArgS(args, 1); double val; @@ -1298,12 +1296,12 @@ void StringFamily::IncrByFloat(CmdArgList args, CommandContext* cmnd_cntx) { rb->SendDouble(result.value()); } -void StringFamily::Decr(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdDecr(CmdArgList args, CommandContext* cmnd_cntx) { string_view key = ArgS(args, 0); return IncrByGeneric(key, -1, cmnd_cntx->tx, cmnd_cntx->rb); } -void StringFamily::DecrBy(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdDecrBy(CmdArgList args, CommandContext* cmnd_cntx) { string_view key = ArgS(args, 0); string_view sval = ArgS(args, 1); int64_t val; @@ -1340,7 +1338,7 @@ void ReorderShardResults(absl::Span mget_resp, const Transaction* } } -void StringFamily::MGet(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdMGet(CmdArgList args, CommandContext* cmnd_cntx) { DCHECK_GE(args.size(), 1U); uint8_t fetch_mask = 0; @@ -1398,7 +1396,7 @@ void StringFamily::MGet(CmdArgList args, CommandContext* cmnd_cntx) { } } -void StringFamily::MSet(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdMSet(CmdArgList args, CommandContext* cmnd_cntx) { if (VLOG_IS_ON(2)) { string str; for (size_t i = 1; i < args.size(); ++i) { @@ -1425,7 +1423,7 @@ void StringFamily::MSet(CmdArgList args, CommandContext* cmnd_cntx) { } } -void StringFamily::MSetNx(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdMSetNx(CmdArgList args, CommandContext* cmnd_cntx) { atomic_bool exists{false}; auto cb = [&](Transaction* t, EngineShard* es) { @@ -1462,14 +1460,14 @@ void StringFamily::MSetNx(CmdArgList args, CommandContext* cmnd_cntx) { cmnd_cntx->rb->SendLong(to_skip || (*result != OpStatus::OK) ? 0 : 1); } -void StringFamily::StrLen(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdStrLen(CmdArgList args, CommandContext* cmnd_cntx) { auto cb = [key = ArgS(args, 0)](Transaction* t, EngineShard* shard) { return OpStrLen(t->GetOpArgs(shard), key); }; GetReplies{cmnd_cntx->rb}.Send(cmnd_cntx->tx->ScheduleSingleHopT(cb)); } -void StringFamily::GetRange(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdGetRange(CmdArgList args, CommandContext* cmnd_cntx) { CmdArgParser parser(args); auto [key, start, end] = parser.Next(); @@ -1484,7 +1482,7 @@ void StringFamily::GetRange(CmdArgList args, CommandContext* cmnd_cntx) { GetReplies{cmnd_cntx->rb}.Send(cmnd_cntx->tx->ScheduleSingleHopT(cb)); } -void StringFamily::SetRange(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdSetRange(CmdArgList args, CommandContext* cmnd_cntx) { CmdArgParser parser(args); auto [key, start, value] = parser.Next(); auto* builder = cmnd_cntx->rb; @@ -1520,7 +1518,7 @@ void StringFamily::SetRange(CmdArgList args, CommandContext* cmnd_cntx) { * 5. The number of seconds until the limit will reset to its maximum capacity. * Equivalent to X-RateLimit-Reset. */ -void StringFamily::ClThrottle(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdClThrottle(CmdArgList args, CommandContext* cmnd_cntx) { constexpr uint64_t kSecondToNanoSecond = 1000000000; const string_view key = ArgS(args, 0); @@ -1628,7 +1626,7 @@ void StringFamily::ClThrottle(CmdArgList args, CommandContext* cmnd_cntx) { // Implements the memcache GAT command. The expected input is // GAT key [keys...] -void StringFamily::GAT(CmdArgList args, CommandContext* cmnd_cntx) { +void CmdGAT(CmdArgList args, CommandContext* cmnd_cntx) { DCHECK_GE(args.size(), 1U); auto* builder = cmnd_cntx->rb; @@ -1681,7 +1679,9 @@ void StringFamily::GAT(CmdArgList args, CommandContext* cmnd_cntx) { rb->SendGetEnd(); } -#define HFUNC(x) SetHandler(&StringFamily::x) +} // namespace + +#define HFUNC(x) SetHandler(&Cmd##x) void StringFamily::Register(CommandRegistry* registry) { constexpr uint32_t kMSetMask = diff --git a/src/server/string_family.h b/src/server/string_family.h index c2bf1fc3ce30..57b4ee530eea 100644 --- a/src/server/string_family.h +++ b/src/server/string_family.h @@ -18,35 +18,6 @@ class CommandRegistry; class StringFamily { public: static void Register(CommandRegistry* registry); - - private: - using SinkReplyBuilder = facade::SinkReplyBuilder; - using CmdArgList = facade::CmdArgList; - - static void Append(CmdArgList args, CommandContext* cmnd_cntx); - static void Decr(CmdArgList args, CommandContext* cmnd_cntx); - static void DecrBy(CmdArgList args, CommandContext* cmnd_cntx); - static void Get(CmdArgList args, CommandContext* cmnd_cntx); - static void GetDel(CmdArgList args, CommandContext* cmnd_cntx); - static void GetRange(CmdArgList args, CommandContext* cmnd_cntx); - static void GetSet(CmdArgList args, CommandContext* cmnd_cntx); - static void GetEx(CmdArgList args, CommandContext* cmnd_cntx); - static void Incr(CmdArgList args, CommandContext* cmnd_cntx); - static void IncrBy(CmdArgList args, CommandContext* cmnd_cntx); - static void IncrByFloat(CmdArgList args, CommandContext* cmnd_cntx); - static void MGet(CmdArgList args, CommandContext* cmnd_cntx); - static void MSet(CmdArgList args, CommandContext* cmnd_cntx); - static void MSetNx(CmdArgList args, CommandContext* cmnd_cntx); - - static void Set(CmdArgList args, CommandContext* cmnd_cntx); - static void SetNx(CmdArgList args, CommandContext* cmnd_cntx); - static void SetRange(CmdArgList args, CommandContext* cmnd_cntx); - static void SetExGeneric(CmdArgList args, CommandContext* cmnd_cntx); - static void StrLen(CmdArgList args, CommandContext* cmnd_cntx); - static void Prepend(CmdArgList args, CommandContext* cmnd_cntx); - - static void ClThrottle(CmdArgList args, CommandContext* cmnd_cntx); - static void GAT(CmdArgList args, CommandContext* cmnd_cntx); }; } // namespace dfly diff --git a/src/server/zset_family.cc b/src/server/zset_family.cc index 61009dc280ec..5aa429fee8da 100644 --- a/src/server/zset_family.cc +++ b/src/server/zset_family.cc @@ -2088,15 +2088,17 @@ OpResult ZSetFamily::OpScore(const OpArgs& op_args, string_view key, str return *res; } -void ZSetFamily::BZPopMin(CmdArgList args, CommandContext* cmd_cntx) { +namespace { + +void CmdBZPopMin(CmdArgList args, CommandContext* cmd_cntx) { BZPopMinMax(args, cmd_cntx->tx, cmd_cntx->rb, cmd_cntx->conn_cntx, false); } -void ZSetFamily::BZPopMax(CmdArgList args, CommandContext* cmd_cntx) { +void CmdBZPopMax(CmdArgList args, CommandContext* cmd_cntx) { BZPopMinMax(args, cmd_cntx->tx, cmd_cntx->rb, cmd_cntx->conn_cntx, true); } -void ZSetFamily::ZAdd(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZAdd(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); ZSetFamily::ZParams zparams; @@ -2191,10 +2193,10 @@ void ZSetFamily::ZAdd(CmdArgList args, CommandContext* cmd_cntx) { } absl::Span memb_sp{members.data(), members.size()}; - ZAddGeneric(key, zparams, memb_sp, cmd_cntx->tx, builder); + ZSetFamily::ZAddGeneric(key, zparams, memb_sp, cmd_cntx->tx, builder); } -void ZSetFamily::ZCard(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZCard(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); auto cb = [&](Transaction* t, EngineShard* shard) -> OpResult { @@ -2215,13 +2217,13 @@ void ZSetFamily::ZCard(CmdArgList args, CommandContext* cmd_cntx) { cmd_cntx->rb->SendLong(result.value()); } -void ZSetFamily::ZCount(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZCount(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); string_view min_s = ArgS(args, 1); string_view max_s = ArgS(args, 2); - ScoreInterval si; + ZSetFamily::ScoreInterval si; if (!ParseBound(min_s, &si.first) || !ParseBound(max_s, &si.second)) { return cmd_cntx->rb->SendError(kFloatRangeErr); } @@ -2244,7 +2246,8 @@ vector ZDiffOp(ShardId key_sid, vector ZDiffOp(ShardId key_sid, vector>> maps(shard_set->size(), OpStatus::OK); auto cb = [&](Transaction* t, EngineShard* shard) { @@ -2331,7 +2334,7 @@ void ZSetFamily::ZDiff(CmdArgList args, CommandContext* cmd_cntx) { } } -void ZSetFamily::ZDiffStore(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZDiffStore(CmdArgList args, CommandContext* cmd_cntx) { vector>> maps(shard_set->size(), OpStatus::OK); const string_view dest_key = ArgS(args, 0); const ShardId dest_shard = Shard(dest_key, shard_set->size()); @@ -2376,7 +2379,7 @@ void ZSetFamily::ZDiffStore(CmdArgList args, CommandContext* cmd_cntx) { rb->SendLong(smvec.size()); } -void ZSetFamily::ZIncrBy(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZIncrBy(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); string_view score_arg = ArgS(args, 1); @@ -2398,10 +2401,11 @@ void ZSetFamily::ZIncrBy(CmdArgList args, CommandContext* cmd_cntx) { zparams.flags = ZADD_IN_INCR; auto cb = [&](Transaction* t, EngineShard* shard) { - return OpAdd(t->GetOpArgs(shard), zparams, key, ScoredMemberSpan{&scored_member, 1}); + return ZSetFamily::OpAdd(t->GetOpArgs(shard), zparams, key, + ScoredMemberSpan{&scored_member, 1}); }; - OpResult add_result = cmd_cntx->tx->ScheduleSingleHopT(std::move(cb)); + OpResult add_result = cmd_cntx->tx->ScheduleSingleHopT(std::move(cb)); if (add_result.status() == OpStatus::WRONG_TYPE) { return rb->SendError(kWrongTypeErr); } @@ -2417,15 +2421,15 @@ void ZSetFamily::ZIncrBy(CmdArgList args, CommandContext* cmd_cntx) { rb->SendDouble(add_result->new_score); } -void ZSetFamily::ZInter(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZInter(CmdArgList args, CommandContext* cmd_cntx) { ZBooleanOperation(args, "zinter", false, false, cmd_cntx->tx, cmd_cntx->rb); } -void ZSetFamily::ZInterStore(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZInterStore(CmdArgList args, CommandContext* cmd_cntx) { ZBooleanOperation(args, "zinterstore", false, true, cmd_cntx->tx, cmd_cntx->rb); } -void ZSetFamily::ZInterCard(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZInterCard(CmdArgList args, CommandContext* cmd_cntx) { unsigned num_keys; auto* builder = cmd_cntx->rb; @@ -2462,15 +2466,15 @@ void ZSetFamily::ZInterCard(CmdArgList args, CommandContext* cmd_cntx) { } // Generic function for ZMPop and BZMPop commands -void ZMPopGeneric(CmdArgList args, const CommandContext& cmd_cntx, bool is_blocking) { +void ZMPopGeneric(CmdArgList args, CommandContext* cmd_cntx, bool is_blocking) { ValidateZMPopResult zmpop_args; - if (!ValidateZMPopCommand(args, is_blocking, cmd_cntx.rb, &zmpop_args)) { + if (!ValidateZMPopCommand(args, is_blocking, cmd_cntx->rb, &zmpop_args)) { return; } - auto* response_builder = static_cast(cmd_cntx.rb); + auto* response_builder = static_cast(cmd_cntx->rb); - // From the list of input keys, keep the first (in the order of keys in the command) key found in - // the current shard. + // From the list of input keys, keep the first (in the order of keys in the command) key found + // in the current shard. std::vector> first_found_key_per_shard_vec(shard_set->size(), std::nullopt); @@ -2482,7 +2486,7 @@ void ZMPopGeneric(CmdArgList args, const CommandContext& cmd_cntx, bool is_block return OpStatus::OK; }; - cmd_cntx.tx->Execute(std::move(cb), false /* possibly another hop */); + cmd_cntx->tx->Execute(std::move(cb), false /* possibly another hop */); // Keep all the keys found (first only for each shard) in a set for fast lookups. absl::flat_hash_set first_found_keys_for_shard; @@ -2495,8 +2499,8 @@ void ZMPopGeneric(CmdArgList args, const CommandContext& cmd_cntx, bool is_block first_found_keys_for_shard.insert(*key); } - // Now that we have the first non empty key from each shard, find the first overall first key and - // pop elements from it. + // Now that we have the first non empty key from each shard, find the first overall first key + // and pop elements from it. std::optional key_to_pop = std::nullopt; // BZMPOP have 1 extra argument as compared to ZMPOP hence adding 1 is is_blocking is true ArgRange arg_keys(args.subspan(1 + is_blocking, zmpop_args.num_keys)); @@ -2508,15 +2512,15 @@ void ZMPopGeneric(CmdArgList args, const CommandContext& cmd_cntx, bool is_block } } - if (!key_to_pop.has_value() && (!is_blocking || cmd_cntx.tx->IsMulti())) { - cmd_cntx.tx->Conclude(); + if (!key_to_pop.has_value() && (!is_blocking || cmd_cntx->tx->IsMulti())) { + cmd_cntx->tx->Conclude(); response_builder->SendNull(); return; } // if we don't have any key to pop and it's blocking then we will block it using `WaitOnWatch` if (is_blocking && !key_to_pop.has_value()) { - auto trans = cmd_cntx.tx; - auto cntx = cmd_cntx.conn_cntx; + auto trans = cmd_cntx->tx; + auto cntx = cmd_cntx->conn_cntx; auto* ns = &trans->GetNamespace(); auto limit_tp = Transaction::time_point::max(); @@ -2553,7 +2557,7 @@ void ZMPopGeneric(CmdArgList args, const CommandContext& cmd_cntx, bool is_block // Pop elements from relevant set. OpResult pop_result = ZPopMinMaxInternal( - *key_to_pop, FilterShards::YES, zmpop_args.pop_count, zmpop_args.is_max, cmd_cntx.tx); + *key_to_pop, FilterShards::YES, zmpop_args.pop_count, zmpop_args.is_max, cmd_cntx->tx); if (pop_result.status() == OpStatus::WRONG_TYPE) { return response_builder->SendError(kWrongTypeErr); @@ -2563,29 +2567,29 @@ void ZMPopGeneric(CmdArgList args, const CommandContext& cmd_cntx, bool is_block response_builder->SendLabeledScoredArray(*key_to_pop, pop_result.value()); } -void ZSetFamily::ZMPop(CmdArgList args, CommandContext* cmd_cntx) { - ZMPopGeneric(args, *cmd_cntx, false); +void CmdZMPop(CmdArgList args, CommandContext* cmd_cntx) { + ZMPopGeneric(args, cmd_cntx, false); } -void ZSetFamily::BZMPop(CmdArgList args, CommandContext* cmd_cntx) { - ZMPopGeneric(args, *cmd_cntx, true); +void CmdBZMPop(CmdArgList args, CommandContext* cmd_cntx) { + ZMPopGeneric(args, cmd_cntx, true); } -void ZSetFamily::ZPopMax(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZPopMax(CmdArgList args, CommandContext* cmd_cntx) { ZPopMinMaxFromArgs(args, true, cmd_cntx->tx, cmd_cntx->rb); } -void ZSetFamily::ZPopMin(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZPopMin(CmdArgList args, CommandContext* cmd_cntx) { ZPopMinMaxFromArgs(args, false, cmd_cntx->tx, cmd_cntx->rb); } -void ZSetFamily::ZLexCount(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZLexCount(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); string_view min_s = ArgS(args, 1); string_view max_s = ArgS(args, 2); - LexInterval li; + ZSetFamily::LexInterval li; if (!ParseLexBound(min_s, &li.first) || !ParseLexBound(max_s, &li.second)) { return cmd_cntx->rb->SendError(kLexRangeErr); } @@ -2602,95 +2606,97 @@ void ZSetFamily::ZLexCount(CmdArgList args, CommandContext* cmd_cntx) { } } -void ZSetFamily::ZRange(CmdArgList args, CommandContext* cmd_cntx) { +using RangeParams = ZSetFamily::RangeParams; + +void CmdZRange(CmdArgList args, CommandContext* cmd_cntx) { ZRangeGeneric(args, cmd_cntx->tx, cmd_cntx->rb, RangeParams{}); } -void ZSetFamily::ZRank(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZRank(CmdArgList args, CommandContext* cmd_cntx) { ZRankGeneric(args, false, cmd_cntx->tx, cmd_cntx->rb); } -void ZSetFamily::ZRevRange(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZRevRange(CmdArgList args, CommandContext* cmd_cntx) { ZRangeGeneric(args, cmd_cntx->tx, cmd_cntx->rb, RangeParams{.reverse = true}); } -void ZSetFamily::ZRangeByScore(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZRangeByScore(CmdArgList args, CommandContext* cmd_cntx) { ZRangeGeneric(args, cmd_cntx->tx, cmd_cntx->rb, RangeParams{.interval_type = RangeParams::SCORE}); } -void ZSetFamily::ZRangeStore(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZRangeStore(CmdArgList args, CommandContext* cmd_cntx) { ZRangeGeneric(args.subspan(1), cmd_cntx->tx, cmd_cntx->rb, RangeParams{.with_scores = true, .store_key = ArgS(args, 0)}); } -void ZSetFamily::ZRevRangeByScore(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZRevRangeByScore(CmdArgList args, CommandContext* cmd_cntx) { ZRangeGeneric(args, cmd_cntx->tx, cmd_cntx->rb, RangeParams{.reverse = true, .interval_type = RangeParams::SCORE}); } -void ZSetFamily::ZRevRank(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZRevRank(CmdArgList args, CommandContext* cmd_cntx) { ZRankGeneric(args, true, cmd_cntx->tx, cmd_cntx->rb); } -void ZSetFamily::ZRangeByLex(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZRangeByLex(CmdArgList args, CommandContext* cmd_cntx) { ZRangeGeneric(args, cmd_cntx->tx, cmd_cntx->rb, RangeParams{.interval_type = RangeParams::LEX}); } -void ZSetFamily::ZRevRangeByLex(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZRevRangeByLex(CmdArgList args, CommandContext* cmd_cntx) { ZRangeGeneric(args, cmd_cntx->tx, cmd_cntx->rb, RangeParams{.reverse = true, .interval_type = RangeParams::LEX}); } -void ZSetFamily::ZRemRangeByRank(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZRemRangeByRank(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); string_view min_s = ArgS(args, 1); string_view max_s = ArgS(args, 2); - IndexInterval ii; + ZSetFamily::IndexInterval ii; if (!SimpleAtoi(min_s, &ii.first) || !SimpleAtoi(max_s, &ii.second)) { return cmd_cntx->rb->SendError(kInvalidIntErr); } - ZRangeSpec range_spec; + ZSetFamily::ZRangeSpec range_spec; range_spec.interval = ii; ZRemRangeGeneric(key, range_spec, cmd_cntx->tx, cmd_cntx->rb); } -void ZSetFamily::ZRemRangeByScore(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZRemRangeByScore(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); string_view min_s = ArgS(args, 1); string_view max_s = ArgS(args, 2); - ScoreInterval si; + ZSetFamily::ScoreInterval si; if (!ParseBound(min_s, &si.first) || !ParseBound(max_s, &si.second)) { return cmd_cntx->rb->SendError(kFloatRangeErr); } - ZRangeSpec range_spec; + ZSetFamily::ZRangeSpec range_spec; range_spec.interval = si; ZRemRangeGeneric(key, range_spec, cmd_cntx->tx, cmd_cntx->rb); } -void ZSetFamily::ZRemRangeByLex(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZRemRangeByLex(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); string_view min_s = ArgS(args, 1); string_view max_s = ArgS(args, 2); - LexInterval li; + ZSetFamily::LexInterval li; if (!ParseLexBound(min_s, &li.first) || !ParseLexBound(max_s, &li.second)) { return cmd_cntx->rb->SendError(kLexRangeErr); } - ZRangeSpec range_spec; + ZSetFamily::ZRangeSpec range_spec; range_spec.interval = li; ZRemRangeGeneric(key, range_spec, cmd_cntx->tx, cmd_cntx->rb); } -void ZSetFamily::ZRem(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZRem(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); auto members = args.subspan(1); auto cb = [&](Transaction* t, EngineShard* shard) { @@ -2705,7 +2711,7 @@ void ZSetFamily::ZRem(CmdArgList args, CommandContext* cmd_cntx) { } } -void ZSetFamily::ZRandMember(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZRandMember(CmdArgList args, CommandContext* cmd_cntx) { auto* rb = static_cast(cmd_cntx->rb); if (args.size() > 3) @@ -2744,12 +2750,12 @@ void ZSetFamily::ZRandMember(CmdArgList args, CommandContext* cmd_cntx) { } } -void ZSetFamily::ZScore(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZScore(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); string_view member = ArgS(args, 1); auto cb = [&](Transaction* t, EngineShard* shard) { - return OpScore(t->GetOpArgs(shard), key, member); + return ZSetFamily::OpScore(t->GetOpArgs(shard), key, member); }; auto* rb = static_cast(cmd_cntx->rb); @@ -2763,10 +2769,10 @@ void ZSetFamily::ZScore(CmdArgList args, CommandContext* cmd_cntx) { } } -void ZSetFamily::ZMScore(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZMScore(CmdArgList args, CommandContext* cmd_cntx) { auto* rb = static_cast(cmd_cntx->rb); - OpResult result = ZGetMembers(args, cmd_cntx->tx, rb); + OpResult result = ZSetFamily::ZGetMembers(args, cmd_cntx->tx, rb); if (result.status() == OpStatus::WRONG_TYPE) { return rb->SendError(kWrongTypeErr); @@ -2782,7 +2788,7 @@ void ZSetFamily::ZMScore(CmdArgList args, CommandContext* cmd_cntx) { } } -void ZSetFamily::ZScan(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZScan(CmdArgList args, CommandContext* cmd_cntx) { string_view key = ArgS(args, 0); string_view token = ArgS(args, 1); @@ -2818,15 +2824,17 @@ void ZSetFamily::ZScan(CmdArgList args, CommandContext* cmd_cntx) { } } -void ZSetFamily::ZUnion(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZUnion(CmdArgList args, CommandContext* cmd_cntx) { ZBooleanOperation(args, "zunion", true, false, cmd_cntx->tx, cmd_cntx->rb); } -void ZSetFamily::ZUnionStore(CmdArgList args, CommandContext* cmd_cntx) { +void CmdZUnionStore(CmdArgList args, CommandContext* cmd_cntx) { ZBooleanOperation(args, "zunionstore", true, true, cmd_cntx->tx, cmd_cntx->rb); } -#define HFUNC(x) SetHandler(&ZSetFamily::x) +} // namespace + +#define HFUNC(x) SetHandler(&Cmd##x) void ZSetFamily::Register(CommandRegistry* registry) { constexpr uint32_t kStoreMask = diff --git a/src/server/zset_family.h b/src/server/zset_family.h index 1d24c6c44301..1fb7e8277ba2 100644 --- a/src/server/zset_family.h +++ b/src/server/zset_family.h @@ -99,43 +99,6 @@ class ZSetFamily { static OpResult OpScore(const OpArgs& op_args, std::string_view key, std::string_view member); - - private: - static void BZPopMin(CmdArgList args, CommandContext* cmd_cntx); - static void BZPopMax(CmdArgList args, CommandContext* cmd_cntx); - static void ZAdd(CmdArgList args, CommandContext* cmd_cntx); - static void ZCard(CmdArgList args, CommandContext* cmd_cntx); - static void ZCount(CmdArgList args, CommandContext* cmd_cntx); - static void ZDiff(CmdArgList args, CommandContext* cmd_cntx); - static void ZDiffStore(CmdArgList args, CommandContext* cmd_cntx); - static void ZIncrBy(CmdArgList args, CommandContext* cmd_cntx); - static void ZInterStore(CmdArgList args, CommandContext* cmd_cntx); - static void ZInter(CmdArgList args, CommandContext* cmd_cntx); - static void ZInterCard(CmdArgList args, CommandContext* cmd_cntx); - static void ZLexCount(CmdArgList args, CommandContext* cmd_cntx); - static void ZMPop(CmdArgList args, CommandContext* cmd_cntx); - static void BZMPop(CmdArgList args, CommandContext* cmd_cntx); - static void ZPopMax(CmdArgList args, CommandContext* cmd_cntx); - static void ZPopMin(CmdArgList args, CommandContext* cmd_cntx); - static void ZRange(CmdArgList args, CommandContext* cmd_cntx); - static void ZRank(CmdArgList args, CommandContext* cmd_cntx); - static void ZRem(CmdArgList args, CommandContext* cmd_cntx); - static void ZRandMember(CmdArgList args, CommandContext* cmd_cntx); - static void ZScore(CmdArgList args, CommandContext* cmd_cntx); - static void ZMScore(CmdArgList args, CommandContext* cmd_cntx); - static void ZRangeByLex(CmdArgList args, CommandContext* cmd_cntx); - static void ZRevRangeByLex(CmdArgList args, CommandContext* cmd_cntx); - static void ZRangeByScore(CmdArgList args, CommandContext* cmd_cntx); - static void ZRangeStore(CmdArgList args, CommandContext* cmd_cntx); - static void ZRemRangeByRank(CmdArgList args, CommandContext* cmd_cntx); - static void ZRemRangeByScore(CmdArgList args, CommandContext* cmd_cntx); - static void ZRemRangeByLex(CmdArgList args, CommandContext* cmd_cntx); - static void ZRevRange(CmdArgList args, CommandContext* cmd_cntx); - static void ZRevRangeByScore(CmdArgList args, CommandContext* cmd_cntx); - static void ZRevRank(CmdArgList args, CommandContext* cmd_cntx); - static void ZScan(CmdArgList args, CommandContext* cmd_cntx); - static void ZUnion(CmdArgList args, CommandContext* cmd_cntx); - static void ZUnionStore(CmdArgList args, CommandContext* cmd_cntx); }; } // namespace dfly