Skip to content

Commit

Permalink
Fix the error logging when the importer is not in a started state (#2280
Browse files Browse the repository at this point in the history
)
  • Loading branch information
git-hulk committed Apr 29, 2024
1 parent 9bfb05e commit 9d9dff2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/cluster/cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
3 changes: 2 additions & 1 deletion src/cluster/slot_import.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ Status SlotImport::Fail(int slot) {

Status SlotImport::StopForLinkError() {
std::lock_guard<std::mutex> 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:
Expand Down

0 comments on commit 9d9dff2

Please sign in to comment.