check the slave status when find recursive find the master, so support if the dba using reset slave instead of reset slave all.

This commit is contained in:
rj03hou 2016-12-05 19:42:16 +08:00
parent 56bee78108
commit 8f02ab0fed
2 changed files with 19 additions and 0 deletions

View File

@ -692,6 +692,7 @@ func (this *Inspector) readChangelogState() (map[string]string, error) {
} }
func (this *Inspector) getMasterConnectionConfig() (applierConfig *mysql.ConnectionConfig, err error) { func (this *Inspector) getMasterConnectionConfig() (applierConfig *mysql.ConnectionConfig, err error) {
log.Infof("Start find master, recursive to execute show slave status from the host to find the master.")
visitedKeys := mysql.NewInstanceKeyMap() visitedKeys := mysql.NewInstanceKeyMap()
return mysql.GetMasterConnectionConfigSafe(this.connectionConfig, visitedKeys, this.migrationContext.AllowedMasterMaster) return mysql.GetMasterConnectionConfigSafe(this.connectionConfig, visitedKeys, this.migrationContext.AllowedMasterMaster)
} }

View File

@ -83,12 +83,30 @@ func GetMasterKeyFromSlaveStatus(connectionConfig *ConnectionConfig) (masterKey
return nil, err return nil, err
} }
err = sqlutils.QueryRowsMap(db, `show slave status`, func(rowMap sqlutils.RowMap) error { err = sqlutils.QueryRowsMap(db, `show slave status`, func(rowMap sqlutils.RowMap) error {
// Using reset slave not reset slave all, the Master_Log_File is empty.
if rowMap.GetString("Master_Log_File") == "" {
return nil
}
slaveIORunning := rowMap.GetString("Slave_IO_Running")
slaveSQLRunning := rowMap.GetString("Slave_SQL_Running")
// If not using reset slave or reset slave all and slave is break, something is wrong, so we stop.
if slaveIORunning != "Yes" || slaveSQLRunning != "Yes" {
return fmt.Errorf("The slave %s is break: Slave_IO_Running:%s Slave_SQL_Running:%s please make sure the replication is correct.",
connectionConfig.Key.Hostname,
slaveIORunning,
slaveSQLRunning,
)
}
masterKey = &InstanceKey{ masterKey = &InstanceKey{
Hostname: rowMap.GetString("Master_Host"), Hostname: rowMap.GetString("Master_Host"),
Port: rowMap.GetInt("Master_Port"), Port: rowMap.GetInt("Master_Port"),
} }
return nil return nil
}) })
return masterKey, err return masterKey, err
} }