Online DDL plan via Send; "singleton" migrations on tablets#7785
Online DDL plan via Send; "singleton" migrations on tablets#7785shlomi-noach merged 77 commits intovitessio:masterfrom
Conversation
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…ne-ddl-send-plan-comments Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
- introducing DDLStrategySetting, formal wrapper for strategy+options - NewOnlineDDLs generates multiple OnlineDDL from a given statement, instead of parser generating multiple statements - OnlineDDL utilizes DDLStrategySetting; some logic moved out from OnlineDDL and into DDLStrategySetting Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…mal; also uses NewOnlineDDLs to break down queries Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…to clean up VT comments from query Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
… instead of writing them to topo. It utilizes new DDLStrategySetting, and uses samd TaretDestination as non-online DDL engine. Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…SQL string, but validates that it parses as a DDLStatement Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…eDDL now parses query and expects either DDLStatement or RevertMigration Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…rt statement on IsSkipTopo() Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…ntial quotes and spaces in text. OnlineDDLFromCommentedStatement() function reads a commented statement and reconstructs an OnlineDDL instance Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
systay
left a comment
There was a problem hiding this comment.
Looks good from what I can see. Mostly looked over parser, engine and both planners
go/vt/schema/ddl_strategy.go
Outdated
| @@ -0,0 +1,156 @@ | |||
| /* | |||
| Copyright 2019 The Vitess Authors. | |||
go/vt/schema/ddl_strategy_test.go
Outdated
| @@ -0,0 +1,109 @@ | |||
| /* | |||
| Copyright 2019 The Vitess Authors. | |||
go/vt/schema/online_ddl.go
Outdated
| } | ||
| } | ||
| return onlineDDLs, nil | ||
| case *sqlparser.CreateTable: |
There was a problem hiding this comment.
instead of adding a comment that this is done later, why not just do it in here straight away? just to keep the logic easier to follow
There was a problem hiding this comment.
I see what you mean, but there is code that is shard to all DropTable, CreateTable, AlterTable that is performed after the switch statement, when DropTable has, on top, special handling. I've clarified that in code comments.
There was a problem hiding this comment.
Refactored. It does look better now
go/vt/schema/online_ddl.go
Outdated
| case *sqlparser.AlterTable: | ||
| // handled later on | ||
| default: | ||
| return nil, fmt.Errorf("Unsupported statement for Online DDL: %v", sqlparser.String(ddlStmt)) |
There was a problem hiding this comment.
nit:vterrors is your friend. this applies to quite a few errors in this file.
also, I believe errors should not start with a capitalised letter
There was a problem hiding this comment.
Replaced all fmt.Errorf() in this file with vterrors, lower case as needed.
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Description
Two in one!
This PR introduces (WIP) "singleton migrations": a setting where you can't submit a new migration if any of the relevant shards still has any other pending migration (
queued,ready, running`).The use case resurfaced the question of the use of
topoin Online DDL. And I'm using the particular use case to begin the refactor away fromtopo.Elaborating on the refactor, first:
Online DDL is still the only mechanism that utilizes
topoas a mean to communicate fromVTGateorvtctltovttablets. There's advantages to going throughtopo(decoupling, persisted "request" entry, auto-retries), but there's also disadvantages: too decoupled, non-idiomatic path, added constraint onvtctldavailability.With the recent introduction of migration queries, #7663 , #7656 , I see a nice path out of
topoand into more fine-grained control over migrations.The changes offered here provide 1-version backwards compatibility, and for now require opting-in.
How will the new online DDL plan/engine flow work?
For some DDL queries (where the user intentionally opted-in), we create a
Sendengine primitive, just as we would for direct DDLs. We decorate the DDL query with online DDL hints. For example, assuming ourddl_strategyisonline, the query:is decorated as follows:
alter /*vt+ uuid="38ea1d8d_95da_11eb_b1fa_f875a4d24e90" context="vtctl:38be36cc-95da-11eb-b1fa-f875a4d24e90" strategy="online" options="" */ table corder engine innodband sent via
Send. The tablet planner (TODO) will intercept the query and realize there's online DDL hints, and that's how it will know that the query should run viaonlineddl.Executorrather than a direct commit on the backend database.About singleton migrations
To be implemented; the refactor came first. The user will use
-singletonstrategy flag, e.g.:or
The query will return with UUID if no other pending migration exists on relevant shards, and will atomically fail if there's at least one shard with a pending migration.
This is not implemented yet; I will implement this using a timeout-based mechanism, to avoid overly complex two-phase-commit logic. There may be some constraints on the user (e.g. if one migration is
-singletonthen all others must also be-singletonor else behavior is undefined).Notes to the reviewer
There's many files affected here, but most are just affected by the initial refactor (e.g. change of function signature). The main changes right now are:
go/vt/sqlparser: allCREATE,DROP,ALTERstatements now supportcomment_opt.CREATE TABLE,DROP TABLE,ALTER TABLE, butyaccdoesn't like it.DDLStatementnow hasSetComments()function which allows the us to inject comments into a statement.go/vt/schema:DDLStrategySetting, which is a formal representation of theddl_strategyvalue; some logic moved outside ofonline_ddl.goand intoddl_strategy.go.OnlineDDLinstance now uses saidDDLStrategySetting.NewOnlineDDLsfunction: refactorparser.gologic into a more formal breakdown of a ddl statementNewOnlineDDLfunction chooses whether to decorate the SQL query with/*vt+ ... */hintsgo/vt/vtgate:engine/online_ddl.go:OnlineDDLprimitive now chooses whether to write OnlineDDL request to topo, or to submit directly to tablets viaSendrevert_migration.goMost other changes (e.g.
schemamanager) are just by-product of the introduction ofDDLStrategySetting, and I'm happy to say the refactor formalized and I think simplified a bit, the logic in those places.Related Issue(s)
Checklist
Deployment Notes
Impacted Areas in Vitess
Components that this PR will affect: