-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
schemadiff
: Online DDL support, declarative based
#16462
schemadiff
: Online DDL support, declarative based
#16462
Conversation
…ysis, remove redundant datatypes from onlineddl/vrepl Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
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
|
schemadiff
: Online DDL support, declarative based
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16462 +/- ##
==========================================
+ Coverage 68.62% 68.76% +0.13%
==========================================
Files 1552 1549 -3
Lines 199559 199624 +65
==========================================
+ Hits 136957 137264 +307
+ Misses 62602 62360 -242 ☔ View full report in Codecov by Sentry. |
m := make(map[int]string, len(c.ColumnDefinition.Type.EnumValues)) | ||
for i, enumValue := range c.ColumnDefinition.Type.EnumValues { | ||
// SET and ENUM values are 1 indexed. | ||
m[i+1] = enumValue |
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 doesn't seem symmetric with EnumValuesOrdinals
?
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.
Nice catch. Fixed EnumValuesOrdinals
, which is as yet unused.
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.
Added tests
@@ -445,6 +445,18 @@ type CreateTableEntity struct { | |||
Env *Environment | |||
} | |||
|
|||
func NewCreateTableEntityFromSQL(env *Environment, sql string) (*CreateTableEntity, error) { |
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 Do we want to have a symmetric function for views here?
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.
Added + testing.
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
go/vt/schemadiff/key.go
Outdated
|
||
// ColumnNames returns the names of the columns in the index. | ||
func (i *IndexDefinitionEntity) ColumnNames() []string { | ||
var names []string |
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.
We could preallocate this slice to a size equal to the length of i.IndexDefinition.Columns.
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.
fixed.
go/vt/schemadiff/onlineddl_test.go
Outdated
@@ -0,0 +1,960 @@ | |||
/* | |||
Copyright 2022 The Vitess Authors. |
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.
Should use 2024 here.
@@ -0,0 +1,590 @@ | |||
/* | |||
Copyright 2022 The Vitess Authors. |
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.
Should use 2024 here too.
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.
fixed.
go/vt/schemadiff/onlineddl.go
Outdated
// assumption that the later `targetColumn := targetColumns.GetColumn(expectedTargetName)` | ||
// check is sufficient. It is not. It is possible that a columns was explicitly dropped | ||
// and added (`DROP COLUMN c, ADD COLUMN c INT`) in the same ALTER TABLE statement. | ||
// Without checking the ALTER TABLE statement, we would be folled to believe that column |
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.
Assuming folled
should be fooled
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.
fixed.
@@ -4,3 +4,224 @@ | |||
*/ |
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.
Can we remove this copyright at this point?
Either way, we should also add the vitess copyright.
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.
Good catch. For this file the copyright should be just vitess. There is not derivative work from freno
here.
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.
fixed.
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Description
Addresses #16229 and more. Replaces #16256 just as a succinct single commit change.
In this PR
schemadiff
takes more ownership in the Online DDL process. Specifically, it takes away much of the logic fromvttablet/onlineddl/vrepl/*
andvttablet/onlineddl/vrepl.go
, but also:schemadiff
is purely declarative and does not use database connections, query based logic is replaced with programmatic logic.gh-ost
:Column
,ColumnList
,UniqueKey
and more. We already have the formal AST types ingo/vt/sqlparser
, and there was a lot of duplication of logic.regexp
based parsing, and more.Much of the logic removed as mentioned above is reincarnated in
go/vt/schemadiff/onlineddl.go
, where we introduce helper functions specific to Vitess's Online DDL implementations. Intentionally set apart from the general purposetable.go
orcolumn.go
, these functions deal with questions such as:To help formalizing some of the above, we introduce a few data types in
schemadiff
that assist in iteration, filtering, and generally inter-operate with each other to enrich column information:ColumnDefinitionEntity
(introduced in a previous PR) and many helper functions (is this column nullable? Is it numeric? What's the column's charset? etc.)ColumnDefinitionEntityList
- a list of the aboveColumnDefinitionEntity
IndexDefinitionEntity
and many helper functions (is this index unique? Does it have nullable columns? etc.)IndexDefinitionEntityList
- a list of the aboveIndexDefinitionEntity
These inter-connect, as mentioned above. For example, a column
i int
looks to be nullable, but if we know it's part of aPRIMARY
key, then we implicitly know it is in fact non nullable.What this means
This lets
schemadiff
pre-evaluate the ability to run Online DDL on a table, what risks there might be, what the revertibility implications might be, what keys will be used, and so forth, without actually having to read/write anything from/to the the database.Testing
Thanks to the declarative-only nature of
schemadiff
, it is easier to do more testing in unit tests. For example, we copy+pasted all the revertible tests fromgo/test/endtoend/onlineddl/revert/
and they are now tested in unit tests.There's otherwise a bunch of tests moved over from
go/vt/vttablet/onlineddl/vrepl
, almost as-is. And otherwise just a bunch more tests. Finally, all of the existingendtoend
tests, includingvrepl
suite, reverts, scheduler, and more -- all are unchanged and are expected to exhibit no change of behavior.Related Issue(s)
schemadiff
analysis #16229Checklist
Deployment Notes