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(cluster): should stop the migration if it's changed to the slave role #2716

Merged
merged 4 commits into from
Jan 9, 2025

Conversation

RiversJin
Copy link
Contributor

In cluster mode, if a master-slave failover occurs, it seems that slot migration is not properly stopped. However, the slave of command has corresponding update logic. So, this is a bug, right?

@git-hulk
Copy link
Member

git-hulk commented Jan 8, 2025

@RiversJin Thanks for raising this issue. You're right that we should stop the migration while becoming to the slave role.

@git-hulk git-hulk added the bug type bug label Jan 8, 2025
@git-hulk git-hulk changed the title fix: update migration stop flag in cluster mode fix(cluster): should stop the migration if it's changed to the slave role Jan 8, 2025
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (is_slave && is_cluster_enabled) {
if (is_slave && is_cluster_enabled && srv_->slot_migrator) {

Copy link
Member

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.

if (is_slave && is_cluster_enabled) {
// Slave -> Master
srv_->slot_migrator->SetStopMigrationFlag(false);
LOG(INFO) << "Change server role to master, stop migration task";
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops... fixed

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!is_slave && is_cluster_enabled) {
if (!is_slave && is_cluster_enabled && srv_->slot_migrator) {

Copy link

sonarqubecloud bot commented Jan 8, 2025

@PragmaTwice PragmaTwice merged commit a21df19 into apache:unstable Jan 9, 2025
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug type bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants