Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go/mysql/flavor.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type flavor interface {

// resetReplicationCommands returns the commands to completely reset
// replication on the host.
resetReplicationCommands() []string
resetReplicationCommands(c *Conn) []string

// setSlavePositionCommands returns the commands to set the
// replication position at which the slave will resume.
Expand Down Expand Up @@ -191,7 +191,7 @@ func (c *Conn) ReadBinlogEvent() (BinlogEvent, error) {
// ResetReplicationCommands returns the commands to completely reset
// replication on the host.
func (c *Conn) ResetReplicationCommands() []string {
return c.flavor.resetReplicationCommands()
return c.flavor.resetReplicationCommands(c)
}

// SetSlavePositionCommands returns the commands to set the
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/flavor_filepos.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (flv *filePosFlavor) readBinlogEvent(c *Conn) (BinlogEvent, error) {
}

// resetReplicationCommands is part of the Flavor interface.
func (flv *filePosFlavor) resetReplicationCommands() []string {
func (flv *filePosFlavor) resetReplicationCommands(c *Conn) []string {
return []string{
"unsupported",
}
Expand Down
9 changes: 6 additions & 3 deletions go/mysql/flavor_mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ func (mariadbFlavor) sendBinlogDumpCommand(c *Conn, slaveID uint32, startPos Pos
}

// resetReplicationCommands is part of the Flavor interface.
func (mariadbFlavor) resetReplicationCommands() []string {
return []string{
func (mariadbFlavor) resetReplicationCommands(c *Conn) []string {
resetCommands := []string{
"STOP SLAVE",
"RESET SLAVE ALL", // "ALL" makes it forget master host:port.
"RESET MASTER",
"SET GLOBAL gtid_slave_pos = ''",
"SET GLOBAL rpl_semi_sync_master_enabled = false, GLOBAL rpl_semi_sync_slave_enabled = false", // semi-sync will be enabled if needed when slave is started.
}
if c.SemiSyncExtensionLoaded() {
resetCommands = append(resetCommands, "SET GLOBAL rpl_semi_sync_master_enabled = false, GLOBAL rpl_semi_sync_slave_enabled = false") // semi-sync will be enabled if needed when slave is started.
}
return resetCommands
}

// setSlavePositionCommands is part of the Flavor interface.
Expand Down
9 changes: 6 additions & 3 deletions go/mysql/flavor_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ func (mysqlFlavor) sendBinlogDumpCommand(c *Conn, slaveID uint32, startPos Posit
}

// resetReplicationCommands is part of the Flavor interface.
func (mysqlFlavor) resetReplicationCommands() []string {
return []string{
func (mysqlFlavor) resetReplicationCommands(c *Conn) []string {
resetCommands := []string{
"STOP SLAVE",
"RESET SLAVE ALL", // "ALL" makes it forget master host:port.
"RESET MASTER", // This will also clear gtid_executed and gtid_purged.
"SET GLOBAL rpl_semi_sync_master_enabled = false, GLOBAL rpl_semi_sync_slave_enabled = false", // semi-sync will be enabled if needed when slave is started.
}
if c.SemiSyncExtensionLoaded() {
resetCommands = append(resetCommands, "SET GLOBAL rpl_semi_sync_master_enabled = false, GLOBAL rpl_semi_sync_slave_enabled = false") // semi-sync will be enabled if needed when slave is started.
}
return resetCommands
}

// setSlavePositionCommands is part of the Flavor interface.
Expand Down
10 changes: 10 additions & 0 deletions go/mysql/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,13 @@ func (c *Conn) WriteComBinlogDumpGTID(serverID uint32, binlogFilename string, bi
}
return nil
}

// SemiSyncExtensionLoaded checks if the semisync extension has been loaded.
// It should work for both MariaDB and MySQL.
func (c *Conn) SemiSyncExtensionLoaded() bool {
qr, err := c.ExecuteFetch("SHOW GLOBAL VARIABLES LIKE 'rpl_semi_sync%'", 10, false)
if err != nil {
return false
}
return len(qr.Rows) >= 1
}