Skip to content
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

Closed

Conversation

dbussink
Copy link
Contributor

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

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

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>
Copy link
Contributor

vitess-bot bot commented Jan 11, 2024

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Jan 11, 2024
@github-actions github-actions bot added this to the v19.0.0 milestone Jan 11, 2024
@dbussink dbussink removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request labels Jan 11, 2024
@dbussink dbussink removed the NeedsBackportReason If backport labels have been applied to a PR, a justification is required label Jan 11, 2024
@dbussink dbussink force-pushed the schemadiff-charset-columns-table branch from 1886f57 to df1eb4e Compare January 11, 2024 12:27
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>
@dbussink dbussink force-pushed the schemadiff-charset-columns-table branch from df1eb4e to 5241c23 Compare January 11, 2024 13:08
Copy link

codecov bot commented Jan 11, 2024

Codecov Report

Attention: 32 lines in your changes are missing coverage. Please review.

Comparison is base (9df71e0) 47.26% compared to head (5241c23) 47.30%.
Report is 4 commits behind head on main.

Files Patch % Lines
go/vt/sidecardb/sidecardb.go 64.28% 8 Missing and 2 partials ⚠️
go/vt/schemadiff/table.go 86.48% 4 Missing and 1 partial ⚠️
go/vt/schemadiff/diff.go 87.50% 3 Missing ⚠️
go/vt/vtctl/grpcvtctldserver/server.go 40.00% 3 Missing ⚠️
go/vt/vttablet/onlineddl/executor.go 0.00% 3 Missing ⚠️
go/vt/vtctl/workflow/materializer.go 0.00% 2 Missing ⚠️
go/vt/wrangler/materializer.go 33.33% 2 Missing ⚠️
go/vt/vttablet/onlineddl/vrepl.go 0.00% 1 Missing ⚠️
go/vt/vttablet/tabletserver/schema/engine.go 0.00% 1 Missing ⚠️
go/vt/vttest/local_cluster.go 0.00% 1 Missing ⚠️
... and 1 more
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.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@shlomi-noach shlomi-noach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one! Looks like this formalizes a lot of code and brings some order.

Re: including #14930, I just thought of something I missed there. I'm gonna add a commit to #14930 which you can then cherry pick (or I can push to your repo).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

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,
}
}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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"
Copy link
Contributor

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))
Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

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?

Copy link
Contributor Author

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?

@shlomi-noach
Copy link
Contributor

This PR now merged into #14930

@shlomi-noach shlomi-noach marked this pull request as draft January 11, 2024 16:20
@shlomi-noach
Copy link
Contributor

Converted to Draft since we now have #14930 as the more updated version.

@dbussink dbussink closed this Jan 11, 2024
@dbussink dbussink deleted the schemadiff-charset-columns-table branch January 11, 2024 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants