@@ -125,14 +125,9 @@ func (r *nodeSQLRunner) ChangeMasterTo(ctx context.Context, masterHost, user, pa
125125
126126// MarkConfigurationDone write in a MEMORY table value. The readiness probe checks for that value to exist to succeed.
127127func (r * nodeSQLRunner ) MarkConfigurationDone (ctx context.Context ) error {
128- query := `
129- CREATE TABLE IF NOT EXISTS %s.%s (
130- ok tinyint(1) NOT NULL
131- ) ENGINE=MEMORY;
132-
133- INSERT INTO %[1]s.%[2]s VALUES (1);
134- `
135- query = fmt .Sprintf (query , constants .OperatorDbName , constants .OperatorReadinessTableName )
128+ // nolint: gosec
129+ query := fmt .Sprintf ("REPLACE INTO %s.%s VALUES ('%s', '1');" ,
130+ constants .OperatorDbName , constants .OperatorStatusTableName , "configured" )
136131
137132 if err := r .runQuery (ctx , query ); err != nil {
138133 return fmt .Errorf ("failed to mark configuration done, err: %s" , err )
@@ -203,38 +198,35 @@ func (r *nodeSQLRunner) dbConn() (*sql.DB, func(), error) {
203198}
204199
205200func (r * nodeSQLRunner ) SetPurgedGTID (ctx context.Context ) error {
206- // first check if the GTID should be set, if the table exists or if the GTID was set before (used)
201+ // first check if the GTID should be set, if in the status table is a key with the GTID that was set
207202 // nolint: gosec
208- qq := fmt .Sprintf ("SELECT used FROM %[1]s.%[2]s WHERE id=1" ,
209- constants .OperatorDbName , constants .OperatorGtidsTableName )
210-
211- var used bool
212- if err := r .readFromMysql (ctx , qq , & used ); err != nil {
213- // if it's a: "Table doesn't exist" error then GTID should not be set, it's a master case.
214- if isMySQLError (err , 1146 ) || err == sql .ErrNoRows {
215- log .V (1 ).Info ("GTID purged table does not exists" , "host" , r .Host ())
216- return nil
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
217211 }
218-
219- return err
220212 }
221213
222- if used {
223- log .V (1 ).Info ("GTID purged set" , "host" , r .Host ())
214+ if len ( value ) != 0 {
215+ log .V (1 ).Info ("GTID purged was already set" , "host" , r .Host (), "gtid_purged" , value )
224216 return nil
225217 }
226218
227219 // GTID exists and should be set in a transaction
228220 // nolint: gosec
229221 query := fmt .Sprintf (`
230- SET @@SESSION.SQL_LOG_BIN = 0;
231- START TRANSACTION;
232- SELECT gtid INTO @gtid FROM %[1]s.%[2]s WHERE id=1 AND used=false ;
233- RESET MASTER;
234- SET @@GLOBAL.GTID_PURGED = @gtid;
235- REPLACE INTO %[1]s.%[2]s VALUES (1 , @gtid, true );
236- COMMIT;
237- ` , constants .OperatorDbName , constants .OperatorGtidsTableName )
222+ SET @@SESSION.SQL_LOG_BIN = 0;
223+ START TRANSACTION;
224+ SELECT value INTO @gtid FROM %[1]s.%[2]s WHERE name='%s' ;
225+ RESET MASTER;
226+ SET @@GLOBAL.GTID_PURGED = @gtid;
227+ REPLACE INTO %[1]s.%[2]s VALUES ('%s' , @gtid);
228+ COMMIT;
229+ ` , constants .OperatorDbName , constants .OperatorStatusTableName , "backup_gtid_purged" , "set_gtid_purged" )
238230
239231 if err := r .runQuery (ctx , query ); err != nil {
240232 return err
0 commit comments