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


##########
src/server/redis_connection.cc:
##########
@@ -74,6 +75,17 @@ void Connection::Close() {
 
 void Connection::Detach() { owner_->DetachConnection(this); }
 
+bool Connection::IsBlockingMode() const {
+  if (current_cmd == nullptr) return false;
+  if (dynamic_cast<BlockingCommander *>(current_cmd.get()) != nullptr) return 
true;
+
+  auto args = current_cmd->GetArgs();
+  if (args.empty()) return false;
+
+  std::string cmd_name = util::ToLower(args.front());
+  return cmd_name == "xread";

Review Comment:
   Seems it can cause data race since args are used in multiple threads. And 
the check `cmd_name == "xread"` is really a disaster of maintainability (we can 
easily forget while facing new blocking commands).
   
   So I think a better solution is add an new attribute like `blocking` to 
these commands and check it here.



##########
src/server/redis_connection.cc:
##########
@@ -74,6 +75,17 @@ void Connection::Close() {
 
 void Connection::Detach() { owner_->DetachConnection(this); }
 
+bool Connection::IsBlockingMode() const {
+  if (current_cmd == nullptr) return false;
+  if (dynamic_cast<BlockingCommander *>(current_cmd.get()) != nullptr) return 
true;
+
+  auto args = current_cmd->GetArgs();
+  if (args.empty()) return false;
+
+  std::string cmd_name = util::ToLower(args.front());
+  return cmd_name == "xread";

Review Comment:
   Seems it can cause data race since `args` are used in multiple threads. And 
the check `cmd_name == "xread"` is really a disaster of maintainability (we can 
easily forget while facing new blocking commands).
   
   So I think a better solution is add an new attribute like `blocking` to 
these commands and check it here.



-- 
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