-
Notifications
You must be signed in to change notification settings - Fork 491
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(cluster): should stop the migration if it's changed to the slave role #2716
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -237,23 +237,40 @@ Status Cluster::SetMasterSlaveRepl() { | |||||
return Status::OK(); | ||||||
} | ||||||
|
||||||
bool is_slave = srv_->IsSlave(); | ||||||
bool is_cluster_enabled = srv_->GetConfig()->cluster_enabled; | ||||||
|
||||||
if (myself_->role == kClusterMaster) { | ||||||
// Master mode | ||||||
auto s = srv_->RemoveMaster(); | ||||||
if (!s.IsOK()) { | ||||||
return s.Prefixed("failed to remove master"); | ||||||
} | ||||||
LOG(INFO) << "MASTER MODE enabled by cluster topology setting"; | ||||||
} else if (nodes_.find(myself_->master_id) != nodes_.end()) { | ||||||
if (is_slave && is_cluster_enabled) { | ||||||
// Slave -> Master | ||||||
srv_->slot_migrator->SetStopMigrationFlag(false); | ||||||
LOG(INFO) << "Change server role to master, stop migration task"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong log message, it should restart the migration task instead of the stop. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops... fixed |
||||||
} | ||||||
return Status::OK(); | ||||||
} | ||||||
|
||||||
auto it = nodes_.find(myself_->master_id); | ||||||
if (it != nodes_.end()) { | ||||||
// Replica mode and master node is existing | ||||||
std::shared_ptr<ClusterNode> master = nodes_[myself_->master_id]; | ||||||
std::shared_ptr<ClusterNode> master = it->second; | ||||||
auto s = srv_->AddMaster(master->host, master->port, false); | ||||||
if (!s.IsOK()) { | ||||||
LOG(WARNING) << "SLAVE OF " << master->host << ":" << master->port | ||||||
<< " wasn't enabled by cluster topology setting, encounter error: " << s.Msg(); | ||||||
return s.Prefixed("failed to add master"); | ||||||
} | ||||||
LOG(INFO) << "SLAVE OF " << master->host << ":" << master->port << " enabled by cluster topology setting"; | ||||||
if (!is_slave && is_cluster_enabled) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// Master -> Slave | ||||||
srv_->slot_migrator->SetStopMigrationFlag(true); | ||||||
LOG(INFO) << "Change server role to slave, stop migration task"; | ||||||
} | ||||||
LOG(INFO) << fmt::format("SLAVE OF {}:{} enabled by cluster topology setting", master->host, master->port); | ||||||
} | ||||||
|
||||||
return Status::OK(); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The slot_migrator might be null pointer while starting the server.