-
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
Refactor schemadiff to inject environment #14934
Refactor schemadiff to inject environment #14934
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>
…eIgnoreAlways behavior 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>
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
|
1886f57
to
df1eb4e
Compare
We already had the parser that needed to be injected, but in order to properly handle MySQL 5.7 we also need to inject collations configuration. Instead of adding more arguments, we introduce the schemadiff environment struct and use that to inject the things like the current parser and current collation environment and default collation. Also need to refactor the rest that ends up using schemadiff to inject it similarly. The core goal here is that the sidecar can properly inject the right collation as well so we can unblock fixing the case sensitivity there. Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
df1eb4e
to
5241c23
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #14934 +/- ##
==========================================
+ Coverage 47.26% 47.30% +0.04%
==========================================
Files 1136 1137 +1
Lines 238484 238647 +163
==========================================
+ Hits 112721 112898 +177
+ Misses 117158 117134 -24
- Partials 8605 8615 +10 ☔ View full report in Codecov by Sentry. |
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.
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.
👍
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.
👍
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.
👍, copied from #14930
DefaultColl: defaultColl, | ||
Parser: parser, | ||
} | ||
} |
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.
I predict it might be useful: let's add a NewMySQL8Env()
function that uses utf8mb4
and possibly also creates a MySQL8 compliant parser.
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 I'm hesitant actually about that and I like that this is explicit and the caller is required to pass these in. We also explicitly name the default one as a test specific one.
The main reason for this is also slightly less collations, but also the parser since the parser has MySQL specific version behavior, so you almost always want to pass in a specific version parser from the context you're in.
So I very much prefer not to add this and see that if we seem to have a need, to look at that and do the proper thing at that point.
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.
👍
showCreateTableQuery = "show create table %s.%s" | ||
sidecarDBExistsQuery = "select 'true' as 'dbexists' from information_schema.SCHEMATA where SCHEMA_NAME = %a" | ||
showCreateTableQuery = "show create table %s.%s" | ||
sidecarCollationQuery = "select @@global.collation_server" |
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.
👍
return si.collEnv.LookupByName(rs.Rows[0][0].ToString()), nil | ||
default: | ||
// This should never happen. | ||
return collations.Unknown, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "invalid results for SidecarDB query %q as it produced %d rows", sidecarCollationQuery, len(rs.Rows)) |
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.
👍
return collations.Unknown, err | ||
} | ||
|
||
switch len(rs.Rows) { |
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.
I know this is a copy+paste from elsewhere, because I recognize the pattern. I think at some later stage we should cleanup this kind of code. A select @@global.collation_server
will either fail, or return exactly one row. There is no need to check in the code what happens if less or more different rows are returned. It's only confusing and adding error prone logic.
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 It actually helped me here since with the fake db I had to add stuff since things were missing since no mock queries were set up. So it help uncover that in an easier way than random panics.
@@ -375,7 +400,8 @@ func (si *schemaInit) findTableSchemaDiff(tableName, current, desired string) (s | |||
TableCharsetCollateStrategy: schemadiff.TableCharsetCollateIgnoreAlways, | |||
AlterTableAlgorithmStrategy: schemadiff.AlterTableAlgorithmStrategyCopy, | |||
} | |||
diff, err := schemadiff.DiffCreateTablesQueries(current, desired, hints, si.parser) | |||
env := schemadiff.NewEnv(si.collEnv, si.coll, si.parser) |
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.
👍
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 we also add a 5.7
-collation test? Will it be beneficial?
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 schemadiff
has one for 5.7 and implicit the sidecar is already tested on 5.7 (see the failures in #14930), so I think we're covered here?
This PR now merged into #14930 |
Converted to |
We already had the parser that needed to be injected, but in order to properly handle MySQL 5.7 we also need to inject collations configuration. Instead of adding more arguments, we introduce the schemadiff environment struct and use that to inject the things like the current parser and current collation environment and default collation.
Also need to refactor the rest that ends up using schemadiff to inject it similarly.
The core goal here is that the sidecar can properly inject the right collation as well so we can unblock fixing the case sensitivity there.
Also includes the changes in #14930
Related Issue(s)
Fixes #14929
Checklist