-
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
Materializer: normalize schema via schemadiff on --atomic-copy #14636
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ import ( | |
"vitess.io/vitess/go/vt/key" | ||
"vitess.io/vitess/go/vt/log" | ||
"vitess.io/vitess/go/vt/mysqlctl/tmutils" | ||
"vitess.io/vitess/go/vt/schemadiff" | ||
"vitess.io/vitess/go/vt/sqlparser" | ||
"vitess.io/vitess/go/vt/topo" | ||
"vitess.io/vitess/go/vt/vtctl/schematools" | ||
|
@@ -444,7 +445,23 @@ func (mz *materializer) deploySchema() error { | |
} | ||
|
||
if len(applyDDLs) > 0 { | ||
if mz.ms.AtomicCopy { | ||
// AtomicCopy suggests we may be interested in Foreign Key support. As such, we want to | ||
// normalize the source schema: ensure the order of table definitions is compatible with | ||
// the constraints graph. We want to first create the parents, then the children. | ||
// We use schemadiff to normalize the schema. | ||
// For now, and because this is could have wider implications, we ignore any errors in | ||
// reading the source schema. | ||
schema, err := schemadiff.NewSchemaFromQueries(applyDDLs) | ||
if err != nil { | ||
log.Error(vterrors.Wrapf(err, "AtomicCopy: failed to normalize schema via schemadiff")) | ||
} else { | ||
applyDDLs = schema.ToQueries() | ||
log.Infof("AtomicCopy used, and schema was normalized via schemadiff. New queries: %v", applyDDLs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really want to always log this? As it can be a giant schema and thus a huge log entry? |
||
} | ||
} | ||
sql := strings.Join(applyDDLs, ";\n") | ||
log.Infof("materializer.deploySchema: sql=%v", sql) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, this can be very big and also would duplicate the logging. |
||
|
||
_, err = mz.tmc.ApplySchema(mz.ctx, targetTablet.Tablet, &tmutils.SchemaChange{ | ||
SQL: sql, | ||
|
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 change to the test ensures the new behavior is applied. The schema in the test is composed of
parent
andchild
tables. Sincechild < parent
lexicographically, the test fails without the new normalization.