git-hulk commented on code in PR #2954:
URL: https://github.com/apache/kvrocks/pull/2954#discussion_r2149038147
##########
src/commands/cmd_cluster.cc:
##########
@@ -237,7 +237,35 @@ class CommandClusterX : public Commander {
return Status::OK();
}
- return {Status::RedisParseErr, "CLUSTERX command, CLUSTERX
VERSION|MYID|SETNODEID|SETNODES|SETSLOT|MIGRATE"};
+ // CLUSTERX CLEARSLOT $SLOT_ID
+ if (subcommand_ == "clearslot") {
+ if (args_.size() != 3) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
+ Status s = CommandTable::ParseSlotRanges(args_[2], slot_ranges_);
+ if (!s.IsOK()) {
+ return s;
+ }
+ return Status::OK();
Review Comment:
```suggestion
return CommandTable::ParseSlotRanges(args_[2], slot_ranges_);
```
##########
src/server/server.cc:
##########
@@ -2126,3 +2127,110 @@ AuthResult Server::AuthenticateUser(const std::string
&user_password, std::strin
*ns = kDefaultNamespace;
return AuthResult::IS_ADMIN;
}
+
+std::string Server::GetSlotStats(const std::vector<SlotRange> &slot_ranges) {
Review Comment:
Can also return the `last_scan_time_secs` as well? so that we can identify
if the scan operation is in progress.
##########
src/server/server.cc:
##########
@@ -2126,3 +2127,110 @@ AuthResult Server::AuthenticateUser(const std::string
&user_password, std::strin
*ns = kDefaultNamespace;
return AuthResult::IS_ADMIN;
}
+
+std::string Server::GetSlotStats(const std::vector<SlotRange> &slot_ranges) {
+ size_t slot_count = 0;
+ std::string output;
+
+ std::lock_guard<std::mutex> lg(db_job_mu_);
+ std::bitset<HASH_SLOTS_SIZE> checked_slots;
+ std::string slotstats;
+ for (auto slot_range : slot_ranges) {
+ for (int slot = slot_range.start; slot <= slot_range.end; ++slot) {
+ if (checked_slots.test(slot)) {
+ continue;
+ } else {
+ checked_slots.set(slot);
+ }
+
+ ++slot_count;
+ slotstats.append(redis::MultiLen(6));
+ slotstats.append(redis::SimpleString("slot"));
+ slotstats.append(redis::Integer(slot));
+ if (slot_scan_infos_.slot_stats.find(slot) ==
slot_scan_infos_.slot_stats.end()) {
+ slotstats.append(redis::SimpleString("key_num"));
+ slotstats.append(redis::Integer(0));
+ slotstats.append(redis::SimpleString("unexpected_key_num"));
+ slotstats.append(redis::Integer(0));
+ } else {
+ SlotStats ss = slot_scan_infos_.slot_stats[slot];
+ slotstats.append(redis::SimpleString("key_num"));
+ slotstats.append(redis::Integer(ss.n_key));
+ slotstats.append(redis::SimpleString("unexpected_key_num"));
+ slotstats.append(redis::Integer(ss.n_unexpected_key));
+ }
Review Comment:
```suggestion
uint64_t key_num = 0, unexpected_key_num = 0;
if (slot_scan_infos_.slot_stats.find(slot) !=
slot_scan_infos_.slot_stats.end()) {
SlotStats ss = slot_scan_infos_.slot_stats[slot];
key_num = ss.n_key;
unexpected_key_num = ss.n_unexpected_key;
}
slotstats.append(redis::MultiLen(6));
slotstats.append(redis::SimpleString("slot"));
slotstats.append(redis::Integer(slot));
slotstats.append(redis::SimpleString("key_num"));
slotstats.append(redis::Integer(key_num));
slotstats.append(redis::SimpleString("unexpected_key_num"));
slotstats.append(redis::Integer(unexpected_key_num));
```
##########
src/commands/cmd_cluster.cc:
##########
@@ -289,8 +317,26 @@ class CommandClusterX : public Commander {
} else {
return s;
}
+ } else if (subcommand_ == "clearslot") {
+ Status s = srv->cluster->ClearSlotRanges(slot_ranges_);
+ if (s.IsOK()) {
+ *output = redis::RESP_OK;
+ } else {
+ return s;
+ }
+ } else if (subcommand_ == "slotsize") {
+ if (args_.size() == 3) {
+ *output = srv->GetSlotStats(slot_ranges_);
+ } else {
+ Status s = srv->AsyncScanSlots(slot_ranges_);
+ if (s.IsOK()) {
+ *output = redis::RESP_OK;
+ } else {
+ return s;
+ }
Review Comment:
```suggestion
if (!s.IsOK()) return s;
*output = redis::RESP_OK;
```
##########
src/commands/cmd_cluster.cc:
##########
@@ -289,8 +317,26 @@ class CommandClusterX : public Commander {
} else {
return s;
}
+ } else if (subcommand_ == "clearslot") {
+ Status s = srv->cluster->ClearSlotRanges(slot_ranges_);
+ if (s.IsOK()) {
+ *output = redis::RESP_OK;
+ } else {
+ return s;
+ }
Review Comment:
```suggestion
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]