-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add --test-on-replica-manual-replication-control flag #174
Changes from 1 commit
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 |
---|---|---|
|
@@ -566,14 +566,41 @@ func (this *Applier) StartSlaveSQLThread() error { | |
return nil | ||
} | ||
|
||
func (this *Applier) isReplicationStopped() bool { | ||
query := `show slave status` | ||
replicationStopped := false | ||
|
||
err := sqlutils.QueryRowsMap(this.db, query, func(rowMap sqlutils.RowMap) error { | ||
replicationStopped = rowMap["Slave_IO_Running"].String == "No" && rowMap["Slave_SQL_Running"].String == "No" | ||
return nil | ||
}) | ||
|
||
if err != nil { | ||
return false | ||
} | ||
return replicationStopped | ||
} | ||
|
||
// StopReplication is used by `--test-on-replica` and stops replication. | ||
func (this *Applier) StopReplication() error { | ||
if err := this.StopSlaveIOThread(); err != nil { | ||
return err | ||
} | ||
if err := this.StopSlaveSQLThread(); err != nil { | ||
return err | ||
if this.migrationContext.ManualReplicationControl { | ||
for { | ||
log.Info("Waiting for replication to stop...") | ||
if this.isReplicationStopped() { | ||
log.Info("Replication stopped.") | ||
break | ||
} | ||
time.Sleep(5 * time.Second) | ||
} | ||
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. We discussed the use of plugins. In such case the plugin would be called synchronously and would stop replication. I would suggest the PR could be made much smaller: merely introducing the flag; and if it is set, we skip the Later on I will add the plugin injection. WDYT? 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. I like that approach, it keeps things clean and simple in the tool. I would probably block this PR until #62 is done, since simply skipping replication without the ability to stop it externally, would break the behavior of I think we should also log a Warning or Info line explaining the above - eg. "You must use a plugin to stop replication." The wording would depend on how #62 turns out. Thoughts? 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. As for the RDS calls to start/stop replication, they are indeed synchronous. If there's ever a case of an async operation, the plugin could block while it waits for the desired state. |
||
} else { | ||
if err := this.StopSlaveIOThread(); err != nil { | ||
return err | ||
} | ||
if err := this.StopSlaveSQLThread(); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
readBinlogCoordinates, executeBinlogCoordinates, err := mysql.GetReplicationBinlogCoordinates(this.db) | ||
if err != nil { | ||
return err | ||
|
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.
@shlomi-noach , in my opinion the code reads more complicated to me when there are two flags that have the same core functionality, with this one slight variation.
I think the semantics would be more clear if we still used the
--test-on-replica
flag and had a separate flag that just customized this one aspect of its behavior. So if one wants to have manual replication control, one would use the args:Without the extra flag,
--test-on-replica
would behave as it always has.What do you think?
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.
That was my original intention. The flag is good to be named
--test-on-replica-skip-stop-replica
or whatever, but it would be an addon to--test-on-replica
. Not only are the flags not mutually exclusive, the--test-on-replica-skip-stop-replica
is only applicable when--test-on-replica
exists.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.
Ah, I understand now. My apologies for the confusion. I'll update the logic.