-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Online DDL: resume vreplication after cut-over/RENAME failure #18428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shlomi-noach
merged 5 commits into
vitessio:main
from
planetscale:onlineddl-cutover-start-vrepl
Jul 10, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
474fb29
Online DDL: resume vreplication after cut-over/RENAME failure
shlomi-noach 67de091
ensure to remvoe vreplication entry when starting a vrepl migration (…
shlomi-noach b180f6f
typo
shlomi-noach b337478
Update go/vt/vttablet/onlineddl/executor.go
shlomi-noach bffd76f
fix referencing call
shlomi-noach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -605,7 +605,7 @@ func (e *Executor) primaryPosition(ctx context.Context) (pos replication.Positio | |
| } | ||
|
|
||
| // terminateVReplMigration stops vreplication, then removes the _vt.vreplication entry for the given migration | ||
| func (e *Executor) terminateVReplMigration(ctx context.Context, uuid string) error { | ||
| func (e *Executor) terminateVReplMigration(ctx context.Context, uuid string, deleteEntry bool) error { | ||
| tablet, err := e.ts.GetTablet(ctx, e.tabletAlias) | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -621,10 +621,26 @@ func (e *Executor) terminateVReplMigration(ctx context.Context, uuid string) err | |
| if _, err := e.vreplicationExec(ctx, tablet.Tablet, query); err != nil { | ||
| log.Errorf("FAIL vreplicationExec: uuid=%s, query=%v, error=%v", uuid, query, err) | ||
| } | ||
| if deleteEntry { | ||
| if err := e.deleteVReplicationEntry(ctx, uuid); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| if err := e.deleteVReplicationEntry(ctx, uuid); err != nil { | ||
| return nil | ||
| } | ||
|
|
||
| func (e *Executor) startVReplication(ctx context.Context, tablet *topodatapb.Tablet, workflow string) (err error) { | ||
| query, err := sqlparser.ParseAndBind(sqlStartVReplStream, | ||
| sqltypes.StringBindVariable(e.dbName), | ||
| sqltypes.StringBindVariable(workflow), | ||
| ) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if _, err := e.vreplicationExec(ctx, tablet, query); err != nil { | ||
| return vterrors.Wrapf(err, "FAIL vreplicationExec: uuid=%s, query=%v", workflow, query) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -1071,6 +1087,16 @@ func (e *Executor) cutOverVReplMigration(ctx context.Context, s *VReplStream, sh | |
| } | ||
| go log.Infof("cutOverVReplMigration %v: stopped vreplication", s.workflow) | ||
|
|
||
| defer func() { | ||
| if !renameWasSuccessful { | ||
| // Restarting vreplication | ||
| if err := e.startVReplication(ctx, tablet.Tablet, s.workflow); err != nil { | ||
| log.Errorf("cutOverVReplMigration %v: failed restarting vreplication after cutover failure: %v", s.workflow, err) | ||
| } | ||
| go log.Infof("cutOverVReplMigration %v: started vreplication after cutover failure", s.workflow) | ||
| } | ||
| }() | ||
|
|
||
| // rename tables atomically (remember, writes on source tables are stopped) | ||
| { | ||
| if isVreplicationTestSuite { | ||
|
|
@@ -1345,7 +1371,7 @@ func (e *Executor) initVreplicationRevertMigration(ctx context.Context, onlineDD | |
| // ExecuteWithVReplication sets up the grounds for a vreplication schema migration | ||
| func (e *Executor) ExecuteWithVReplication(ctx context.Context, onlineDDL *schema.OnlineDDL, revertMigration *schema.OnlineDDL) error { | ||
| // make sure there's no vreplication workflow running under same name | ||
| _ = e.terminateVReplMigration(ctx, onlineDDL.UUID) | ||
| _ = e.terminateVReplMigration(ctx, onlineDDL.UUID, true) | ||
|
|
||
| if e.tabletTypeFunc() != topodatapb.TabletType_PRIMARY { | ||
| return ErrExecutorNotWritableTablet | ||
|
|
@@ -1506,7 +1532,7 @@ func (e *Executor) terminateMigration(ctx context.Context, onlineDDL *schema.Onl | |
| // migration could have started by a different tablet. We need to actively verify if it is running | ||
| s, _ := e.readVReplStream(ctx, onlineDDL.UUID, true) | ||
| foundRunning = (s != nil && s.isRunning()) | ||
| if err := e.terminateVReplMigration(ctx, onlineDDL.UUID); err != nil { | ||
| if err := e.terminateVReplMigration(ctx, onlineDDL.UUID, false); err != nil { | ||
| return foundRunning, fmt.Errorf("Error terminating migration, vreplication exec error: %+v", err) | ||
| } | ||
| } | ||
|
|
@@ -3137,6 +3163,7 @@ func (e *Executor) reviewRunningMigrations(ctx context.Context) (countRunnning i | |
| cancellable = append(cancellable, newCancellableMigration(uuid, s.message)) | ||
| } | ||
| if !s.isRunning() { | ||
| log.Infof("migration %s in 'running' state but vreplication state is '%s'", uuid, s.state.String()) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just some added visibility. |
||
| return nil | ||
| } | ||
| // This VRepl migration may have started from outside this tablet, so | ||
|
|
@@ -4128,7 +4155,7 @@ func (e *Executor) ForceCutOverPendingMigrations(ctx context.Context) (result *s | |
| if err != nil { | ||
| return result, err | ||
| } | ||
| log.Infof("ForceCutOverPendingMigrations: iterating %v migrations %s", len(uuids)) | ||
| log.Infof("ForceCutOverPendingMigrations: iterating %v migrations", len(uuids)) | ||
|
|
||
| result = &sqltypes.Result{} | ||
| for _, uuid := range uuids { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why to start a goroutine for calling in log function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because in this critical section I don't want to block on writing a log line, as silly as it may be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shlomi-noach Is it then essential to log at all? Starting a goroutine also has some cost 😄.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dbussink , yeah, I'd like this entry to appear in the logs. If it appears, it means vreplication has definitely started, which is an important info
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not be the only
go log.Infofcall in thecutOverVReplMigrationfunction. There's a bunch of other such calls.