diff --git a/src/redis_request.cc b/src/redis_request.cc index 7d896d2be97..64de2f1b312 100644 --- a/src/redis_request.cc +++ b/src/redis_request.cc @@ -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(); diff --git a/src/server.cc b/src/server.cc index 2d8eb217c34..fbcde791ffa 100644 --- a/src/server.cc +++ b/src/server.cc @@ -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 *Server::GetClientID() {