onlineddl: ALTER VITESS_MIGRATION CANCEL CONTEXT 'ctx'#20146
Conversation
Introduces `ALTER VITESS_MIGRATION CANCEL CONTEXT 'ctx'` syntax to cancel all pending migrations belonging to a given migration context, without affecting migrations from other contexts. Complements the existing CANCEL ALL. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
The test was accidentally placed inside testSingleton where t1uuid, t2uuid, trivialAlterT1Statement, and ddlStrategy are out of scope. Moved it to the end of testScheduler where those variables are declared. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
|
Promptless prepared a documentation update related to this change. Triggered by vitessio/vitess#20146 Added documentation for the new Review: Document ALTER VITESS_MIGRATION CANCEL CONTEXT command |
There was a problem hiding this comment.
Pull request overview
Adds support for cancelling Online DDL migrations by migration_context via a new SQL statement: ALTER VITESS_MIGRATION CANCEL CONTEXT '…', wiring it through the sqlparser AST and the onlineddl executor, and adding end-to-end coverage.
Changes:
- Extend sqlparser (keyword/grammar/AST/format/equality/tests) to parse and print
ALTER VITESS_MIGRATION CANCEL CONTEXT 'migration_context'. - Update OnlineDDL executor cancellation path to optionally filter pending migrations by context and return
rows_affectedfor actual cancellations. - Add e2e helper + scheduler test coverage for cancel-by-context behavior.
Reviewed changes
Copilot reviewed 9 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| go/vt/vttablet/tabletserver/query_executor.go | Passes parsed migration context through to the OnlineDDL executor cancellation method. |
| go/vt/vttablet/onlineddl/executor.go | Adds context-filtering behavior to cancelling pending migrations. |
| go/vt/sqlparser/sql.y | Adds CONTEXT token/grammar rule for ALTER VITESS_MIGRATION CANCEL CONTEXT. |
| go/vt/sqlparser/parse_test.go | Adds parser coverage for the new statement. |
| go/vt/sqlparser/keywords.go | Registers context as a keyword token. |
| go/vt/sqlparser/cached_size.go | Updates cached-size accounting for new AST field. |
| go/vt/sqlparser/ast.go | Adds Context field to AlterMigration AST node. |
| go/vt/sqlparser/ast_format.go | Prints cancel context '…' when context is present. |
| go/vt/sqlparser/ast_format_fast.go | Fast formatter support for the new context clause. |
| go/vt/sqlparser/ast_equals.go | Includes Context in AST equality comparisons. |
| go/test/endtoend/onlineddl/vtgate_util.go | Adds helper to run cancel-by-context statement and assert affected rows. |
| go/test/endtoend/onlineddl/scheduler/onlineddl_scheduler_test.go | Adds scheduler e2e test ensuring only matching-context migrations are cancelled. |
Files not reviewed (3)
- go/vt/sqlparser/ast_equals.go: Language not supported
- go/vt/sqlparser/ast_format_fast.go: Language not supported
- go/vt/sqlparser/cached_size.go: Language not supported
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #20146 +/- ##
===========================================
+ Coverage 69.67% 75.95% +6.28%
===========================================
Files 1614 589 -1025
Lines 216793 110233 -106560
===========================================
- Hits 151044 83726 -67318
+ Misses 65749 26507 -39242
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Empty migrationContext is not a supported filter value; it falls through to the cancel-all path by design. The test suite confirms this. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
|
all of CoPilot's current comments are about the single same concern: the fall back of empty context into
This is intentional and documented. Introducing a distinct |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 13 changed files in this pull request and generated 2 comments.
Files not reviewed (3)
- go/vt/sqlparser/ast_equals.go: Language not supported
- go/vt/sqlparser/ast_format_fast.go: Language not supported
- go/vt/sqlparser/cached_size.go: Language not supported
Threshold, Expire, Context, and Shards were written raw between single quotes, so values containing a single quote would produce invalid SQL. Use encodeSQLString (backed by sqltypes.EncodeStringSQL) for all four fields, matching the pattern used for other string literals in the formatter. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
CANCEL CONTEXT '' previously silently fell through to cancel-all behavior. Reject it at parse time via yylex.Error so clients that accidentally pass an empty context (e.g. an unset variable) get a clear error instead of unexpectedly affecting all migrations. Updated the parse test to expect a parse error, and simplified the CancelPendingMigrations doc comment now that the empty-context edge case is unreachable via the parser. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
|
OK OK copilot was right and I give up. Empty context is now rejected by the parser. I like this idea better than my original approach. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 13 changed files in this pull request and generated no new comments.
Files not reviewed (3)
- go/vt/sqlparser/ast_equals.go: Language not supported
- go/vt/sqlparser/ast_format_fast.go: Language not supported
- go/vt/sqlparser/cached_size.go: Language not supported
…ect error string yylex.Error alone does not abort parsing in goyacc; return 1 is required to make yyParse return non-zero. Also update the invalidSQL test entry to match the actual error format which includes position info. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
| buf.astPrintf(node, " %#s", alterType) | ||
| if node.Threshold != "" { | ||
| buf.astPrintf(node, " '%#s'", node.Threshold) | ||
| buf.astPrintf(node, " %s", encodeSQLString(node.Threshold)) |
There was a problem hiding this comment.
Should these remain as %#s to maintain casing?
There was a problem hiding this comment.
In my understanding the # directive is only applicable to keyword/identifier nodes. It will be completely harmless to change to %#s and I'm happy to do that -- at the same time it will be ineffective and possibly misleading since there is no keyword/identifier involved. I have absolutely zero preferences. What would make more sense in your opinion?
There was a problem hiding this comment.
It does seem to apply to literals as well, here's an example unit test: 300c07d
❯ go test ./go/vt/sqlparser -run TestCanonicalOutput/alter_vitess_migration_cancel_context -count 1
--- FAIL: TestCanonicalOutput (0.00s)
--- FAIL: TestCanonicalOutput/alter_vitess_migration_cancel_context_'ProdCtx' (0.00s)
tracked_buffer_test.go:292:
Error Trace: /Users/mhamza/.local/share/forest/worktrees/vitess/planetscale-onlineddl-cancel-migration-context/go/vt/sqlparser/tracked_buffer_test.go:292
Error: Not equal:
expected: "ALTER VITESS_MIGRATION cancel CONTEXT 'ProdCtx'"
actual : "ALTER VITESS_MIGRATION cancel CONTEXT 'PRODCTX'"
Diff:
--- Expected
+++ Actual
@@ -1 +1 @@
-ALTER VITESS_MIGRATION cancel CONTEXT 'ProdCtx'
+ALTER VITESS_MIGRATION cancel CONTEXT 'PRODCTX'
Test: TestCanonicalOutput/alter_vitess_migration_cancel_context_'ProdCtx'
Messages: bad serialization
FAIL
FAIL vitess.io/vitess/go/vt/sqlparser 0.394s
FAIL
There was a problem hiding this comment.
Done and pushed! Interestingly ast_format_fast.go was unaffected by the change.
…g fields Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 13 changed files in this pull request and generated no new comments.
Files not reviewed (3)
- go/vt/sqlparser/ast_equals.go: Language not supported
- go/vt/sqlparser/ast_format_fast.go: Language not supported
- go/vt/sqlparser/cached_size.go: Language not supported
mattlord
left a comment
There was a problem hiding this comment.
LGTM. Thanks, @shlomi-noach ! ❤️
Closes #20145
Adds
ALTER VITESS_MIGRATION CANCEL CONTEXT 'migration_context'— a new SQL statement that cancels all pending migrations belonging to a specific migration context, leaving migrations in other contexts untouched.Follow-up to #20027 and #19995.
How it works
CONTEXTis added as a non-reserved keyword so it doesn't break existing SQL usingcontextas an identifier.CancelAllMigrationTypeAlterMigrationnode with a newContext stringfield.CancelPendingMigrationson the executor gains amigrationContextparameter; when non-empty it filters the pending list before cancelling.rows_affectedin the response equals the number of migrations actually cancelled (leveragingAppendResultsemantics already used byCANCEL ALL).Changes
go/vt/sqlparser/— newCONTEXTkeyword, grammar rule, AST field, format, equality, parse testgo/vt/vttablet/onlineddl/executor.go—CancelPendingMigrationsacceptsmigrationContextgo/vt/vttablet/tabletserver/query_executor.go— passesalterMigration.Contextthroughgo/test/endtoend/onlineddl/—CheckCancelContextMigrationshelper + e2e test in scheduler suiteExample
ALTER VITESS_MIGRATION CANCEL CONTEXT 'my-context-123';