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

[18.x] Fix schemacopy collation issues #15859

Merged

Conversation

arthurschreiber
Copy link
Contributor

@arthurschreiber arthurschreiber commented May 7, 2024

Description

This fixes a collation error caused by a query run during health check in vttablet.

The same issue exists in v17.x, so a backport is required once this has been merged to v18.x.

Related Issue(s)

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

Deployment Notes

Copy link
Contributor

vitess-bot bot commented May 7, 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 May 7, 2024
@github-actions github-actions bot added this to the v18.0.5 milestone May 7, 2024
@arthurschreiber arthurschreiber force-pushed the arthur/fix-schemacopy-collation-issues branch 2 times, most recently from c3acb5d to f3895d1 Compare May 7, 2024 12:05
@arthurschreiber arthurschreiber added Backport to: release-17.0 and removed NeedsIssue A linked issue is missing for this Pull Request labels May 7, 2024
@arthurschreiber arthurschreiber force-pushed the arthur/fix-schemacopy-collation-issues branch 3 times, most recently from 2a28040 to 7f47760 Compare May 7, 2024 15:42
Signed-off-by: Arthur Schreiber <arthurschreiber@github.com>
@arthurschreiber arthurschreiber force-pushed the arthur/fix-schemacopy-collation-issues branch from 7f47760 to cfb8e60 Compare May 7, 2024 17:38
@arthurschreiber
Copy link
Contributor Author

@shlomi-noach Do you know what's going on here? Based on the log files when running some of the failing end-to-end tests, it looks like when the table is created with the collation information, each subsequent PlannedReparentShard operation / primary tablet restart will re-run an ALTER TABLE statement like this:

I0507 19:12:48.661431   15423 sidecardb.go:383] No changes needed for table tables
I0507 19:12:48.661433   15423 sidecardb.go:436] Table schema was already up to date for the tables table in the __vt_e2e-test sidecar database
I0507 19:12:48.662026   15423 sidecardb.go:383] No changes needed for table views
I0507 19:12:48.662041   15423 sidecardb.go:436] Table schema was already up to date for the views table in the __vt_e2e-test sidecar database
I0507 19:12:48.662463   15423 sidecardb.go:385] Applying DDL for table schemacopy:
ALTER TABLE `schemacopy` MODIFY COLUMN `table_schema` varchar(64) COLLATE utf8mb3_bin NOT NULL, MODIFY COLUMN `table_name` varchar(64) COLLATE utf8mb3_bin NOT NULL, MODIFY COLUMN `column_name` varchar(64) COLLATE utf8mb3_general_ci NOT NULL, MODIFY COLUMN `character_set_name` varchar(32) COLLATE utf8mb3_general_ci, MODIFY COLUMN `collation_name` varchar(32) COLLATE utf8mb3_general_ci, MODIFY COLUMN `data_type` varchar(64) COLLATE utf8mb3_bin NOT NULL, MODIFY COLUMN `column_key` varchar(3) COLLATE utf8mb3_bin NOT NULL, ALGORITHM = COPY
I0507 19:12:48.663843   15423 sidecardb.go:330] createSidecarDB: __vt_e2e-test
I0507 19:12:48.723271   15423 sidecardb.go:432] Applied DDL ALTER TABLE `schemacopy` MODIFY COLUMN `table_schema` varchar(64) COLLATE utf8mb3_bin NOT NULL, MODIFY COLUMN `table_name` varchar(64) COLLATE utf8mb3_bin NOT NULL, MODIFY COLUMN `column_name` varchar(64) COLLATE utf8mb3_general_ci NOT NULL, MODIFY COLUMN `character_set_name` varchar(32) COLLATE utf8mb3_general_ci, MODIFY COLUMN `collation_name` varchar(32) COLLATE utf8mb3_general_ci, MODIFY COLUMN `data_type` varchar(64) COLLATE utf8mb3_bin NOT NULL, MODIFY COLUMN `column_key` varchar(3) COLLATE utf8mb3_bin NOT NULL, ALGORITHM = COPY for table `__vt_e2e-test`.schemacopy (schematracker) during sidecar database initialization
I0507 19:12:48.723982   15423 sidecardb.go:383] No changes needed for table dt_participant
I0507 19:12:48.723997   15423 sidecardb.go:436] Table schema was already up to date for the dt_participant table in the __vt_e2e-test sidecar database

Does the sidecardb initialization not handle the collation information correctly? 🤔

@arthurschreiber
Copy link
Contributor Author

Also, it doesn't matter whether I use the old or new collation names (utf8mb3_* vs utf8_*). 😞

@arthurschreiber
Copy link
Contributor Author

Ugh, I think I might have figured this out. Is this a bug in the schemadiff code?

It looks like creating a column with just a COLLATE utf8mb3_general_ci collation setting (without the CHARACTER SET part), SHOW CREATE TABLE ... will return the CHARACTER SET option in the returned DDL statement.

And I guess the schema diff code then sees that as a change that was made (without any actual change) and runs the ALTER TABLE when a tablet is restarted / promoted to primary. 😞

Signed-off-by: Arthur Schreiber <arthurschreiber@github.com>
@arthurschreiber
Copy link
Contributor Author

Here's a test case that is currently failing:

diff --git a/go/vt/schemadiff/schema_diff_test.go b/go/vt/schemadiff/schema_diff_test.go
index f6477c1885..d7cf8a9258 100644
--- a/go/vt/schemadiff/schema_diff_test.go
+++ b/go/vt/schemadiff/schema_diff_test.go
@@ -663,6 +663,15 @@ func TestSchemaDiff(t *testing.T) {
                        expectDeps:  0,
                        entityOrder: []string{"t1"},
                },
+               {
+                       name: "two identical tables, one with explicit charset, one without",
+                       fromQueries: []string{
+                               "create table foobar (id int primary key, foo varchar(64) character set utf8mb3 collate utf8mb3_bin)",
+                       },
+                       toQueries: []string{
+                               "create table foobar (id int primary key, foo varchar(64) collate utf8mb3_bin)",
+                       },
+               },
        }
        hints := &DiffHints{RangeRotationStrategy: RangeRotationDistinctStatements}
        for _, tc := range tt {

@shlomi-noach
Copy link
Contributor

@arthurschreiber thank you for producing a test case! Looking into it.

@shlomi-noach
Copy link
Contributor

From what I can see, schemadiff knows how to strip out the charset, but only when the collation is the default for said charset. I'm now looking to remove the charset even if the collation is not said default.

This was referenced Apr 30, 2024
@shlomi-noach
Copy link
Contributor

This is weird, because the following test passes in TestCreateTableDiff:

		{
			name: "ignore identical implicit charset",
			from: "create table t (id int primary key, v varchar(64) character set utf8mb3 collate utf8mb3_bin)",
			to:   "create table t (id int primary key, v varchar(64) collate utf8mb3_bin)",
		},

@shlomi-noach
Copy link
Contributor

OK, I completely missed that the issue is with 18. The problem is solved in 19. Let me see how to solve it in 18 as the changes in v19 are not backportable.

@shlomi-noach
Copy link
Contributor

v18 specific fix in #15873

Not sure how backportable this will be to v17, we'll have to see.

@shlomi-noach shlomi-noach modified the milestones: v18.0.5, v18.0.6 May 8, 2024
Signed-off-by: Arthur Schreiber <arthurschreiber@github.com>
@shlomi-noach shlomi-noach removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants