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

Fix condition race for ReclaimOldDBPtr #246

Merged
merged 1 commit into from
May 7, 2021
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
8 changes: 8 additions & 0 deletions src/redis_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ void Request::ExecuteCommands(Connection *conn) {
auto start = std::chrono::high_resolution_clock::now();
bool is_profiling = isProfilingEnabled(cmd_name);
svr_->IncrExecutingCommandNum();
// Need to check again, because we set loading firstly and then check
// excuting_command_num_, there may be some commands when loading is 1
// and excuting_command_num_ is 0, these commands may access storage DB.
if (svr_->IsLoading() && !inCommandWhitelist(conn->current_cmd_->Name())) {
svr_->DecrExecutingCommandNum();
conn->Reply(Redis::Error("ERR restoring the db from backup"));
break;
}
s = conn->current_cmd_->Execute(svr_, conn, &reply);
svr_->DecrExecutingCommandNum();
auto end = std::chrono::high_resolution_clock::now();
Expand Down
4 changes: 2 additions & 2 deletions src/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,11 @@ int Server::DecrMonitorClientNum() {
}

int Server::IncrExecutingCommandNum() {
return excuting_command_num_.fetch_add(1, std::memory_order_relaxed);
return excuting_command_num_.fetch_add(1, std::memory_order_seq_cst);
}

int Server::DecrExecutingCommandNum() {
return excuting_command_num_.fetch_sub(1, std::memory_order_relaxed);
return excuting_command_num_.fetch_sub(1, std::memory_order_seq_cst);
}

std::atomic<uint64_t> *Server::GetClientID() {
Expand Down