Skip to content

Commit 0e7de97

Browse files
committed
add hooks
1 parent 301564b commit 0e7de97

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

go/base/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ func getSafeTableName(baseName string, suffix string) string {
351351
// or a given table name
352352
func (this *MigrationContext) GetGhostTableName() string {
353353
if this.Revert {
354+
// When reverting the "ghost" table is the _del table from the original migration.
354355
return this.OldTableName
355356
}
356357
if this.ForceTmpTableName != "" {
@@ -371,7 +372,6 @@ func (this *MigrationContext) GetOldTableName() string {
371372

372373
suffix := "del"
373374
if this.Revert {
374-
// When reverting the "ghost" table is the _del table
375375
suffix = "rev_del"
376376
}
377377
if this.TimestampOldTable {

go/logic/hooks.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func (this *HooksExecutor) applyEnvironmentVariables(extraVariables ...string) [
6969
env = append(env, fmt.Sprintf("GH_OST_HOOKS_HINT_OWNER=%s", this.migrationContext.HooksHintOwner))
7070
env = append(env, fmt.Sprintf("GH_OST_HOOKS_HINT_TOKEN=%s", this.migrationContext.HooksHintToken))
7171
env = append(env, fmt.Sprintf("GH_OST_DRY_RUN=%t", this.migrationContext.Noop))
72+
env = append(env, fmt.Sprintf("GH_OST_REVERT=%t", this.migrationContext.Revert))
7273

7374
env = append(env, extraVariables...)
7475
return env

go/logic/inspect.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ func (this *Inspector) ValidateOriginalTable() (err error) {
102102
}
103103

104104
func (this *Inspector) InspectTableColumnsAndUniqueKeys(tableName string) (columns *sql.ColumnList, virtualColumns *sql.ColumnList, uniqueKeys [](*sql.UniqueKey), err error) {
105-
this.migrationContext.Log.Debugf("InspectTableColumnsAndUniqueKeys: %s", tableName)
106105
uniqueKeys, err = this.getCandidateUniqueKeys(tableName)
107106
if err != nil {
108107
return columns, virtualColumns, uniqueKeys, err

go/logic/migrator.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ func (this *Migrator) Migrate() (err error) {
364364
return err
365365
}
366366
// If we are resuming, we will initiateStreaming later when we know
367-
// the coordinates to resume streaming.
367+
// the binlog coordinates to resume streaming from.
368368
// If not resuming, the streamer must be initiated before the applier,
369369
// so that the "GhostTableMigrated" event gets processed.
370370
if !this.migrationContext.Resume {
@@ -504,7 +504,7 @@ func (this *Migrator) Migrate() (err error) {
504504
}
505505
atomic.StoreInt64(&this.migrationContext.CutOverCompleteFlag, 1)
506506

507-
if this.migrationContext.Checkpoint {
507+
if this.migrationContext.Checkpoint && !this.migrationContext.Noop {
508508
cutoverChk, err := this.CheckpointAfterCutOver()
509509
if err != nil {
510510
this.migrationContext.Log.Warningf("failed to checkpoint after cutover: %+v", err)
@@ -527,7 +527,6 @@ func (this *Migrator) Migrate() (err error) {
527527
// after the original cutover, then doing another cutover to swap the tables back.
528528
// The steps are similar to Migrate(), but without row copying.
529529
func (this *Migrator) Revert() error {
530-
//TODO: add hooks
531530
this.migrationContext.Log.Infof("Reverting %s.%s from %s.%s",
532531
sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(this.migrationContext.OriginalTableName),
533532
sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(this.migrationContext.OldTableName))
@@ -599,11 +598,17 @@ func (this *Migrator) Revert() error {
599598
} else {
600599
retrier = this.retryOperation
601600
}
601+
if err := this.hooksExecutor.onBeforeCutOver(); err != nil {
602+
return err
603+
}
602604
if err := retrier(this.cutOver); err != nil {
603605
return err
604606
}
605607
atomic.StoreInt64(&this.migrationContext.CutOverCompleteFlag, 1)
606-
this.migrationContext.Log.Infof("Reverted %s.%s", sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(this.migrationContext.OriginalTableName))
608+
if err := this.hooksExecutor.onSuccess(); err != nil {
609+
return err
610+
}
611+
this.migrationContext.Log.Infof("Done reverting %s.%s", sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(this.migrationContext.OriginalTableName))
607612
return nil
608613
}
609614

@@ -749,6 +754,7 @@ func (this *Migrator) waitForEventsUpToLock() error {
749754
if lockProcessed.state == allEventsUpToLockProcessedChallenge {
750755
this.migrationContext.Log.Infof("Waiting for events up to lock: got %s", lockProcessed.state)
751756
found = true
757+
this.lastLockProcessed = lockProcessed
752758
} else {
753759
this.migrationContext.Log.Infof("Waiting for events up to lock: skipping %s", lockProcessed.state)
754760
}
@@ -757,7 +763,6 @@ func (this *Migrator) waitForEventsUpToLock() error {
757763
}
758764
waitForEventsUpToLockDuration := time.Since(waitForEventsUpToLockStartTime)
759765

760-
this.lastLockProcessed = lockProcessed
761766
this.migrationContext.Log.Infof("Done waiting for events up to lock; duration=%+v", waitForEventsUpToLockDuration)
762767
this.printStatus(ForcePrintStatusAndHintRule)
763768

go/logic/migrator_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ func (suite *MigratorTestSuite) TestRevert() {
742742
var _tableName, checksum1, checksum2 string
743743
rows, err := suite.db.Query(fmt.Sprintf("CHECKSUM TABLE %s, %s", testMysqlTableName, oldTableName))
744744
suite.Require().NoError(err)
745+
defer rows.Close()
745746
suite.Require().True(rows.Next())
746747
suite.Require().NoError(rows.Scan(&_tableName, &checksum1))
747748
suite.Require().True(rows.Next())

0 commit comments

Comments
 (0)