Skip to content

onlineddl: ALTER VITESS_MIGRATION CANCEL CONTEXT 'ctx'#20146

Merged
shlomi-noach merged 8 commits into
vitessio:mainfrom
planetscale:onlineddl-cancel-migration-context
May 21, 2026
Merged

onlineddl: ALTER VITESS_MIGRATION CANCEL CONTEXT 'ctx'#20146
shlomi-noach merged 8 commits into
vitessio:mainfrom
planetscale:onlineddl-cancel-migration-context

Conversation

@shlomi-noach
Copy link
Copy Markdown
Contributor

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

  • CONTEXT is added as a non-reserved keyword so it doesn't break existing SQL using context as an identifier.
  • The parser produces a CancelAllMigrationType AlterMigration node with a new Context string field.
  • CancelPendingMigrations on the executor gains a migrationContext parameter; when non-empty it filters the pending list before cancelling.
  • rows_affected in the response equals the number of migrations actually cancelled (leveraging AppendResult semantics already used by CANCEL ALL).

Changes

  • go/vt/sqlparser/ — new CONTEXT keyword, grammar rule, AST field, format, equality, parse test
  • go/vt/vttablet/onlineddl/executor.goCancelPendingMigrations accepts migrationContext
  • go/vt/vttablet/tabletserver/query_executor.go — passes alterMigration.Context through
  • go/test/endtoend/onlineddl/CheckCancelContextMigrations helper + e2e test in scheduler suite

Example

ALTER VITESS_MIGRATION CANCEL CONTEXT 'my-context-123';

shlomi-noach and others added 2 commits May 20, 2026 10:30
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>
Copilot AI review requested due to automatic review settings May 20, 2026 07:42
@shlomi-noach shlomi-noach added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: Online DDL Online DDL (vitess/native/gh-ost/pt-osc) labels May 20, 2026
@github-actions github-actions Bot added this to the v25.0.0 milestone May 20, 2026
@vitess-bot vitess-bot Bot added NeedsWebsiteDocsUpdate What it says NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels May 20, 2026
@vitess-bot
Copy link
Copy Markdown
Contributor

vitess-bot Bot commented May 20, 2026

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@shlomi-noach shlomi-noach removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels May 20, 2026
@promptless
Copy link
Copy Markdown
Contributor

promptless Bot commented May 20, 2026

Promptless prepared a documentation update related to this change.

Triggered by vitessio/vitess#20146

Added documentation for the new ALTER VITESS_MIGRATION CANCEL CONTEXT 'context' SQL command in the Online DDL audit-and-control guide. The new section explains how users can cancel all pending migrations belonging to a specific migration context, which is useful when multiple deployment pipelines submit migrations concurrently.

Review: Document ALTER VITESS_MIGRATION CANCEL CONTEXT command

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_affected for 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

Comment thread go/vt/sqlparser/sql.y
Comment thread go/vt/vttablet/onlineddl/executor.go
Comment thread go/vt/sqlparser/ast_format.go
Comment thread go/vt/sqlparser/ast_format_fast.go
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

❌ Patch coverage is 38.46154% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.95%. Comparing base (70c7a72) to head (3b06ef4).
⚠️ Report is 266 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/sqlparser/ast_format.go 11.11% 8 Missing ⚠️
go/vt/vttablet/onlineddl/executor.go 50.00% 8 Missing ⚠️
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     
Flag Coverage Δ
partial 75.95% <38.46%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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>
@shlomi-noach
Copy link
Copy Markdown
Contributor Author

all of CoPilot's current comments are about the single same concern: the fall back of empty context into CANCEL ALL. This nehavior is intentional, now documented, and also exposed in the parser tests. This is fine. Not the place to be nitty-griitty.

CANCEL CONTEXT '' would be indistinguishable from CANCEL ALL

This is intentional and documented. migrationContext == "" is the sentinel for "cancel all" — an empty context string is not a supported filter value. We've added a doc comment to CancelPendingMigrations making this explicit, and the test suite includes a case that confirms CANCEL CONTEXT '' behaves identically to CANCEL ALL.

Introducing a distinct CancelContextMigrationType to handle the empty-string edge case would add complexity (new constant, new grammar rule, new executor branch, new formatter branch) to protect against a usage pattern we consider a user error. The test-as-documentation approach gives us the same safety net without the overhead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 20, 2026 09:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread go/vt/sqlparser/ast_format_fast.go Outdated
Comment thread go/test/endtoend/onlineddl/vtgate_util.go
shlomi-noach and others added 2 commits May 20, 2026 12:22
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>
Copilot AI review requested due to automatic review settings May 20, 2026 11:13
@shlomi-noach
Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Comment thread go/vt/sqlparser/ast_format.go Outdated
buf.astPrintf(node, " %#s", alterType)
if node.Threshold != "" {
buf.astPrintf(node, " '%#s'", node.Threshold)
buf.astPrintf(node, " %s", encodeSQLString(node.Threshold))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these remain as %#s to maintain casing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copilot AI review requested due to automatic review settings May 20, 2026 15:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

@mhamza15 mhamza15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Member

@mattlord mattlord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks, @shlomi-noach ! ❤️

@shlomi-noach shlomi-noach merged commit da94cc8 into vitessio:main May 21, 2026
121 of 123 checks passed
@shlomi-noach shlomi-noach deleted the onlineddl-cancel-migration-context branch May 21, 2026 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Online DDL Online DDL (vitess/native/gh-ost/pt-osc) Type: Enhancement Logical improvement (somewhere between a bug and feature)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Online DDL: ALTER VITESS_MIGRATION CANCEL CONTEXT 'migration_context'

4 participants