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: Add VTGate VStreamFlag to include journal events in the stream #16737

Merged
merged 3 commits into from
Sep 17, 2024

Conversation

mattlord
Copy link
Contributor

@mattlord mattlord commented Sep 10, 2024

Description

Previously reshard journal events were only sent in the event stream if the StopOnReshard option was set for the VTGate VStream RPC. This was required because you needed the journal event in order to pick back up on the new shards later on.

However, there are use cases for including the reshard journal events even when StopOnReshard is not set and thus not strictly necessary. Please see the issue #16644 for a great explanation of such a use case for the Debezium connector for Vitess.

This PR adds a new IncludeReshardJournalEvents VStreamFlag which supports this optional behavior.

Manual test on the PR branch:

diff --git a/examples/local/vstream_client.go b/examples/local/vstream_client.go
index ab00f83871..dd6c82abc5 100644
--- a/examples/local/vstream_client.go
+++ b/examples/local/vstream_client.go
@@ -44,14 +44,10 @@ func main() {
                vgtid = &binlogdatapb.VGtid{
                        ShardGtids: []*binlogdatapb.ShardGtid{{
                                Keyspace: "customer",
-                               Shard:    "-80",
+                               Shard:    "0",
                                // Gtid "" is to stream from the start, "current" is to stream from the current gtid
                                // you can also specify a gtid to start with.
                                Gtid: "", //"current"  // "MySQL56/36a89abd-978f-11eb-b312-04ed332e05c2:1-265"
-                       }, {
-                               Keyspace: "customer",
-                               Shard:    "80-",
-                               Gtid:     "",
                        }}}
        } else {
                vgtid = &binlogdatapb.VGtid{
@@ -76,7 +72,7 @@ func main() {
                // MinimizeSkew:      false,
                // HeartbeatInterval: 60, //seconds
                // StopOnReshard: true,
-               // IncludeReshardJournalEvents: true,
+               IncludeReshardJournalEvents: true,
        }
        reader, err := conn.VStream(ctx, topodatapb.TabletType_PRIMARY, vgtid, filter, flags)
        if err != nil {
cd examples/local

./101_initial_cluster.sh; mysql < ../common/insert_commerce_data.sql; ./201_customer_tablets.sh; ./202_move_tables.sh; ./203_switch_reads.sh; ./204_switch_writes.sh; ./205_clean_commerce.sh; ./301_customer_sharded.sh; ./302_new_shards.sh

# In another terminal window
go run vstream_client.go

./303_reshard.sh; ./304_switch_reads.sh; ./305_switch_writes.sh; ./306_down_shard_0.sh; ./307_delete_shard_0.sh

mysql customer -e "insert into customer values (10, 'mlord@planetscale.com')"

Test output:

❯ go run vstream_client.go
[type:BEGIN keyspace:"customer" shard:"0" type:FIELD field_event:{table_name:"customer.customer" fields:{name:"customer_id" type:INT64 table:"customer" org_table:"customer" database:"vt_customer" org_name:"customer_id" column_length:20 charset:63 flags:53251 column_type:"bigint"} fields:{name:"email" type:VARBINARY table:"customer" org_table:"customer" database:"vt_customer" org_name:"email" column_length:128 charset:63 flags:128 column_type:"varbinary(128)"} keyspace:"customer" shard:"0" enum_set_string_values:true} keyspace:"customer" shard:"0"]
[type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/813f4cc6-6f8a-11ef-8623-c6596802cd02:1-58"}} keyspace:"customer" shard:"0"]
[type:ROW row_event:{table_name:"customer.customer" row_changes:{after:{lengths:1 lengths:16 values:"1alice@domain.com"}} keyspace:"customer" shard:"0"} keyspace:"customer" shard:"0" type:ROW row_event:{table_name:"customer.customer" row_changes:{after:{lengths:1 lengths:14 values:"2bob@domain.com"}} keyspace:"customer" shard:"0"} keyspace:"customer" shard:"0" type:ROW row_event:{table_name:"customer.customer" row_changes:{after:{lengths:1 lengths:18 values:"3charlie@domain.com"}} keyspace:"customer" shard:"0"} keyspace:"customer" shard:"0" type:ROW row_event:{table_name:"customer.customer" row_changes:{after:{lengths:1 lengths:14 values:"4dan@domain.com"}} keyspace:"customer" shard:"0"} keyspace:"customer" shard:"0" type:ROW row_event:{table_name:"customer.customer" row_changes:{after:{lengths:1 lengths:14 values:"5eve@domain.com"}} keyspace:"customer" shard:"0"} keyspace:"customer" shard:"0" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/813f4cc6-6f8a-11ef-8623-c6596802cd02:1-58" table_p_ks:{table_name:"customer" lastpk:{fields:{name:"customer_id" type:INT64 charset:63 flags:53251} rows:{lengths:1 values:"5"}}}}} keyspace:"customer" shard:"0" type:COMMIT keyspace:"customer" shard:"0"]
[type:BEGIN keyspace:"customer" shard:"0" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/813f4cc6-6f8a-11ef-8623-c6596802cd02:1-58"}} keyspace:"customer" shard:"0" type:COMMIT keyspace:"customer" shard:"0"]
[type:COPY_COMPLETED keyspace:"customer" shard:"0" type:COPY_COMPLETED]

[type:BEGIN timestamp:1725982713 current_time:1725982713402751000 keyspace:"customer" shard:"0" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/813f4cc6-6f8a-11ef-8623-c6596802cd02:1-59"}} keyspace:"customer" shard:"0" type:COMMIT timestamp:1725982713 current_time:1725982713402768000 keyspace:"customer" shard:"0"]
[type:BEGIN timestamp:1725982713 current_time:1725982713403592000 keyspace:"customer" shard:"0" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/813f4cc6-6f8a-11ef-8623-c6596802cd02:1-60"}} keyspace:"customer" shard:"0" type:COMMIT timestamp:1725982713 current_time:1725982713403601000 keyspace:"customer" shard:"0"]
[type:BEGIN timestamp:1725982713 current_time:1725982713404411000 keyspace:"customer" shard:"0" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/813f4cc6-6f8a-11ef-8623-c6596802cd02:1-61"}} keyspace:"customer" shard:"0" type:COMMIT timestamp:1725982713 current_time:1725982713404420000 keyspace:"customer" shard:"0"]
[type:BEGIN timestamp:1725982713 current_time:1725982713405332000 keyspace:"customer" shard:"0" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/813f4cc6-6f8a-11ef-8623-c6596802cd02:1-62"}} keyspace:"customer" shard:"0" type:COMMIT timestamp:1725982713 current_time:1725982713405339000 keyspace:"customer" shard:"0"]
[type:BEGIN timestamp:1725982713 current_time:1725982713407151000 keyspace:"customer" shard:"0" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/813f4cc6-6f8a-11ef-8623-c6596802cd02:1-63"}} keyspace:"customer" shard:"0" type:COMMIT timestamp:1725982713 current_time:1725982713407161000 keyspace:"customer" shard:"0"]
[type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/813f4cc6-6f8a-11ef-8623-c6596802cd02:1-64"}} keyspace:"customer" shard:"0" type:OTHER timestamp:1725982713 current_time:1725982713409077000 keyspace:"customer" shard:"0"]
[type:BEGIN timestamp:1725982713 current_time:1725982713412070000 keyspace:"customer" shard:"0" type:JOURNAL timestamp:1725982713 journal:{id:8200191490597391617 migration_type:SHARDS tables:"/.*" local_position:"MySQL56/813f4cc6-6f8a-11ef-8623-c6596802cd02:1-58" shard_gtids:{keyspace:"customer" shard:"80-" gtid:"MySQL56/95d28c66-6f8a-11ef-aa1d-ca69ae2cd39c:1-52"} shard_gtids:{keyspace:"customer" shard:"-80" gtid:"MySQL56/8f57b33e-6f8a-11ef-bcdd-21c062a722b4:1-52"} participants:{keyspace:"customer" shard:"0"}} current_time:1725982713412474000 keyspace:"customer" shard:"0" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/813f4cc6-6f8a-11ef-8623-c6596802cd02:1-65"}} keyspace:"customer" shard:"0" type:COMMIT timestamp:1725982713 current_time:1725982713412479000 keyspace:"customer" shard:"0"]
[type:BEGIN timestamp:1725982713 current_time:1725982713452029000 keyspace:"customer" shard:"80-" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"80-" gtid:"MySQL56/95d28c66-6f8a-11ef-aa1d-ca69ae2cd39c:1-53"} shard_gtids:{keyspace:"customer" shard:"-80" gtid:"MySQL56/8f57b33e-6f8a-11ef-bcdd-21c062a722b4:1-52"}} keyspace:"customer" shard:"80-" type:COMMIT timestamp:1725982713 current_time:1725982713452047000 keyspace:"customer" shard:"80-"]
[type:BEGIN timestamp:1725982713 current_time:1725982713452023000 keyspace:"customer" shard:"-80" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"80-" gtid:"MySQL56/95d28c66-6f8a-11ef-aa1d-ca69ae2cd39c:1-53"} shard_gtids:{keyspace:"customer" shard:"-80" gtid:"MySQL56/8f57b33e-6f8a-11ef-bcdd-21c062a722b4:1-53"}} keyspace:"customer" shard:"-80" type:COMMIT timestamp:1725982713 current_time:1725982713452043000 keyspace:"customer" shard:"-80"]
[type:BEGIN timestamp:1725982713 current_time:1725982713452906000 keyspace:"customer" shard:"-80" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"80-" gtid:"MySQL56/95d28c66-6f8a-11ef-aa1d-ca69ae2cd39c:1-53"} shard_gtids:{keyspace:"customer" shard:"-80" gtid:"MySQL56/8f57b33e-6f8a-11ef-bcdd-21c062a722b4:1-54"}} keyspace:"customer" shard:"-80" type:COMMIT timestamp:1725982713 current_time:1725982713452914000 keyspace:"customer" shard:"-80"]
[type:BEGIN timestamp:1725982713 current_time:1725982713453040000 keyspace:"customer" shard:"80-" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"80-" gtid:"MySQL56/95d28c66-6f8a-11ef-aa1d-ca69ae2cd39c:1-54"} shard_gtids:{keyspace:"customer" shard:"-80" gtid:"MySQL56/8f57b33e-6f8a-11ef-bcdd-21c062a722b4:1-54"}} keyspace:"customer" shard:"80-" type:COMMIT timestamp:1725982713 current_time:1725982713453059000 keyspace:"customer" shard:"80-"]
[type:BEGIN timestamp:1725982713 current_time:1725982713676800000 keyspace:"customer" shard:"80-" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"80-" gtid:"MySQL56/95d28c66-6f8a-11ef-aa1d-ca69ae2cd39c:1-55"} shard_gtids:{keyspace:"customer" shard:"-80" gtid:"MySQL56/8f57b33e-6f8a-11ef-bcdd-21c062a722b4:1-54"}} keyspace:"customer" shard:"80-" type:COMMIT timestamp:1725982713 current_time:1725982713676814000 keyspace:"customer" shard:"80-"]
[type:BEGIN timestamp:1725982713 current_time:1725982713676804000 keyspace:"customer" shard:"-80" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"80-" gtid:"MySQL56/95d28c66-6f8a-11ef-aa1d-ca69ae2cd39c:1-55"} shard_gtids:{keyspace:"customer" shard:"-80" gtid:"MySQL56/8f57b33e-6f8a-11ef-bcdd-21c062a722b4:1-55"}} keyspace:"customer" shard:"-80" type:COMMIT timestamp:1725982713 current_time:1725982713676898000 keyspace:"customer" shard:"-80"]
[type:BEGIN timestamp:1725982713 current_time:1725982713677994000 keyspace:"customer" shard:"80-" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"80-" gtid:"MySQL56/95d28c66-6f8a-11ef-aa1d-ca69ae2cd39c:1-56"} shard_gtids:{keyspace:"customer" shard:"-80" gtid:"MySQL56/8f57b33e-6f8a-11ef-bcdd-21c062a722b4:1-55"}} keyspace:"customer" shard:"80-" type:COMMIT timestamp:1725982713 current_time:1725982713678006000 keyspace:"customer" shard:"80-"]
[type:BEGIN timestamp:1725982713 current_time:1725982713677979000 keyspace:"customer" shard:"-80" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"80-" gtid:"MySQL56/95d28c66-6f8a-11ef-aa1d-ca69ae2cd39c:1-56"} shard_gtids:{keyspace:"customer" shard:"-80" gtid:"MySQL56/8f57b33e-6f8a-11ef-bcdd-21c062a722b4:1-56"}} keyspace:"customer" shard:"-80" type:COMMIT timestamp:1725982713 current_time:1725982713677991000 keyspace:"customer" shard:"-80"]
[type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"80-" gtid:"MySQL56/95d28c66-6f8a-11ef-aa1d-ca69ae2cd39c:1-57"} shard_gtids:{keyspace:"customer" shard:"-80" gtid:"MySQL56/8f57b33e-6f8a-11ef-bcdd-21c062a722b4:1-56"}} keyspace:"customer" shard:"80-" type:OTHER timestamp:1725982713 current_time:1725982713721662000 keyspace:"customer" shard:"80-"]
[type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"80-" gtid:"MySQL56/95d28c66-6f8a-11ef-aa1d-ca69ae2cd39c:1-57"} shard_gtids:{keyspace:"customer" shard:"-80" gtid:"MySQL56/8f57b33e-6f8a-11ef-bcdd-21c062a722b4:1-57"}} keyspace:"customer" shard:"-80" type:OTHER timestamp:1725982713 current_time:1725982713723047000 keyspace:"customer" shard:"-80"]
[type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"80-" gtid:"MySQL56/95d28c66-6f8a-11ef-aa1d-ca69ae2cd39c:1-58"} shard_gtids:{keyspace:"customer" shard:"-80" gtid:"MySQL56/8f57b33e-6f8a-11ef-bcdd-21c062a722b4:1-57"}} keyspace:"customer" shard:"80-" type:OTHER timestamp:1725982713 current_time:1725982713730817000 keyspace:"customer" shard:"80-"]
[type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"80-" gtid:"MySQL56/95d28c66-6f8a-11ef-aa1d-ca69ae2cd39c:1-58"} shard_gtids:{keyspace:"customer" shard:"-80" gtid:"MySQL56/8f57b33e-6f8a-11ef-bcdd-21c062a722b4:1-58"}} keyspace:"customer" shard:"-80" type:OTHER timestamp:1725982713 current_time:1725982713734496000 keyspace:"customer" shard:"-80"]

[type:BEGIN timestamp:1725982774 current_time:1725982774169397000 keyspace:"customer" shard:"-80" type:FIELD timestamp:1725982774 field_event:{table_name:"customer.customer" fields:{name:"customer_id" type:INT64 table:"customer" org_table:"customer" database:"vt_customer" org_name:"customer_id" column_length:20 charset:63 flags:53251 column_type:"bigint"} fields:{name:"email" type:VARBINARY table:"customer" org_table:"customer" database:"vt_customer" org_name:"email" column_length:128 charset:63 flags:128 column_type:"varbinary(128)"} keyspace:"customer" shard:"-80"} current_time:1725982774171791000 keyspace:"customer" shard:"-80" type:ROW timestamp:1725982774 row_event:{table_name:"customer.customer" row_changes:{after:{lengths:2 lengths:21 values:"10mlord@planetscale.com"}} keyspace:"customer" shard:"-80" flags:1} current_time:1725982774171808000 keyspace:"customer" shard:"-80" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"80-" gtid:"MySQL56/95d28c66-6f8a-11ef-aa1d-ca69ae2cd39c:1-58"} shard_gtids:{keyspace:"customer" shard:"-80" gtid:"MySQL56/8f57b33e-6f8a-11ef-bcdd-21c062a722b4:1-59"}} keyspace:"customer" shard:"-80" type:COMMIT timestamp:1725982774 current_time:1725982774171817000 keyspace:"customer" shard:"-80"]

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: Document VStreamFlags.IncludeReshardJournalEvents website#1844

@mattlord mattlord added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: VReplication labels Sep 10, 2024
Copy link
Contributor

vitess-bot bot commented Sep 10, 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 Sep 10, 2024
@github-actions github-actions bot added this to the v21.0.0 milestone Sep 10, 2024
Copy link

codecov bot commented Sep 10, 2024

Codecov Report

Attention: Patch coverage is 88.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 68.93%. Comparing base (a513601) to head (784a84b).
Report is 22 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/vtgate/vstream_manager.go 88.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16737      +/-   ##
==========================================
- Coverage   68.93%   68.93%   -0.01%     
==========================================
  Files        1565     1565              
  Lines      201745   201753       +8     
==========================================
- Hits       139075   139073       -2     
- Misses      62670    62680      +10     

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

Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
@mattlord mattlord removed NeedsIssue A linked issue is missing for this Pull Request 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 labels Sep 10, 2024
@mattlord mattlord removed the NeedsWebsiteDocsUpdate What it says label Sep 10, 2024
@mattlord mattlord marked this pull request as ready for review September 10, 2024 15:56
Signed-off-by: Matt Lord <mattalord@gmail.com>
@deepthi deepthi merged commit 53a6ea4 into vitessio:main Sep 17, 2024
130 checks passed
@deepthi deepthi deleted the vstream_include_journals branch September 17, 2024 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: VReplication Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: ReceiveJournalEvent Flag for VStream
3 participants