@@ -198,21 +198,25 @@ func (r *nodeSQLRunner) dbConn() (*sql.DB, func(), error) {
198198}
199199
200200func (r * nodeSQLRunner ) SetPurgedGTID (ctx context.Context ) error {
201- // first check if the GTID should be set, if in the status table is a key with the GTID that was set
202- // nolint: gosec
203- qq := fmt .Sprintf ("SELECT value FROM %s.%s WHERE name='%s'" ,
204- constants .OperatorDbName , constants .OperatorStatusTableName , "set_gtid_purged" )
205-
206- var value string
207- if err := r .readFromMysql (ctx , qq , & value ); err != nil {
208- // if no rows found then continue to add GTID purged
209- if err != sql .ErrNoRows {
210- return err
211- }
201+ var (
202+ err error
203+ setGTID string
204+ backupGTID string
205+ )
206+
207+ // first check if the GTID was set before
208+ if setGTID , err = r .readStatusValue (ctx , "set_gtid_purged" ); err != nil {
209+ return err
210+ } else if len (setGTID ) != 0 {
211+ log .V (1 ).Info ("GTID purged was already set" , "host" , r .Host (), "gtid_purged" , setGTID )
212+ return nil
212213 }
213214
214- if len (value ) != 0 {
215- log .V (1 ).Info ("GTID purged was already set" , "host" , r .Host (), "gtid_purged" , value )
215+ // check if there is any GTID to set
216+ if backupGTID , err = r .readStatusValue (ctx , "backup_gtid_purged" ); err != nil {
217+ return err
218+ } else if len (backupGTID ) == 0 {
219+ log .V (1 ).Info ("no GTID to set" , "host" , r .Host ())
216220 return nil
217221 }
218222
@@ -235,6 +239,22 @@ func (r *nodeSQLRunner) SetPurgedGTID(ctx context.Context) error {
235239 return nil
236240}
237241
242+ func (r * nodeSQLRunner ) readStatusValue (ctx context.Context , key string ) (string , error ) {
243+ // nolint: gosec
244+ qq := fmt .Sprintf ("SELECT value FROM %s.%s WHERE name='%s'" ,
245+ constants .OperatorDbName , constants .OperatorStatusTableName , key )
246+
247+ var value string
248+ if err := r .readFromMysql (ctx , qq , & value ); err != nil {
249+ // if no rows found then continue to add GTID purged
250+ if err != sql .ErrNoRows {
251+ return "" , err
252+ }
253+ }
254+
255+ return value , nil
256+ }
257+
238258// isMySQLError checks if a mysql error is of the given code.
239259// more information about mysql error codes can be found here:
240260// https://dev.mysql.com/doc/refman/8.0/en/server-error-reference.html
0 commit comments