-
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
Online DDL: evaluate REVERTibility of a migration #9232
Online DDL: evaluate REVERTibility of a migration #9232
Conversation
…s ewhen computing shared unique key or columns-covered unique key Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Examples of expanded data types, which we need to check for revertibility:
|
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…lt NULL? Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…ropped non-generated columns. Added unit test Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…rations 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>
It occurs to me that a user may change a column's type from anything to anything, really. e.g. |
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>
…changes, that may affect revertibility Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@@ -0,0 +1,161 @@ | |||
/* |
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 was refactored out of vrepl.go
without code changes
@@ -0,0 +1,192 @@ | |||
/* |
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 file was refactored out of vrepl.go
with changes as noted below.
} | ||
|
||
// GetSharedColumns returns the intersection of two lists of columns in same order as the first list | ||
func GetSharedColumns( |
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 function is unchanged, refactored out of vrepl.go
} | ||
|
||
// isExpandedColumn sees if target column has any value set/range that is impossible in source column. See GetExpandedColumns comment for examples | ||
func isExpandedColumn(sourceColumn *Column, targetColumn *Column) (bool, 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.
New functionality, and at the heart of this PR
// - BIGINT UNSIGNED -> INT SIGNED (negative values) | ||
// - TIMESTAMP -> TIMESTAMP(3) | ||
// etc. | ||
func GetExpandedColumnNames( |
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.
new functionality
} | ||
|
||
// GetNoDefaultColumnNames returns names of columns which have no default value, out of given list of columns | ||
func GetNoDefaultColumnNames(columns *ColumnList) (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.
new functionality. Though small, it's at the heart of this PR
alterSchemaMigrationsTableRemovedUniqueNames, | ||
alterSchemaMigrationsTableRemovedNoDefaultColNames, | ||
alterSchemaMigrationsTableExpandedColNames, | ||
alterSchemaMigrationsTableRevertibleNotes, |
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.
These new columns in schema_migrations
table help us to understand better the nature of the schema change, and in particular inform us what may be blockers/issues to reverting the migration.
alterSchemaMigrationsTableRemovedUniqueNames = "ALTER TABLE _vt.schema_migrations add column removed_unique_key_names text NOT NULL" | ||
alterSchemaMigrationsTableRemovedNoDefaultColNames = "ALTER TABLE _vt.schema_migrations add column dropped_no_default_column_names text NOT NULL" | ||
alterSchemaMigrationsTableExpandedColNames = "ALTER TABLE _vt.schema_migrations add column expanded_column_names text NOT NULL" | ||
alterSchemaMigrationsTableRevertibleNotes = "ALTER TABLE _vt.schema_migrations add column revertible_notes text NOT NULL" |
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.
These new columns in schema_migrations
table help us to understand better the nature of the schema change, and in particular inform us what may be blockers/issues to reverting the migration.
Ready for review! Notes notes for the reviewers:
|
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.
Very nicely written PR (as usual). The online DDL stuff blows my mind.
A few questions/clarification requests inline.
go/vt/schema/parser.go
Outdated
@@ -54,7 +54,7 @@ var ( | |||
createTableRegexp = regexp.MustCompile(`(?s)(?i)(CREATE\s+TABLE\s+)` + "`" + `([^` + "`" + `]+)` + "`" + `(\s*[(].*$)`) | |||
revertStatementRegexp = regexp.MustCompile(`(?i)^revert\s+([\S]*)$`) | |||
|
|||
enumValuesRegexp = regexp.MustCompile("(?i)^enum[(](.*)[)]$") | |||
enumValuesRegexp = regexp.MustCompile("(?i)^(enum|set)[(](.*)[)]$") |
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.
Does this change affect anything besides online DDL?
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.
Double checking.
go/vt/vttablet/onlineddl/executor.go
Outdated
if err := e.updateSchemaAnalysis(ctx, onlineDDL.UUID, | ||
len(v.addedUniqueKeys), | ||
len(v.removedUniqueKeys), | ||
strings.Join(removedUniqueKeyNames, ","), |
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.
Is it safe to concatenate like this? MySQL lets you use commas in column names.
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.
You are right -- but this is going to be informational only. That is, we're not going to then re-parse this. This is about us being able to tell the user "there is a chance we can't revert this migration due to these columns: a,b,c". So in a way, I consider this to be free text.
However, you're right and why no make the extra effort of qualifying the names. I'll proceed to do that.
Copyright 2016 GitHub Inc. | ||
See https://github.com/github/gh-ost/blob/master/LICENSE | ||
*/ | ||
|
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.
Has this been copied from gh-ost
with no changes?
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.
Right! It was copied from gh-ost
and there have been changes. I'll append the Vitess copyright.
return true // good to go! | ||
} | ||
|
||
// GetSharedUniqueKeys returns the unique keys shared between the two source&target tables |
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.
nit: it seems redundant to say "two source&target". Just "source and target"?
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>
Addressed all review comments:
|
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.
👍
Description
In this WIP PR we evaluate whether a migration is
REVERT
ible. A migration may, for example, possibly be irrevertible if:INT
toBIGINT
; what happens if a user INSERTs a value greater thanINT
on the new table? This value cannot be propagated back to the old table)NOT NULL
column with noDEFAULT
value, then INSERTing any row on the new table. How can we populate the dropped column on the old table?We cannot say for certain that a migration is not revertible. It depends on how the user uses the new table in the interim.
However, assuming we cover all the cases, we can predict that a migration is in fact revertible. If we see nothing to block revertibility, then we have high confidence that we will make it.
As a side note, most cases illustrated above are IMO unlikely. It's unlikely that immediately after cut-over the user will suddenly populate a BIGINT value: their app needs to first realize it can populate such values. But of course we can't say for sure. We cannot predict an app's behavior in the generic case.
Related Issue(s)
Followup to #8495
Tracking: #6926
Checklist
Deployment Notes