minor cleanup

This commit is contained in:
Morgan Tocker 2022-11-10 09:30:13 -07:00
parent 1be6a4c082
commit 05f32ebf29
2 changed files with 3 additions and 30 deletions

View File

@ -199,41 +199,15 @@ func (this *Applier) ValidateOrDropExistingTables() error {
// It is safer to attempt the change than try and parse the DDL, since
// there might be specifics about the table which make it not possible to apply instantly.
func (this *Applier) AttemptInstantDDL() error {
query := fmt.Sprintf(`ALTER /* gh-ost */ TABLE %s.%s %s, ALGORITHM=INSTANT`,
sql.EscapeName(this.migrationContext.DatabaseName),
sql.EscapeName(this.migrationContext.OriginalTableName),
this.migrationContext.AlterStatementOptions,
)
this.migrationContext.Log.Infof("INSTANT DDL Query is: %s", query)
err := func() error {
tx, err := this.db.Begin()
if err != nil {
this.migrationContext.Log.Infof("INSTANT DDL query is: %s", query)
// We don't need a trx, because for instant DDL the SQL mode doesn't matter.
_, err := this.db.Exec(query)
return err
}
defer tx.Rollback()
sessionQuery := fmt.Sprintf(`SET SESSION time_zone = '%s'`, this.migrationContext.ApplierTimeZone)
sessionQuery = fmt.Sprintf("%s, %s", sessionQuery, this.generateSqlModeQuery())
if _, err := tx.Exec(sessionQuery); err != nil {
return err
}
if _, err := tx.Exec(query); err != nil {
this.migrationContext.Log.Infof("INSTANT DDL failed: %s", err)
return err
}
if err := tx.Commit(); err != nil {
// Neither SET SESSION nor ALTER are really transactional, so strictly speaking
// there's no need to commit; but let's do this the legit way anyway.
return err
}
return nil
}()
return err
}
// CreateGhostTable creates the ghost table on the applier host

View File

@ -370,7 +370,6 @@ func (this *Migrator) Migrate() (err error) {
if err := this.initiateApplier(); err != nil {
return err
}
if err := this.createFlagFiles(); err != nil {
return err
}