git-hulk commented on code in PR #2210:
URL: https://github.com/apache/kvrocks/pull/2210#discussion_r1545671585
##########
src/cluster/cluster.cc:
##########
@@ -828,3 +828,31 @@ Status Cluster::CanExecByMySelf(const
redis::CommandAttributes *attributes, cons
return {Status::RedisExecErr,
fmt::format("MOVED {} {}:{}", slot, slots_nodes_[slot]->host,
slots_nodes_[slot]->port)};
}
+
+Status Cluster::Reset() {
+ if (srv_->slot_migrator && srv_->slot_migrator->GetMigratingSlot() != -1) {
+ return {Status::NotOK, "Can't reset cluster while migrating slot"};
+ }
+ if (srv_->slot_import && srv_->slot_import->GetSlot() != -1) {
+ return {Status::NotOK, "Can't reset cluster while importing slot"};
+ }
+ if (!srv_->storage->IsEmptyDB()) {
+ return {Status::NotOK, "Can't reset cluster while database is not empty"};
+ }
+
+ version_ = -1;
+ size_ = 0;
+ myid_.clear();
+ myself_.reset();
+
+ nodes_.clear();
+ for (auto &n : slots_nodes_) {
+ n = nullptr;
+ }
Review Comment:
slot_nodes_ is an array and the number of slot is a fixed number, so I think
it should be fine to clear them with the null pointer.
--
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]