minor cleanup
This commit is contained in:
parent
1be6a4c082
commit
05f32ebf29
@ -199,42 +199,16 @@ func (this *Applier) ValidateOrDropExistingTables() error {
|
|||||||
// It is safer to attempt the change than try and parse the DDL, since
|
// 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.
|
// there might be specifics about the table which make it not possible to apply instantly.
|
||||||
func (this *Applier) AttemptInstantDDL() error {
|
func (this *Applier) AttemptInstantDDL() error {
|
||||||
|
|
||||||
query := fmt.Sprintf(`ALTER /* gh-ost */ TABLE %s.%s %s, ALGORITHM=INSTANT`,
|
query := fmt.Sprintf(`ALTER /* gh-ost */ TABLE %s.%s %s, ALGORITHM=INSTANT`,
|
||||||
sql.EscapeName(this.migrationContext.DatabaseName),
|
sql.EscapeName(this.migrationContext.DatabaseName),
|
||||||
sql.EscapeName(this.migrationContext.OriginalTableName),
|
sql.EscapeName(this.migrationContext.OriginalTableName),
|
||||||
this.migrationContext.AlterStatementOptions,
|
this.migrationContext.AlterStatementOptions,
|
||||||
)
|
)
|
||||||
this.migrationContext.Log.Infof("INSTANT DDL Query is: %s", query)
|
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 := func() error {
|
_, err := this.db.Exec(query)
|
||||||
tx, err := this.db.Begin()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
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
|
// CreateGhostTable creates the ghost table on the applier host
|
||||||
func (this *Applier) CreateGhostTable() error {
|
func (this *Applier) CreateGhostTable() error {
|
||||||
|
@ -370,7 +370,6 @@ func (this *Migrator) Migrate() (err error) {
|
|||||||
if err := this.initiateApplier(); err != nil {
|
if err := this.initiateApplier(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := this.createFlagFiles(); err != nil {
|
if err := this.createFlagFiles(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user