@@ -61,13 +61,16 @@ func GetDB(migrationUuid string, mysql_uri string) (db *gosql.DB, exists bool, e
61
61
}
62
62
63
63
// GetReplicationLagFromSlaveStatus returns replication lag for a given db; via SHOW SLAVE STATUS
64
- func GetReplicationLagFromSlaveStatus (informationSchemaDb * gosql.DB ) (replicationLag time.Duration , err error ) {
65
- err = sqlutils .QueryRowsMap (informationSchemaDb , `show slave status` , func (m sqlutils.RowMap ) error {
66
- slaveIORunning := m .GetString ("Slave_IO_Running" )
67
- slaveSQLRunning := m .GetString ("Slave_SQL_Running" )
68
- secondsBehindMaster := m .GetNullInt64 ("Seconds_Behind_Master" )
64
+ func GetReplicationLagFromSlaveStatus (dbVersion string , informationSchemaDb * gosql.DB ) (replicationLag time.Duration , err error ) {
65
+ showReplicaStatusQuery := fmt .Sprintf ("show %s" , ReplicaTermFor (dbVersion , `slave status` ))
66
+ err = sqlutils .QueryRowsMap (informationSchemaDb , showReplicaStatusQuery , func (m sqlutils.RowMap ) error {
67
+ ioRunningTerm := ReplicaTermFor (dbVersion , "Slave_IO_Running" )
68
+ sqlRunningTerm := ReplicaTermFor (dbVersion , "Slave_SQL_Running" )
69
+ slaveIORunning := m .GetString (ioRunningTerm )
70
+ slaveSQLRunning := m .GetString (sqlRunningTerm )
71
+ secondsBehindMaster := m .GetNullInt64 (ReplicaTermFor (dbVersion , "Seconds_Behind_Master" ))
69
72
if ! secondsBehindMaster .Valid {
70
- return fmt .Errorf ("replication not running; Slave_IO_Running =%+v, Slave_SQL_Running =%+v" , slaveIORunning , slaveSQLRunning )
73
+ return fmt .Errorf ("replication not running; %s =%+v, %s =%+v" , ioRunningTerm , slaveIORunning , sqlRunningTerm , slaveSQLRunning )
71
74
}
72
75
replicationLag = time .Duration (secondsBehindMaster .Int64 ) * time .Second
73
76
return nil
@@ -76,7 +79,7 @@ func GetReplicationLagFromSlaveStatus(informationSchemaDb *gosql.DB) (replicatio
76
79
return replicationLag , err
77
80
}
78
81
79
- func GetMasterKeyFromSlaveStatus (connectionConfig * ConnectionConfig ) (masterKey * InstanceKey , err error ) {
82
+ func GetMasterKeyFromSlaveStatus (dbVersion string , connectionConfig * ConnectionConfig ) (masterKey * InstanceKey , err error ) {
80
83
currentUri := connectionConfig .GetDBUri ("information_schema" )
81
84
// This function is only called once, okay to not have a cached connection pool
82
85
db , err := gosql .Open ("mysql" , currentUri )
@@ -85,40 +88,45 @@ func GetMasterKeyFromSlaveStatus(connectionConfig *ConnectionConfig) (masterKey
85
88
}
86
89
defer db .Close ()
87
90
88
- err = sqlutils .QueryRowsMap (db , `show slave status` , func (rowMap sqlutils.RowMap ) error {
91
+ showReplicaStatusQuery := fmt .Sprintf ("show %s" , ReplicaTermFor (dbVersion , `slave status` ))
92
+ err = sqlutils .QueryRowsMap (db , showReplicaStatusQuery , func (rowMap sqlutils.RowMap ) error {
89
93
// We wish to recognize the case where the topology's master actually has replication configuration.
90
94
// This can happen when a DBA issues a `RESET SLAVE` instead of `RESET SLAVE ALL`.
91
95
92
96
// An empty log file indicates this is a master:
93
- if rowMap .GetString ("Master_Log_File" ) == "" {
97
+ if rowMap .GetString (ReplicaTermFor ( dbVersion , "Master_Log_File" ) ) == "" {
94
98
return nil
95
99
}
96
100
97
- slaveIORunning := rowMap .GetString ("Slave_IO_Running" )
98
- slaveSQLRunning := rowMap .GetString ("Slave_SQL_Running" )
101
+ ioRunningTerm := ReplicaTermFor (dbVersion , "Slave_IO_Running" )
102
+ sqlRunningTerm := ReplicaTermFor (dbVersion , "Slave_SQL_Running" )
103
+ slaveIORunning := rowMap .GetString (ioRunningTerm )
104
+ slaveSQLRunning := rowMap .GetString (sqlRunningTerm )
99
105
100
106
if slaveIORunning != "Yes" || slaveSQLRunning != "Yes" {
101
- return fmt .Errorf ("Replication on %+v is broken: Slave_IO_Running : %s, Slave_SQL_Running : %s. Please make sure replication runs before using gh-ost." ,
107
+ return fmt .Errorf ("Replication on %+v is broken: %s : %s, %s : %s. Please make sure replication runs before using gh-ost." ,
102
108
connectionConfig .Key ,
109
+ ioRunningTerm ,
103
110
slaveIORunning ,
111
+ sqlRunningTerm ,
104
112
slaveSQLRunning ,
105
113
)
106
114
}
107
115
108
116
masterKey = & InstanceKey {
109
- Hostname : rowMap .GetString ("Master_Host" ),
110
- Port : rowMap .GetInt ("Master_Port" ),
117
+ Hostname : rowMap .GetString (ReplicaTermFor ( dbVersion , "Master_Host" ) ),
118
+ Port : rowMap .GetInt (ReplicaTermFor ( dbVersion , "Master_Port" ) ),
111
119
}
112
120
return nil
113
121
})
114
122
115
123
return masterKey , err
116
124
}
117
125
118
- func GetMasterConnectionConfigSafe (connectionConfig * ConnectionConfig , visitedKeys * InstanceKeyMap , allowMasterMaster bool ) (masterConfig * ConnectionConfig , err error ) {
119
- log .Debugf ("Looking for master on %+v" , connectionConfig .Key )
126
+ func GetMasterConnectionConfigSafe (dbVersion string , connectionConfig * ConnectionConfig , visitedKeys * InstanceKeyMap , allowMasterMaster bool ) (masterConfig * ConnectionConfig , err error ) {
127
+ log .Debugf ("Looking for %s on %+v" , ReplicaTermFor ( dbVersion , "master" ) , connectionConfig .Key )
120
128
121
- masterKey , err := GetMasterKeyFromSlaveStatus (connectionConfig )
129
+ masterKey , err := GetMasterKeyFromSlaveStatus (dbVersion , connectionConfig )
122
130
if err != nil {
123
131
return nil , err
124
132
}
@@ -131,34 +139,36 @@ func GetMasterConnectionConfigSafe(connectionConfig *ConnectionConfig, visitedKe
131
139
masterConfig = connectionConfig .Duplicate ()
132
140
masterConfig .Key = * masterKey
133
141
134
- log .Debugf ("Master of %+v is %+v" , connectionConfig .Key , masterConfig .Key )
142
+ log .Debugf ("%s of %+v is %+v" , ReplicaTermFor ( dbVersion , "master" ) , connectionConfig .Key , masterConfig .Key )
135
143
if visitedKeys .HasKey (masterConfig .Key ) {
136
144
if allowMasterMaster {
137
145
return connectionConfig , nil
138
146
}
139
147
return nil , fmt .Errorf ("There seems to be a master-master setup at %+v. This is unsupported. Bailing out" , masterConfig .Key )
140
148
}
141
149
visitedKeys .AddKey (masterConfig .Key )
142
- return GetMasterConnectionConfigSafe (masterConfig , visitedKeys , allowMasterMaster )
150
+ return GetMasterConnectionConfigSafe (dbVersion , masterConfig , visitedKeys , allowMasterMaster )
143
151
}
144
152
145
- func GetReplicationBinlogCoordinates (db * gosql.DB ) (readBinlogCoordinates * BinlogCoordinates , executeBinlogCoordinates * BinlogCoordinates , err error ) {
146
- err = sqlutils .QueryRowsMap (db , `show slave status` , func (m sqlutils.RowMap ) error {
153
+ func GetReplicationBinlogCoordinates (dbVersion string , db * gosql.DB ) (readBinlogCoordinates * BinlogCoordinates , executeBinlogCoordinates * BinlogCoordinates , err error ) {
154
+ showReplicaStatusQuery := fmt .Sprintf ("show %s" , ReplicaTermFor (dbVersion , `slave status` ))
155
+ err = sqlutils .QueryRowsMap (db , showReplicaStatusQuery , func (m sqlutils.RowMap ) error {
147
156
readBinlogCoordinates = & BinlogCoordinates {
148
- LogFile : m .GetString ("Master_Log_File" ),
149
- LogPos : m .GetInt64 ("Read_Master_Log_Pos" ),
157
+ LogFile : m .GetString (ReplicaTermFor ( dbVersion , "Master_Log_File" ) ),
158
+ LogPos : m .GetInt64 (ReplicaTermFor ( dbVersion , "Read_Master_Log_Pos" ) ),
150
159
}
151
160
executeBinlogCoordinates = & BinlogCoordinates {
152
- LogFile : m .GetString ("Relay_Master_Log_File" ),
153
- LogPos : m .GetInt64 ("Exec_Master_Log_Pos" ),
161
+ LogFile : m .GetString (ReplicaTermFor ( dbVersion , "Relay_Master_Log_File" ) ),
162
+ LogPos : m .GetInt64 (ReplicaTermFor ( dbVersion , "Exec_Master_Log_Pos" ) ),
154
163
}
155
164
return nil
156
165
})
157
166
return readBinlogCoordinates , executeBinlogCoordinates , err
158
167
}
159
168
160
- func GetSelfBinlogCoordinates (db * gosql.DB ) (selfBinlogCoordinates * BinlogCoordinates , err error ) {
161
- err = sqlutils .QueryRowsMap (db , `show master status` , func (m sqlutils.RowMap ) error {
169
+ func GetSelfBinlogCoordinates (dbVersion string , db * gosql.DB ) (selfBinlogCoordinates * BinlogCoordinates , err error ) {
170
+ binaryLogStatusTerm := ReplicaTermFor (dbVersion , "master status" )
171
+ err = sqlutils .QueryRowsMap (db , fmt .Sprintf ("show %s" , binaryLogStatusTerm ), func (m sqlutils.RowMap ) error {
162
172
selfBinlogCoordinates = & BinlogCoordinates {
163
173
LogFile : m .GetString ("File" ),
164
174
LogPos : m .GetInt64 ("Position" ),
0 commit comments