-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Online DDL: support migration cut-over backoff and forced cut-over #14546
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 39 commits into
vitessio:main
from
planetscale:onlineddl-cutover-backoff
Dec 13, 2023
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
57667a7
Online DDL: backoff for vitess cut-over intervals
shlomi-noach 906e7fc
resolve conflict
shlomi-noach 100eb76
refactor reviewVReplRunningMigration()
shlomi-noach 0c92e95
DDL Strategy: support --force-cut-over-after=<duration> flag
shlomi-noach 08c83b3
schema_migrations: support force_cutover column
shlomi-noach cb4bcf0
Updte ready_to_complete: only update ready_to_complete_timestamp on f…
shlomi-noach abf999f
detect (heuristic) queries running on a given table, and detect trans…
shlomi-noach bd2868b
validate --force-cut-over-after
shlomi-noach c3f3ccc
shouldCutOverAccordingToBackoff(): backoff and force-cutover logic; k…
shlomi-noach 8e7d8ac
sqlparser: support ALTER VITESS_MIGRATION '...' FORCE_CUTOVER
shlomi-noach c821fc3
Implement ALTER VITESS_MIGRATION '...' FORCE_CUTOVER in query executo…
shlomi-noach a0d980f
endtoend: test 'ALTER VITESS_MIGRATION ... FORCE_CUTOVER' statement, …
shlomi-noach 26d7809
endtoend: validate 'ALTER VITESS_MIGRATION ... FORCE_CUTOVER' kills t…
shlomi-noach 1c002c5
FORCE_CUTOVER triggers scheduler next checks
shlomi-noach 9a0a82b
proto: ForceCutOverSchemaMigration, ForceCutOverSchemaMigrationReques…
shlomi-noach 9eac122
nuance test changes
shlomi-noach 738cd7b
rename function
shlomi-noach 24da375
vtctl gRPC: implement CleanupSchemaMigration
shlomi-noach 359c6fb
implement vtctldclient force_cutover
shlomi-noach 0589d4a
resolved conflict
shlomi-noach 804b684
support 'ALTER VITESS_MIGRATION FORCE_CUTOVER ALL'
shlomi-noach 769053b
force cutover only possible on MySQL 8.0
shlomi-noach 7995987
resolved conflict
shlomi-noach 7ed323c
resolved conflict
shlomi-noach 5240429
Merge branch 'onlineddl-cutover-backoff' of github.com:planetscale/vi…
shlomi-noach baae9f2
punctuation
shlomi-noach c787863
validate: --force-cut-over-after is only valid in 'vitess' strategy.
shlomi-noach 71fb82b
simplify test expectations
shlomi-noach 7b7413d
-1 for maxrows
shlomi-noach 7192e96
rename as killTableLockHoldersAndAccessors, add comments
shlomi-noach 92aeac1
endtoend: use context with timeout
shlomi-noach 478fcad
added unit test
shlomi-noach 9c2929b
OnlineDDL command named force-cutover
shlomi-noach 10868b9
Update go/cmd/vtctldclient/command/onlineddl.go
shlomi-noach 2fd3850
span name
shlomi-noach 848cafb
include UUID in log
shlomi-noach 849d8ae
reorder proto alphabetically
shlomi-noach 839f772
resolved conflict
shlomi-noach 892fd23
resolved conflict
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
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
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 |
|---|---|---|
|
|
@@ -200,6 +200,29 @@ func waitForReadyToComplete(t *testing.T, uuid string, expected bool) { | |
| } | ||
| } | ||
|
|
||
| func waitForMessage(t *testing.T, uuid string, messageSubstring string) { | ||
| ctx, cancel := context.WithTimeout(context.Background(), normalWaitTime) | ||
| defer cancel() | ||
|
|
||
| ticker := time.NewTicker(time.Second) | ||
| defer ticker.Stop() | ||
| for { | ||
| rs := onlineddl.ReadMigrations(t, &vtParams, uuid) | ||
| require.NotNil(t, rs) | ||
| for _, row := range rs.Named().Rows { | ||
| message := row.AsString("message", "") | ||
| if strings.Contains(message, messageSubstring) { | ||
|
Member
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. Any reason not to make it case insensitive?
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. I wonder why we should? If the test knows what to expect, then it should expect the exact string. |
||
| return | ||
| } | ||
| } | ||
| select { | ||
| case <-ticker.C: | ||
| case <-ctx.Done(): | ||
| } | ||
| require.NoError(t, ctx.Err()) | ||
| } | ||
| } | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| defer cluster.PanicHandler(nil) | ||
| flag.Parse() | ||
|
|
@@ -366,6 +389,9 @@ func testScheduler(t *testing.T) { | |
| alterNonexistent = ` | ||
| ALTER TABLE nonexistent FORCE | ||
| ` | ||
| populateT1Statement = ` | ||
| insert into t1_test values (1, 'new_row') | ||
| ` | ||
| ) | ||
|
|
||
| testReadTimestamp := func(t *testing.T, uuid string, timestampColumn string) (timestamp string) { | ||
|
|
@@ -490,6 +516,109 @@ func testScheduler(t *testing.T) { | |
| onlineddl.CheckMigrationStatus(t, &vtParams, shards, t1uuid, schema.OnlineDDLStatusComplete) | ||
| }) | ||
| }) | ||
|
|
||
| t.Run("Postpone completion ALTER", func(t *testing.T) { | ||
| t1uuid = testOnlineDDLStatement(t, createParams(trivialAlterT1Statement, ddlStrategy+" --postpone-completion", "vtgate", "", "", true)) // skip wait | ||
|
|
||
| t.Run("wait for t1 running", func(t *testing.T) { | ||
| status := onlineddl.WaitForMigrationStatus(t, &vtParams, shards, t1uuid, normalWaitTime, schema.OnlineDDLStatusRunning) | ||
mattlord marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fmt.Printf("# Migration status (for debug purposes): <%s>\n", status) | ||
| }) | ||
| t.Run("check postpone_completion", func(t *testing.T) { | ||
| rs := onlineddl.ReadMigrations(t, &vtParams, t1uuid) | ||
| require.NotNil(t, rs) | ||
| for _, row := range rs.Named().Rows { | ||
| postponeCompletion := row.AsInt64("postpone_completion", 0) | ||
| assert.Equal(t, int64(1), postponeCompletion) | ||
| } | ||
| }) | ||
| t.Run("complete", func(t *testing.T) { | ||
| onlineddl.CheckCompleteMigration(t, &vtParams, shards, t1uuid, true) | ||
| status := onlineddl.WaitForMigrationStatus(t, &vtParams, shards, t1uuid, normalWaitTime, schema.OnlineDDLStatusComplete, schema.OnlineDDLStatusFailed) | ||
| fmt.Printf("# Migration status (for debug purposes): <%s>\n", status) | ||
| onlineddl.CheckMigrationStatus(t, &vtParams, shards, t1uuid, schema.OnlineDDLStatusComplete) | ||
| }) | ||
| t.Run("check no postpone_completion", func(t *testing.T) { | ||
| rs := onlineddl.ReadMigrations(t, &vtParams, t1uuid) | ||
| require.NotNil(t, rs) | ||
| for _, row := range rs.Named().Rows { | ||
| postponeCompletion := row.AsInt64("postpone_completion", 0) | ||
| assert.Equal(t, int64(0), postponeCompletion) | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| forceCutoverCapable, err := capableOf(mysql.PerformanceSchemaDataLocksTableCapability) // 8.0 | ||
| require.NoError(t, err) | ||
| if forceCutoverCapable { | ||
| t.Run("force_cutover", func(t *testing.T) { | ||
| ctx, cancel := context.WithTimeout(context.Background(), extendedWaitTime*2) | ||
| defer cancel() | ||
|
|
||
| t.Run("populate t1_test", func(t *testing.T) { | ||
| onlineddl.VtgateExecQuery(t, &vtParams, populateT1Statement, "") | ||
| }) | ||
| t1uuid = testOnlineDDLStatement(t, createParams(trivialAlterT1Statement, ddlStrategy+" --postpone-completion", "vtgate", "", "", true)) // skip wait | ||
|
|
||
| t.Run("wait for t1 running", func(t *testing.T) { | ||
| status := onlineddl.WaitForMigrationStatus(t, &vtParams, shards, t1uuid, normalWaitTime, schema.OnlineDDLStatusRunning) | ||
| fmt.Printf("# Migration status (for debug purposes): <%s>\n", status) | ||
| }) | ||
| commitTransactionChan := make(chan any) | ||
| transactionErrorChan := make(chan error) | ||
| t.Run("locking table rows", func(t *testing.T) { | ||
| go runInTransaction(t, ctx, shards[0].Vttablets[0], "select * from t1_test for update", commitTransactionChan, transactionErrorChan) | ||
| }) | ||
| t.Run("check no force_cutover", func(t *testing.T) { | ||
| rs := onlineddl.ReadMigrations(t, &vtParams, t1uuid) | ||
| require.NotNil(t, rs) | ||
| for _, row := range rs.Named().Rows { | ||
| forceCutOver := row.AsInt64("force_cutover", 0) | ||
| assert.Equal(t, int64(0), forceCutOver) // disabled | ||
| } | ||
| }) | ||
| t.Run("attempt to complete", func(t *testing.T) { | ||
| onlineddl.CheckCompleteMigration(t, &vtParams, shards, t1uuid, true) | ||
| }) | ||
| t.Run("cut-over fail due to timeout", func(t *testing.T) { | ||
| waitForMessage(t, t1uuid, "due to context deadline exceeded") | ||
| status := onlineddl.WaitForMigrationStatus(t, &vtParams, shards, t1uuid, normalWaitTime, schema.OnlineDDLStatusComplete, schema.OnlineDDLStatusFailed, schema.OnlineDDLStatusRunning) | ||
| fmt.Printf("# Migration status (for debug purposes): <%s>\n", status) | ||
| onlineddl.CheckMigrationStatus(t, &vtParams, shards, t1uuid, schema.OnlineDDLStatusRunning) | ||
| }) | ||
| t.Run("force_cutover", func(t *testing.T) { | ||
| onlineddl.CheckForceMigrationCutOver(t, &vtParams, shards, t1uuid, true) | ||
| }) | ||
| t.Run("check force_cutover", func(t *testing.T) { | ||
| rs := onlineddl.ReadMigrations(t, &vtParams, t1uuid) | ||
| require.NotNil(t, rs) | ||
| for _, row := range rs.Named().Rows { | ||
| forceCutOver := row.AsInt64("force_cutover", 0) | ||
| assert.Equal(t, int64(1), forceCutOver) // enabled | ||
| } | ||
| }) | ||
| t.Run("expect completion", func(t *testing.T) { | ||
| status := onlineddl.WaitForMigrationStatus(t, &vtParams, shards, t1uuid, normalWaitTime, schema.OnlineDDLStatusComplete, schema.OnlineDDLStatusFailed) | ||
| fmt.Printf("# Migration status (for debug purposes): <%s>\n", status) | ||
| onlineddl.CheckMigrationStatus(t, &vtParams, shards, t1uuid, schema.OnlineDDLStatusComplete) | ||
| }) | ||
| t.Run("expect transaction failure", func(t *testing.T) { | ||
| select { | ||
| case commitTransactionChan <- true: //good | ||
| case <-ctx.Done(): | ||
| assert.Fail(t, ctx.Err().Error()) | ||
| } | ||
| // Transaction will now attempt to commit. But we expect our "force_cutover" to have terminated | ||
| // the transaction's connection. | ||
| select { | ||
| case err := <-transactionErrorChan: | ||
| assert.ErrorContains(t, err, "broken pipe") | ||
| case <-ctx.Done(): | ||
| assert.Fail(t, ctx.Err().Error()) | ||
| } | ||
| }) | ||
| }) | ||
| } | ||
| t.Run("ALTER both tables non-concurrent", func(t *testing.T) { | ||
| t1uuid = testOnlineDDLStatement(t, createParams(trivialAlterT1Statement, ddlStrategy, "vtgate", "", "", true)) // skip wait | ||
| t2uuid = testOnlineDDLStatement(t, createParams(trivialAlterT2Statement, ddlStrategy, "vtgate", "", "", true)) // skip wait | ||
|
|
@@ -2400,3 +2529,31 @@ func getCreateTableStatement(t *testing.T, tablet *cluster.Vttablet, tableName s | |
| statement = queryResult.Rows[0][1].ToString() | ||
| return statement | ||
| } | ||
|
|
||
| func runInTransaction(t *testing.T, ctx context.Context, tablet *cluster.Vttablet, query string, commitTransactionChan chan any, transactionErrorChan chan error) error { | ||
| conn, err := tablet.VttabletProcess.TabletConn(keyspaceName, true) | ||
| require.NoError(t, err) | ||
| defer conn.Close() | ||
|
|
||
| _, err = conn.ExecuteFetch("begin", 0, false) | ||
| require.NoError(t, err) | ||
|
|
||
| _, err = conn.ExecuteFetch(query, 10000, false) | ||
| require.NoError(t, err) | ||
|
|
||
| if commitTransactionChan != nil { | ||
| // Wait for instruction to commit | ||
| select { | ||
| case <-commitTransactionChan: | ||
| // good | ||
| case <-ctx.Done(): | ||
| assert.Fail(t, ctx.Err().Error()) | ||
| } | ||
| } | ||
|
|
||
| _, err = conn.ExecuteFetch("commit", 0, false) | ||
| if transactionErrorChan != nil { | ||
| transactionErrorChan <- err | ||
| } | ||
| return err | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.