PragmaTwice commented on code in PR #3047:
URL: https://github.com/apache/kvrocks/pull/3047#discussion_r2203761939


##########
src/commands/cmd_replication.cc:
##########
@@ -344,10 +344,54 @@ class CommandDBName : public Commander {
   }
 };
 
+class CommandWait : public Commander {
+ public:
+  Status Parse(const std::vector<std::string> &args) override {
+    auto num_replicas_result = ParseInt<uint64_t>(args[1], 10);
+    if (!num_replicas_result) {
+      return {Status::RedisParseErr, "numreplicas should be a positive 
integer"};
+    }
+
+    num_replicas_ = *num_replicas_result;
+
+    return Commander::Parse(args);
+  }
+
+  Status Execute([[maybe_unused]] engine::Context &ctx, Server *srv, 
Connection *conn, std::string *output) override {
+    // Only master can execute WAIT command
+    if (srv->IsSlave()) {
+      return {Status::RedisExecErr, "WAIT command can only be executed on 
master"};
+    }
+
+    // Get current sequence number
+    auto current_seq = srv->storage->LatestSeqNumber();
+
+    // Check if we already have enough replicas at the current sequence
+    int reached_replicas = srv->GetReplicasReachedSequence(current_seq);
+
+    // If we already have enough replicas, return immediately
+    if (reached_replicas >= static_cast<int>(num_replicas_)) {
+      *output = redis::Integer(reached_replicas);
+      return Status::OK();
+    }

Review Comment:
   ```suggestion
       size_t reached_replicas = srv->GetReplicasReachedSequence(current_seq);
   
       // If we already have enough replicas, return immediately
       if (reached_replicas >= num_replicas_) {
         *output = redis::Integer(reached_replicas);
         return Status::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]

Reply via email to