VStream API: allow aligning streams from different shards to minimize skews across the streams#7626
Merged
rohit-nayak-ps merged 6 commits intovitessio:masterfrom Mar 26, 2021
Merged
Conversation
62b2c86 to
e29a218
Compare
…erent shards in a stream Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
c50638f to
2d356a6
Compare
sougou
approved these changes
Mar 24, 2021
Contributor
sougou
left a comment
There was a problem hiding this comment.
While reviewing this code, I realize that VStream will regroup a chunked transaction into a single packet. This could blow up memory if the transaction is huge (which we have seen in the past). So, I think we'll have to change the logic to send chunks if we receive chunks.
But at the same time, we have to ensure that transactions are not fragmented, and also skew continue to work correctly. So, a refactor may be needed.
We can do this later.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Minimizing skew across shard streams in the VStream API
Description
When VStream API is streaming from multiple shards we have multiple sources of events: one primary or replica tablet for each shard in the provided filter. The rate at which the events will be streamed by the source can depend on:
This can result in the events from some shards being well ahead of other shards. So, for example, if a row moves from the faster shard to a slower shard we might see the delete event in the faster shard much before the insert in the second, resulting in the row going "invisible" for the duration of the skew. This can affect user experience in applications where these events are used to refresh UI , for example.
For most applications where vstream api events feed into change data capture systems for auditing or reporting purposes these delays may be acceptable.
This PR adds a flag that the client can set. This flag enables skew detection between the various streams. Once a skew is detected, events for streams that are ahead are held back until the skew reaches an acceptable level.
Skew Detection
Each vstreamer event (vevent) contains two timestamps: one for when the database transaction occurred and the other is the current time on the source when the vevent was created. This lets us compute how far in the past the event we just received was created. We use this to determine which shard has the most recent and which one has the oldest event. Note that, for shards where there is no activity, vstreamer sends a heartbeat event every second. The transaction time for an heartbeat is the same as the current time on the source. (These heartbeats are not forwarded to the vstream since they are synthetic vreplication events).
If the difference between the fastest and slowest streams is greater than a threshold, we declare that we detected a skew. MySQL binlogs store the transaction timestamp in seconds. Also, on the vtgate serving the vstream, we adjust this time for clock skews between the vtgate and the source MySQL server. When the user sets the
minimizeSkewflag we want to keep the events across shards to be in the same second: each transaction timestamp is within 1 second of each other. Fuzzy logic alert: To account for rounding-off of the transaction timestamp and the clock-skew we set the threshold to be 2 seconds, instead of 1 second, so that we don't keep stalling the streams due to cumulative round-offs.Some other changes:
Related Issue(s)
Checklist
Impacted Areas in Vitess
Components that this PR will affect: