From 42ae3e37f52b9041eb84d62e0f471d15fbc0d96a Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Wed, 1 Jun 2016 10:40:49 +0200 Subject: [PATCH] dropping _osc (changelog) table at end of operation; also better status hint at end of operation --- go/logic/migrator.go | 64 ++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/go/logic/migrator.go b/go/logic/migrator.go index cc50fda..c7692bf 100644 --- a/go/logic/migrator.go +++ b/go/logic/migrator.go @@ -335,6 +335,9 @@ func (this *Migrator) Migrate() (err error) { return err } + if err := this.finalCleanup(); err != nil { + return nil + } log.Infof("Done migrating %s.%s", sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(this.migrationContext.OriginalTableName)) return nil } @@ -381,26 +384,10 @@ func (this *Migrator) stopWritesAndCompleteMigration() (err error) { }); err != nil { return err } - if err := this.dropOldTableIfRequired(); err != nil { - return err - } } return } -func (this *Migrator) dropOldTableIfRequired() (err error) { - if !this.migrationContext.OkToDropTable { - return nil - } - dropTableFunc := func() error { - return this.applier.dropTable(this.migrationContext.GetOldTableName()) - } - if err := this.retryOperation(dropTableFunc); err != nil { - return err - } - return nil -} - // Inject the "AllEventsUpToLockProcessed" state hint, wait for it to appear in the binary logs, // make sure the queue is drained. func (this *Migrator) waitForEventsUpToLock() (err error) { @@ -435,9 +422,6 @@ func (this *Migrator) stopWritesAndCompleteMigrationOnMasterQuickAndBumpy() (err if err := this.retryOperation(this.applier.UnlockTables); err != nil { return err } - if err := this.dropOldTableIfRequired(); err != nil { - return err - } lockAndRenameDuration := this.migrationContext.RenameTablesEndTime.Sub(this.migrationContext.LockTablesStartTime) renameDuration := this.migrationContext.RenameTablesEndTime.Sub(this.migrationContext.RenameTablesStartTime) @@ -520,6 +504,7 @@ func (this *Migrator) stopWritesAndCompleteMigrationOnReplica() (err error) { this.waitForEventsUpToLock() + this.printMigrationStatusHint() log.Info("Table duplicated with new schema. Am not touching the original table. Replication is stopped. You may now compare the two tables to gain trust into this tool's operation") return nil } @@ -569,6 +554,17 @@ func (this *Migrator) initiateStatus() error { return nil } +func (this *Migrator) printMigrationStatusHint() { + hint := fmt.Sprintf("# Migrating %s.%s; Ghost table is %s.%s; migration started at %+v", + sql.EscapeName(this.migrationContext.DatabaseName), + sql.EscapeName(this.migrationContext.OriginalTableName), + sql.EscapeName(this.migrationContext.DatabaseName), + sql.EscapeName(this.migrationContext.GetGhostTableName()), + this.migrationContext.StartTime.Format(time.RubyDate), + ) + fmt.Println(hint) +} + func (this *Migrator) printStatus() { elapsedTime := this.migrationContext.ElapsedTime() elapsedSeconds := int64(elapsedTime.Seconds()) @@ -580,16 +576,9 @@ func (this *Migrator) printStatus() { } // Before status, let's see if we should print a nice reminder for what exactly we're doing here. - shouldPrintCourtesyReminder := (elapsedSeconds%600 == 0) - if shouldPrintCourtesyReminder { - courtesyReminder := fmt.Sprintf("# Migrating %s.%s; Ghost table is %s.%s; migration started at %+v", - sql.EscapeName(this.migrationContext.DatabaseName), - sql.EscapeName(this.migrationContext.OriginalTableName), - sql.EscapeName(this.migrationContext.DatabaseName), - sql.EscapeName(this.migrationContext.GetGhostTableName()), - this.migrationContext.StartTime.Format(time.RubyDate), - ) - fmt.Println(courtesyReminder) + shouldPrintMigrationStatusHint := (elapsedSeconds%600 == 0) + if shouldPrintMigrationStatusHint { + this.printMigrationStatusHint() } var etaSeconds float64 = math.MaxFloat64 @@ -816,3 +805,20 @@ func (this *Migrator) executeWriteFuncs() error { } return nil } + +// finalCleanup takes actions at very end of migration, dropping tables etc. +func (this *Migrator) finalCleanup() error { + if err := this.retryOperation(this.applier.DropChangelogTable); err != nil { + return err + } + if this.migrationContext.OkToDropTable && !this.migrationContext.TestOnReplica { + dropTableFunc := func() error { + return this.applier.dropTable(this.migrationContext.GetOldTableName()) + } + if err := this.retryOperation(dropTableFunc); err != nil { + return err + } + } + + return nil +}