From af99b247f9525a46a9e20f3b8711c457fab73da2 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Sat, 4 Jun 2022 23:59:00 +0200 Subject: [PATCH 1/4] Add `Migrated` changelog event --- go/logic/migrator.go | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/go/logic/migrator.go b/go/logic/migrator.go index c5cb244..13108bc 100644 --- a/go/logic/migrator.go +++ b/go/logic/migrator.go @@ -24,8 +24,9 @@ import ( type ChangelogState string const ( + AllEventsUpToLockProcessed ChangelogState = "AllEventsUpToLockProcessed" GhostTableMigrated ChangelogState = "GhostTableMigrated" - AllEventsUpToLockProcessed = "AllEventsUpToLockProcessed" + Migrated ChangelogState = "Migrated" ) func ReadChangelogState(s string) ChangelogState { @@ -215,6 +216,8 @@ func (this *Migrator) onChangelogStateEvent(dmlEvent *binlog.BinlogDMLEvent) (er changelogState := ReadChangelogState(changelogStateString) this.migrationContext.Log.Infof("Intercepted changelog state %s", changelogState) switch changelogState { + case Migrated: + // no-op event case GhostTableMigrated: { this.ghostTableMigrated <- true @@ -534,19 +537,20 @@ func (this *Migrator) cutOver() (err error) { } } } - if this.migrationContext.CutOverType == base.CutOverAtomic { + + switch this.migrationContext.CutOverType { + case base.CutOverAtomic: // Atomic solution: we use low timeout and multiple attempts. But for // each failed attempt, we throttle until replication lag is back to normal - err := this.atomicCutOver() - this.handleCutOverResult(err) - return err + err = this.atomicCutOver() + case base.CutOverTwoStep: + err = this.cutOverTwoStep() + default: + return this.migrationContext.Log.Fatalf("Unknown cut-over type: %d; should never get here!", this.migrationContext.CutOverType) } - if this.migrationContext.CutOverType == base.CutOverTwoStep { - err := this.cutOverTwoStep() - this.handleCutOverResult(err) - return err - } - return this.migrationContext.Log.Fatalf("Unknown cut-over type: %d; should never get here!", this.migrationContext.CutOverType) + + this.handleCutOverResult(err) + return err } // Inject the "AllEventsUpToLockProcessed" state hint, wait for it to appear in the binary logs, @@ -1296,6 +1300,11 @@ func (this *Migrator) executeWriteFuncs() error { func (this *Migrator) finalCleanup() error { atomic.StoreInt64(&this.migrationContext.CleanupImminentFlag, 1) + this.migrationContext.Log.Infof("Writing changelog state: %+v", Migrated) + if _, err := this.applier.WriteChangelogState(string(Migrated)); err != nil { + return err + } + if this.migrationContext.Noop { if createTableStatement, err := this.inspector.showCreateTable(this.migrationContext.GetGhostTableName()); err == nil { this.migrationContext.Log.Infof("New table structure follows") From ec199f11858193131309e15399e15ceea54e4fc5 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Sun, 5 Jun 2022 00:06:41 +0200 Subject: [PATCH 2/4] revert out of scope change --- go/logic/migrator.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/go/logic/migrator.go b/go/logic/migrator.go index 13108bc..89106b7 100644 --- a/go/logic/migrator.go +++ b/go/logic/migrator.go @@ -537,20 +537,19 @@ func (this *Migrator) cutOver() (err error) { } } } - - switch this.migrationContext.CutOverType { - case base.CutOverAtomic: + if this.migrationContext.CutOverType == base.CutOverAtomic { // Atomic solution: we use low timeout and multiple attempts. But for // each failed attempt, we throttle until replication lag is back to normal - err = this.atomicCutOver() - case base.CutOverTwoStep: - err = this.cutOverTwoStep() - default: - return this.migrationContext.Log.Fatalf("Unknown cut-over type: %d; should never get here!", this.migrationContext.CutOverType) + err := this.atomicCutOver() + this.handleCutOverResult(err) + return err } - - this.handleCutOverResult(err) - return err + if this.migrationContext.CutOverType == base.CutOverTwoStep { + err := this.cutOverTwoStep() + this.handleCutOverResult(err) + return err + } + return this.migrationContext.Log.Fatalf("Unknown cut-over type: %d; should never get here!", this.migrationContext.CutOverType) } // Inject the "AllEventsUpToLockProcessed" state hint, wait for it to appear in the binary logs, From 246800e053c3631360181fd95dd3ca58d71ed924 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Thu, 7 Jul 2022 17:38:41 +0200 Subject: [PATCH 3/4] Fix lint --- go/logic/migrator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/logic/migrator.go b/go/logic/migrator.go index 94958c4..9fc7a6a 100644 --- a/go/logic/migrator.go +++ b/go/logic/migrator.go @@ -27,7 +27,7 @@ type ChangelogState string const ( AllEventsUpToLockProcessed ChangelogState = "AllEventsUpToLockProcessed" GhostTableMigrated ChangelogState = "GhostTableMigrated" - Migrated ChangelogState = "Migrated" + Migrated ChangelogState = "Migrated" ReadMigrationRangeValues ChangelogState = "ReadMigrationRangeValues" ) From 54db4174b351ac8ec1e7259e122e098a3bc17311 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Thu, 7 Jul 2022 17:40:01 +0200 Subject: [PATCH 4/4] Consolidate no-op states --- go/logic/migrator.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/go/logic/migrator.go b/go/logic/migrator.go index 9fc7a6a..159d294 100644 --- a/go/logic/migrator.go +++ b/go/logic/migrator.go @@ -220,7 +220,7 @@ func (this *Migrator) onChangelogStateEvent(dmlEvent *binlog.BinlogDMLEvent) (er changelogState := ReadChangelogState(changelogStateString) this.migrationContext.Log.Infof("Intercepted changelog state %s", changelogState) switch changelogState { - case Migrated: + case Migrated, ReadMigrationRangeValues: // no-op event case GhostTableMigrated: { @@ -241,8 +241,6 @@ func (this *Migrator) onChangelogStateEvent(dmlEvent *binlog.BinlogDMLEvent) (er this.applyEventsQueue <- newApplyEventStructByFunc(&applyEventFunc) }() } - case ReadMigrationRangeValues: - // no-op event default: { return fmt.Errorf("Unknown changelog state: %+v", changelogState)