diff --git a/go/mysql/flavor.go b/go/mysql/flavor.go index 001ef89df7b..4be34fd54da 100644 --- a/go/mysql/flavor.go +++ b/go/mysql/flavor.go @@ -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. @@ -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 diff --git a/go/mysql/flavor_filepos.go b/go/mysql/flavor_filepos.go index 30703fff275..fe1f0e54a83 100644 --- a/go/mysql/flavor_filepos.go +++ b/go/mysql/flavor_filepos.go @@ -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", } diff --git a/go/mysql/flavor_mariadb.go b/go/mysql/flavor_mariadb.go index 98174aa9b48..397c0e63d2b 100644 --- a/go/mysql/flavor_mariadb.go +++ b/go/mysql/flavor_mariadb.go @@ -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. diff --git a/go/mysql/flavor_mysql.go b/go/mysql/flavor_mysql.go index 6ef3a34eb38..44127ed629c 100644 --- a/go/mysql/flavor_mysql.go +++ b/go/mysql/flavor_mysql.go @@ -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. diff --git a/go/mysql/replication.go b/go/mysql/replication.go index e45b31d96e5..dcc4c5e20c2 100644 --- a/go/mysql/replication.go +++ b/go/mysql/replication.go @@ -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 +}