Skip to content

Commit

Permalink
Make StopReplication wait for replication to be stopped externally
Browse files Browse the repository at this point in the history
This will wait indefinitely for the replication status to change.
This allows us to run `--test-on-replica` in RDS without making
extensive modifications.
  • Loading branch information
pbitty committed Aug 15, 2016
1 parent a9f638e commit 222fca4
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions go/logic/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,14 +566,32 @@ 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
for {
log.Info("Waiting for replication to stop...")
if this.isReplicationStopped() {
log.Info("Replication stopped.")
break
}
time.Sleep(5 * time.Second)

This comment has been minimized.

Copy link
@shlomi-noach

shlomi-noach Aug 18, 2016

See discussion on github#162 re: whether to go this way or the hooks way.

Regardless, if you wish to introduce change of behavior, such as in the above, please always make sure to be backwards compatible. This can be supported by some --test-on-replica-manual-stop-replication flag, which would default to false.

}

readBinlogCoordinates, executeBinlogCoordinates, err := mysql.GetReplicationBinlogCoordinates(this.db)
if err != nil {
return err
Expand Down

0 comments on commit 222fca4

Please sign in to comment.