From 9d9dff26d53579c7816c7b8050cf2272c1ed0ccf Mon Sep 17 00:00:00 2001 From: hulk Date: Mon, 29 Apr 2024 13:25:40 +0800 Subject: [PATCH] Fix the error logging when the importer is not in a started state (#2280) --- src/cluster/cluster.cc | 10 +++++----- src/cluster/slot_import.cc | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cluster/cluster.cc b/src/cluster/cluster.cc index 74aec5d0b8a..8bdf9095b0e 100644 --- a/src/cluster/cluster.cc +++ b/src/cluster/cluster.cc @@ -333,24 +333,24 @@ Status Cluster::ImportSlot(redis::Connection *conn, int slot, int state) { conn->SetImporting(); myself_->importing_slot = slot; // Set link error callback - conn->close_cb = [object_ptr = srv_->slot_import.get()](int fd) { + conn->close_cb = [object_ptr = srv_->slot_import.get(), slot](int fd) { auto s = object_ptr->StopForLinkError(); if (!s.IsOK()) { - LOG(ERROR) << "[import] Failed to stop importing slot: " << s.Msg(); + LOG(ERROR) << fmt::format("[import] Failed to stop importing slot {}: {}", slot, s.Msg()); } }; // Stop forbidding writing slot to accept write commands if (slot == srv_->slot_migrator->GetForbiddenSlot()) srv_->slot_migrator->ReleaseForbiddenSlot(); - LOG(INFO) << "[import] Start importing slot " << slot; + LOG(INFO) << fmt::format("[import] Start importing slot {}", slot); break; case kImportSuccess: s = srv_->slot_import->Success(slot); if (!s.IsOK()) return s; - LOG(INFO) << "[import] Mark the importing slot as succeed" << slot; + LOG(INFO) << fmt::format("[import] Mark the importing slot {} as succeed", slot); break; case kImportFailed: s = srv_->slot_import->Fail(slot); if (!s.IsOK()) return s; - LOG(INFO) << "[import] Mark the importing slot as failed" << slot; + LOG(INFO) << fmt::format("[import] Mark the importing slot {} as failed", slot); break; default: return {Status::NotOK, errInvalidImportState}; diff --git a/src/cluster/slot_import.cc b/src/cluster/slot_import.cc index dcc97d66351..4306e336757 100644 --- a/src/cluster/slot_import.cc +++ b/src/cluster/slot_import.cc @@ -82,7 +82,8 @@ Status SlotImport::Fail(int slot) { Status SlotImport::StopForLinkError() { std::lock_guard guard(mutex_); - if (import_status_ != kImportStart) return {Status::NotOK, "no slot is importing"}; + // We don't need to do anything if the importer is not started yet. + if (import_status_ != kImportStart) return Status::OK(); // Maybe server has failovered // Situation: