git-hulk commented on code in PR #2954:
URL: https://github.com/apache/kvrocks/pull/2954#discussion_r2104290925
##########
src/commands/cmd_server.cc:
##########
@@ -309,6 +309,58 @@ class CommandDBSize : public Commander {
}
};
+class CommandSlotSize : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ if (args.size() < 2 || args.size() > 3) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
Review Comment:
```suggestion
if (args.size() > 3) {
return {Status::RedisParseErr, errWrongNumOfArguments};
}
```
##########
src/commands/cmd_server.cc:
##########
@@ -309,6 +309,58 @@ class CommandDBSize : public Commander {
}
};
+class CommandSlotSize : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ if (args.size() < 2 || args.size() > 3) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
+ if (args.size() == 3 && !util::EqualICase(args[2], "scan") &&
!util::EqualICase(args[2], "clear")) {
+ return {Status::RedisParseErr, "Invalid slotsize command, eg: slotsize
{SlotRange} {scan|clear}"};
+ }
+ return Status::OK();
+ }
+
+ Status Execute([[maybe_unused]] engine::Context &ctx, Server *srv,
[[maybe_unused]] Connection *conn,
+ std::string *output) override {
+ if (!srv->storage->IsSlotIdEncoded()) {
Review Comment:
```suggestion
if (!srv->GetConfig()->cluster_enabled) {
```
##########
src/commands/cmd_server.cc:
##########
@@ -309,6 +309,58 @@ class CommandDBSize : public Commander {
}
};
+class CommandSlotSize : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ if (args.size() < 2 || args.size() > 3) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
+ if (args.size() == 3 && !util::EqualICase(args[2], "scan") &&
!util::EqualICase(args[2], "clear")) {
+ return {Status::RedisParseErr, "Invalid slotsize command, eg: slotsize
{SlotRange} {scan|clear}"};
+ }
+ return Status::OK();
+ }
+
+ Status Execute([[maybe_unused]] engine::Context &ctx, Server *srv,
[[maybe_unused]] Connection *conn,
+ std::string *output) override {
+ if (!srv->storage->IsSlotIdEncoded()) {
+ return {Status::RedisExecErr, "It is not in cluster mode"};
Review Comment:
```suggestion
return {Status::RedisExecErr, "the command is only allowed in cluster
mode"};
```
##########
src/commands/cmd_server.cc:
##########
@@ -309,6 +309,58 @@ class CommandDBSize : public Commander {
}
};
+class CommandSlotSize : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ if (args.size() < 2 || args.size() > 3) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
+ if (args.size() == 3 && !util::EqualICase(args[2], "scan") &&
!util::EqualICase(args[2], "clear")) {
+ return {Status::RedisParseErr, "Invalid slotsize command, eg: slotsize
{SlotRange} {scan|clear}"};
+ }
+ return Status::OK();
+ }
+
+ Status Execute([[maybe_unused]] engine::Context &ctx, Server *srv,
[[maybe_unused]] Connection *conn,
+ std::string *output) override {
+ if (!srv->storage->IsSlotIdEncoded()) {
+ return {Status::RedisExecErr, "It is not in cluster mode"};
+ }
+
+ std::vector<SlotRange> slot_ranges;
+ Status s = CommandTable::ParseSlotRanges(args_[1], slot_ranges);
+ if (!s.IsOK()) {
+ return s;
+ }
+
+ if (args_.size() == 2) {
+ std::vector<std::string> stats;
+ s = srv->GetSlotStats(slot_ranges, &stats);
+ if (!s.IsOK()) {
+ return s;
+ }
+ *output = redis::ArrayOfBulkStrings(stats);
+ } else if (args_.size() == 3 && util::EqualICase(args_[2], "scan")) {
+ s = srv->AsyncScanSlots(slot_ranges);
+ if (s.IsOK()) {
+ *output = redis::RESP_OK;
+ } else {
+ return s;
+ }
+ } else if (args_.size() == 3 && util::EqualICase(args_[2], "clear")) {
+ s = srv->ClearSlots(slot_ranges);
+ if (s.IsOK()) {
+ *output = redis::RESP_OK;
+ } else {
+ return s;
+ }
Review Comment:
```suggestion
if (args_.size() == 2) {
std::vector<std::string> stats;
s = srv->GetSlotStats(slot_ranges, &stats);
if (!s.IsOK()) return s;
*output = redis::ArrayOfBulkStrings(stats);
} else {
auto scan = util::EqualICase(args_[2], "scan");
s = scan ? srv->AsyncScanSlots(slot_ranges) :
srv->ClearSlots(slot_ranges);
if (!s.IsOK()) return s;
*output = redis::RESP_OK;
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]