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

VReplication: Fixes for generated column handling #17107

Merged
merged 6 commits into from
Nov 1, 2024

Conversation

mattlord
Copy link
Contributor

@mattlord mattlord commented Oct 29, 2024

Description

We were using the lowercase column name when building the map of columns to ignore in the copy phase — where we copy the filtered rows from a SELECT statement on the source — but then using the case we got back from MySQL when checking the map. h/t to @aluque01 for doing all of the hard work around this in the issue.

Without the code fix, the tests such as TestBasicV2Workflows fail with:

=== NAME  TestBasicV2Workflows
    resharding_workflows_v2_test.go:175: Executing workflow command: vtctldclient MoveTables --workflow wf1 --target-keyspace customer Create --source-keyspace product --tables customer,loadtest,vdiff_order,reftable,_vt_PURGE_4f9194b43b2011eb8a0104ed332e05c2_20221210194431 --defer-secondary-keys --cells zone1 --action_timeout=10m
    helper_test.go:409:
        	Error Trace:	/Users/matt/git/vitess/go/test/endtoend/vreplication/helper_test.go:409
        	            				/Users/matt/git/vitess/go/test/endtoend/vreplication/resharding_workflows_v2_test.go:103
        	            				/Users/matt/git/vitess/go/test/endtoend/vreplication/resharding_workflows_v2_test.go:684
        	            				/Users/matt/git/vitess/go/test/endtoend/vreplication/resharding_workflows_v2_test.go:449
        	Error:      	workflow state not reached
        	Test:       	TestBasicV2Workflows
        	Messages:   	Workflow "customer.wf1" did not fully reach the expected state of "Running" before the timeout of 1m30s; last seen output: {
        	            		"Workflow": "wf1",
  ...
        	            						"State": "Error",
        	            						"DBName": "vt_customer",
        	            						"TransactionTimestamp": 0,
        	            						"TimeUpdated": 1730224772,
        	            						"TimeHeartbeat": 0,
        	            						"TimeThrottled": 0,
        	            						"ComponentThrottled": "",
        	            						"Message": "terminal error: task error: failed inserting rows: Column 'typ' cannot be null (errno 1048) (sqlstate 23000) during query: insert into customer(cid,`name`,meta,typ,sport,ts,bits,date1,date2,dec80,blb) values (2,_binary'Paül',JSON_OBJECT(),null,'soho','cricket','2024-10-29 17:59:13',b'00000011','0000-00-00 00:00:00','2021-00-01 00:00:00',null)",

The test changes added for that issue, then highlighted another issue with how we handled generated columns. Specifically when using the binlog_row_image=noblob MySQL setting (we added experimental support for that in #12905). The problem was that we were removing the generated column from the table's list of columns entirely in the replication plan. This then threw off the indexes used in the bitmap contained in the non-FULL binlog images which denote which columns/fields have data in the event. Without the code fixes for this issue, the tests such as TestCellAliasVreplicationWorkflow which use binlog_row_image=noblob would fail when doing the vdiff after sharding tables in the product keyspace (examples here):

2024-10-29T19:20:47.7378764Z 				"MismatchedRowsSample": [
2024-10-29T19:20:47.7379162Z 					{
2024-10-29T19:20:47.7379549Z 						"Source": {
2024-10-29T19:20:47.7379917Z 							"Row": {
2024-10-29T19:20:47.7380352Z 								"`name`": "ringo",
2024-10-29T19:20:47.7380776Z 								"bits": "\u0003",
2024-10-29T19:20:47.7381197Z 								"blb": "blob data",
2024-10-29T19:20:47.7381594Z 								"cid": "999999",
2024-10-29T19:20:47.7382139Z 								"date1": "0000-00-00 00:00:00",
2024-10-29T19:20:47.7382654Z 								"date2": "2021-00-01 00:00:00",
2024-10-29T19:20:47.7383043Z 								"dec80": "0",
2024-10-29T19:20:47.7383562Z 								"industryCategory": "\"Music\"",
2024-10-29T19:20:47.7384076Z 								"meta": "{\"industry\": \"Music\"}",
2024-10-29T19:20:47.7384539Z 								"sport": "",
2024-10-29T19:20:47.7385059Z 								"ts": "2024-10-29 19:04:26",
2024-10-29T19:20:47.7385536Z 								"typ": "enterprise"
2024-10-29T19:20:47.7385914Z 							}
2024-10-29T19:20:47.7386301Z 						},
2024-10-29T19:20:47.7386622Z 						"Target": {
2024-10-29T19:20:47.7387047Z 							"Row": {
2024-10-29T19:20:47.7387543Z 								"`name`": "ringo",
2024-10-29T19:20:47.7387948Z 								"bits": "\u0003",
2024-10-29T19:20:47.7388406Z 								"blb": "",
2024-10-29T19:20:47.7388783Z 								"cid": "999999",
2024-10-29T19:20:47.7389263Z 								"date1": "0000-00-00 00:00:00",
2024-10-29T19:20:47.7389793Z 								"date2": "2021-00-01 00:00:00",
2024-10-29T19:20:47.7390299Z 								"dec80": "0",
2024-10-29T19:20:47.7390750Z 								"industryCategory": "\"Music\"",
2024-10-29T19:20:47.7391317Z 								"meta": "{\"industry\": \"Music\"}",
2024-10-29T19:20:47.7391916Z 								"sport": "",
2024-10-29T19:20:47.7392330Z 								"ts": "2024-10-29 19:04:26",
2024-10-29T19:20:47.7392845Z 								"typ": "enterprise"
2024-10-29T19:20:47.7393229Z 							}
2024-10-29T19:20:47.7393530Z 						}
2024-10-29T19:20:47.7393853Z 					}
2024-10-29T19:20:47.7394156Z 				]
2024-10-29T19:20:47.7394438Z 			}

This was because, in this specific case, we incorrectly thought that the binlog event that was generated here where only the dec0 column was updated in all existing rows, thus resulting in MySQL eliding the blb blob column from the ROW images in the binlog event (as it did not change), but VReplication incorrectly thinking it was there and thus assigning a NULL value (there was in fact no value in the event for it) to it in the resulting UPDATE statement generated.

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

We were using the lowercase column name when building the list
of columns to ignore but then using the case we got back from
MySQL when checking the list.

Signed-off-by: Matt Lord <[email protected]>
@mattlord mattlord added Type: Bug Component: VReplication Backport to: release-18.0 Needs to be back ported to release-18.0 Backport to: release-19.0 Needs to be back ported to release-19.0 Backport to: release-20.0 Needs to be backport to release-20.0 Backport to: release-21.0 Needs to be backport to release-21.0 labels Oct 29, 2024
Copy link
Contributor

vitess-bot bot commented Oct 29, 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 Oct 29, 2024
@mattlord mattlord 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 NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Oct 29, 2024
@github-actions github-actions bot added this to the v22.0.0 milestone Oct 29, 2024
Copy link

codecov bot commented Oct 29, 2024

Codecov Report

Attention: Patch coverage is 73.33333% with 4 lines in your changes missing coverage. Please review.

Project coverage is 67.18%. Comparing base (4550640) to head (153545b).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
...t/tabletmanager/vreplication/table_plan_partial.go 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17107      +/-   ##
==========================================
+ Coverage   67.15%   67.18%   +0.03%     
==========================================
  Files        1571     1571              
  Lines      252250   252236      -14     
==========================================
+ Hits       169409   169477      +68     
+ Misses      82841    82759      -82     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mattlord mattlord changed the title VReplication: Fix mixed case generated column handling VReplication: Fixes for generated column handling Oct 30, 2024
@mattlord mattlord removed Backport to: release-18.0 Needs to be back ported to release-18.0 Backport to: release-19.0 Needs to be back ported to release-19.0 Backport to: release-20.0 Needs to be backport to release-20.0 Backport to: release-21.0 Needs to be backport to release-21.0 labels Oct 30, 2024
Comment on lines +596 to +599
resetCompression := mainClusterConfig.enableGTIDCompression()
defer resetCompression()
resetExperimentalFlags := setAllVTTabletExperimentalFlags()
defer resetExperimentalFlags()
Copy link
Contributor Author

@mattlord mattlord Oct 30, 2024

Choose a reason for hiding this comment

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

This is unrelated to the PR issues, but I noticed that it was incorrect as I walked through this test.

@mattlord mattlord marked this pull request as ready for review October 30, 2024 15:46
Signed-off-by: Matt Lord <[email protected]>
Copy link
Contributor

@rohit-nayak-ps rohit-nayak-ps left a comment

Choose a reason for hiding this comment

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

Good catch. Nice updates to the test framework!

@@ -142,6 +142,11 @@ type TestQuery struct {
type TestRowChange struct {
before []string
after []string

// If you need to customize the image you can use the raw types.
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

@aluque01
Copy link

Awesome, thanks for implementing this!

@mattlord mattlord merged commit fdf529e into vitessio:main Nov 1, 2024
98 checks passed
@mattlord mattlord deleted the vstream_gen_cols branch November 1, 2024 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants