Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XREAD returns dedicated status if it blocks #1232

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/commands/redis_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6079,7 +6079,7 @@ class CommandXRead : public Commander {
evtimer_add(timer_, &tm);
}

return Status::OK();
return {Status::BlockingCmd};
}

static void WriteCB(bufferevent *bev, void *ctx) {
Expand Down
22 changes: 12 additions & 10 deletions src/server/redis_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ void Connection::ExecuteCommands(std::deque<CommandTokens> *to_process_cmds) {
Reply(Redis::Error("NOAUTH Authentication required."));
continue;
}

if (password.empty()) {
BecomeAdmin();
SetNamespace(kDefaultNamespace);
Expand All @@ -319,11 +320,10 @@ void Connection::ExecuteCommands(std::deque<CommandTokens> *to_process_cmds) {

std::unique_ptr<RWLock::ReadLock> concurrency; // Allow concurrency
std::unique_ptr<RWLock::WriteLock> exclusivity; // Need exclusivity
// If the command need to process exclusively, we need to get 'ExclusivityGuard'
// If the command needs to process exclusively, we need to get 'ExclusivityGuard'
// that can guarantee other threads can't come into critical zone, such as DEBUG,
// CLUSTER subcommand, CONFIG SET, MULTI, LUA (in the immediate future).
// Otherwise, we just use 'ConcurrencyGuard' to allow all workers to execute
// commands at the same time.
// Otherwise, we just use 'ConcurrencyGuard' to allow all workers to execute commands at the same time.
if (IsFlagEnabled(Connection::kMultiExec) && attributes->name != "exec") {
// No lock guard, because 'exec' command has acquired 'WorkExclusivityGuard'
} else if (attributes->is_exclusive() ||
Expand All @@ -332,33 +332,32 @@ void Connection::ExecuteCommands(std::deque<CommandTokens> *to_process_cmds) {
cmd_tokens.size() >= 2 && Cluster::SubCommandIsExecExclusive(cmd_tokens[1]))) {
exclusivity = svr_->WorkExclusivityGuard();

// When executing lua script commands that have "exclusive" attribute,
// we need to know current connection, but we should set current
// connection after acquiring the WorkExclusivityGuard to make it
// thread-safe
// When executing lua script commands that have "exclusive" attribute, we need to know current connection,
// but we should set current connection after acquiring the WorkExclusivityGuard to make it thread-safe
svr_->SetCurrentConnection(this);
} else {
concurrency = svr_->WorkConcurrencyGuard();
}

if (cmd_name == "eval_ro" || cmd_name == "evalsha_ro") {
// if executing read only lua script commands, set current
// connection.
// if executing read only lua script commands, set current connection.
svr_->SetCurrentConnection(this);
}

if (svr_->IsLoading() && attributes->is_ok_loading() == false) {
if (svr_->IsLoading() && !attributes->is_ok_loading()) {
Reply(Redis::Error("LOADING kvrocks is restoring the db from backup"));
if (IsFlagEnabled(Connection::kMultiExec)) multi_error_ = true;
continue;
}

int arity = attributes->arity;
int tokens = static_cast<int>(cmd_tokens.size());
if ((arity > 0 && tokens != arity) || (arity < 0 && tokens < -arity)) {
if (IsFlagEnabled(Connection::kMultiExec)) multi_error_ = true;
Reply(Redis::Error("ERR wrong number of arguments"));
continue;
}

current_cmd_->SetArgs(cmd_tokens);
s = current_cmd_->Parse();
if (!s.IsOK()) {
Expand Down Expand Up @@ -394,6 +393,7 @@ void Connection::ExecuteCommands(std::deque<CommandTokens> *to_process_cmds) {
Reply(Redis::Error("READONLY You can't write against a read only slave."));
continue;
}

if (!config->slave_serve_stale_data && svr_->IsSlave() && cmd_name != "info" && cmd_name != "slaveof" &&
svr_->GetReplicationState() != kReplConnected) {
Reply(
Expand All @@ -419,11 +419,13 @@ void Connection::ExecuteCommands(std::deque<CommandTokens> *to_process_cmds) {
if (s.Is<Status::BlockingCmd>()) {
break;
}

// Reply for MULTI
if (!s.IsOK()) {
Reply(Redis::Error("ERR " + s.Msg()));
continue;
}

if (!reply.empty()) Reply(reply);
reply.clear();
}
Expand Down