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

VTGate VStream: Ensure reasonable delivery time for reshard journal event #16639

Merged
merged 14 commits into from
Aug 29, 2024

Conversation

mattlord
Copy link
Contributor

@mattlord mattlord commented Aug 23, 2024

Description

This is a follow-up to #15395 where we added support for resuming a vtgate VStream that was not running when a keyspace had been resharded.

When resuming a vtgate VStream that has the StopOnReshard flag enabled, the reshard journal event was not always fully sent and received as the stream could end (via context cancellation) before the journal event was sent and received in the grpc stream. This timing issue would happen fairly often when all processes are on the same machine such as when using the local examples (see manual test below).

In this PR we enforce a reasonable minimum amount time from the point we have sent the journal event in the vstreamManager to the point that we end the tablet and client stream. This prevents a race between sending the message at the higher layer down to the grpc layer and when the stream is closed via context cancellation — which then causes the lower layer grpc SendMsg/RecvMsg to fail with a context canceled error.

The following manual test then works as expected every time on the PR branch:

git checkout vstream_resume_after_reshard
make build

Update the example vstream client:

diff --git a/examples/local/vstream_client.go b/examples/local/vstream_client.go
index 98d2129f89..3c19bd965d 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{
@@ -75,6 +71,7 @@ func main() {
        flags := &vtgatepb.VStreamFlags{
                //MinimizeSkew:      false,
                //HeartbeatInterval: 60, //seconds
+               StopOnReshard: true,
        }
        reader, err := conn.VStream(ctx, topodatapb.TabletType_PRIMARY, vgtid, filter, flags)
        for {
cd examples/local
alias vtctldclient='command vtctldclient --server=localhost:15999'

./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

sleep 60

go run vstream_client.go

# In another shell
./301_customer_sharded.sh; ./302_new_shards.sh; ./303_reshard.sh; ./304_switch_reads.sh; ./305_switch_writes.sh

# Note and copy the first GTID for the customer/0 shard after the copy completed event (should be 1-56)

Update the example vstream client again, specifying the GTID we saved above (the GTID's UUID will differ from this diff):

diff --git a/examples/local/vstream_client.go b/examples/local/vstream_client.go
index 98d2129f89..2ed93b92bb 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:     "",
+                               Gtid: "d61b2d76-60eb-11ef-9bee-60a726c671e2:1-56", //"current"  // "MySQL56/36a89abd-978f-11eb-b312-04ed332e05c2:1-265"
                        }}}
        } else {
                vgtid = &binlogdatapb.VGtid{
@@ -75,6 +71,7 @@ func main() {
        flags := &vtgatepb.VStreamFlags{
                //MinimizeSkew:      false,
                //HeartbeatInterval: 60, //seconds
+               StopOnReshard: true,
        }
        reader, err := conn.VStream(ctx, topodatapb.TabletType_PRIMARY, vgtid, filter, flags)
        for {

Run the vstream client again and you'll see the stream end with a resharding journal event like this:

❯ go run vstream_client.go
[type:BEGIN timestamp:1724469519 current_time:1724470495748802000 keyspace:"customer" shard:"0" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/7180bfa2-61c7-11ef-af44-65bd845c4133:1-57"}} keyspace:"customer" shard:"0" type:COMMIT timestamp:1724469519 current_time:1724470495748819000 keyspace:"customer" shard:"0"]
[type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/7180bfa2-61c7-11ef-af44-65bd845c4133:1-58"}} keyspace:"customer" shard:"0" type:OTHER timestamp:1724469519 current_time:1724470495748876000 keyspace:"customer" shard:"0"]
[type:BEGIN timestamp:1724469519 current_time:1724470495748880000 keyspace:"customer" shard:"0" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/7180bfa2-61c7-11ef-af44-65bd845c4133:1-59"}} keyspace:"customer" shard:"0" type:COMMIT timestamp:1724469519 current_time:1724470495748895000 keyspace:"customer" shard:"0"]
[type:BEGIN timestamp:1724469519 current_time:1724470495748898000 keyspace:"customer" shard:"0" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/7180bfa2-61c7-11ef-af44-65bd845c4133:1-60"}} keyspace:"customer" shard:"0" type:COMMIT timestamp:1724469519 current_time:1724470495748919000 keyspace:"customer" shard:"0"]
[type:BEGIN timestamp:1724469546 current_time:1724470495748924000 keyspace:"customer" shard:"0" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/7180bfa2-61c7-11ef-af44-65bd845c4133:1-61"}} keyspace:"customer" shard:"0" type:COMMIT timestamp:1724469546 current_time:1724470495748932000 keyspace:"customer" shard:"0"]
[type:BEGIN timestamp:1724469546 current_time:1724470495748937000 keyspace:"customer" shard:"0" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/7180bfa2-61c7-11ef-af44-65bd845c4133:1-62"}} keyspace:"customer" shard:"0" type:COMMIT timestamp:1724469546 current_time:1724470495748943000 keyspace:"customer" shard:"0"]
[type:BEGIN timestamp:1724469546 current_time:1724470495748948000 keyspace:"customer" shard:"0" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/7180bfa2-61c7-11ef-af44-65bd845c4133:1-63"}} keyspace:"customer" shard:"0" type:COMMIT timestamp:1724469546 current_time:1724470495748954000 keyspace:"customer" shard:"0"]
[type:BEGIN timestamp:1724469546 current_time:1724470495748957000 keyspace:"customer" shard:"0" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/7180bfa2-61c7-11ef-af44-65bd845c4133:1-64"}} keyspace:"customer" shard:"0" type:COMMIT timestamp:1724469546 current_time:1724470495748964000 keyspace:"customer" shard:"0"]
[type:BEGIN timestamp:1724469546 current_time:1724470495748979000 keyspace:"customer" shard:"0" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/7180bfa2-61c7-11ef-af44-65bd845c4133:1-65"}} keyspace:"customer" shard:"0" type:COMMIT timestamp:1724469546 current_time:1724470495748986000 keyspace:"customer" shard:"0"]
[type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/7180bfa2-61c7-11ef-af44-65bd845c4133:1-66"}} keyspace:"customer" shard:"0" type:OTHER timestamp:1724469546 current_time:1724470495748995000 keyspace:"customer" shard:"0"]
[type:BEGIN timestamp:1724469546 current_time:1724470495748999000 keyspace:"customer" shard:"0" type:JOURNAL timestamp:1724469546 journal:{id:8200191490597391617 migration_type:SHARDS tables:"/.*" local_position:"MySQL56/7180bfa2-61c7-11ef-af44-65bd845c4133:1-60" shard_gtids:{keyspace:"customer" shard:"80-" gtid:"MySQL56/96b2b596-61c7-11ef-a886-61ad413e7385:1-52"} shard_gtids:{keyspace:"customer" shard:"-80" gtid:"MySQL56/91d7c57a-61c7-11ef-9e52-65bd85625ba0:1-52"} participants:{keyspace:"customer" shard:"0"}} current_time:1724470495749337000 keyspace:"customer" shard:"0" type:VGTID vgtid:{shard_gtids:{keyspace:"customer" shard:"0" gtid:"MySQL56/7180bfa2-61c7-11ef-af44-65bd845c4133:1-67"}} keyspace:"customer" shard:"0" type:COMMIT timestamp:1724469546 current_time:1724470495749339000 keyspace:"customer" shard:"0"]
stream ended

You can execute this last step as many times as you like. For example, I've run this for over an hour w/o a failure:

while true; do go run vstream_client.go | grep -q JOURNAL || say "failure"; done

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

Copy link
Contributor

vitess-bot bot commented Aug 23, 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 Aug 23, 2024
@github-actions github-actions bot added this to the v21.0.0 milestone Aug 23, 2024
@mattlord mattlord added Type: Bug Component: VReplication and 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 Aug 23, 2024
Signed-off-by: Matt Lord <[email protected]>
Signed-off-by: Matt Lord <[email protected]>
Copy link

codecov bot commented Aug 23, 2024

Codecov Report

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

Project coverage is 68.98%. Comparing base (e6843dc) to head (e6b9486).
Report is 22 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/vtgate/vstream_manager.go 60.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16639      +/-   ##
==========================================
- Coverage   68.99%   68.98%   -0.02%     
==========================================
  Files        1562     1562              
  Lines      200754   200762       +8     
==========================================
- Hits       138508   138490      -18     
- Misses      62246    62272      +26     

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

@mattlord mattlord force-pushed the vstream_resume_after_reshard branch from ba1e660 to 5a543d2 Compare August 23, 2024 21:16
@mattlord mattlord force-pushed the vstream_resume_after_reshard branch from 5a543d2 to 9dc4133 Compare August 23, 2024 21:29
@mattlord mattlord changed the title VReplication: VTGate VStream: send reshard journal event immediately VReplication: VTGate VStream: ensure reasonable delivery time for reshard journal event Aug 24, 2024
@mattlord mattlord changed the title VReplication: VTGate VStream: ensure reasonable delivery time for reshard journal event VTGate VStream: ensure reasonable delivery time for reshard journal event Aug 24, 2024
@mattlord mattlord changed the title VTGate VStream: ensure reasonable delivery time for reshard journal event VTGate VStream: Ensure reasonable delivery time for reshard journal event Aug 24, 2024
Signed-off-by: Matt Lord <[email protected]>
Signed-off-by: Matt Lord <[email protected]>
@mattlord mattlord marked this pull request as ready for review August 24, 2024 15:11
Signed-off-by: Matt Lord <[email protected]>
@mattlord mattlord force-pushed the vstream_resume_after_reshard branch from c53790d to 9159b4f Compare August 24, 2024 15:52
@mattlord mattlord merged commit d916e81 into vitessio:main Aug 29, 2024
129 checks passed
@mattlord mattlord deleted the vstream_resume_after_reshard branch August 29, 2024 02:33
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.

Bug Report: VStream with StopOnReshard when resumed does not retransmit Journal event
3 participants