Skip to content

Update VReplication Timestamp w/ Heartbeat#6635

Merged
dkhenry merged 6 commits intovitessio:masterfrom
planetscale:update-transaction-with-heartbeat
Aug 31, 2020
Merged

Update VReplication Timestamp w/ Heartbeat#6635
dkhenry merged 6 commits intovitessio:masterfrom
planetscale:update-transaction-with-heartbeat

Conversation

@PrismaPhonic
Copy link
Copy Markdown
Contributor

@PrismaPhonic PrismaPhonic commented Aug 26, 2020

This PR:

  1. Updates _vt.vreplication row timestamp w/ each heartbeat that happens outside of a transaction. This improves the accuracy of the transaction_timestamp recorded for each _vt.vreplication row, and allows anyone inspecting the _vt.vreplication table to get an accurate read on replication lag.
  2. Adds MaxVReplicationLag to Workflow Show subcommand, which displays the maximum vreplication lag seen across all shards.
  3. Updates tests accordingly.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>
… a workflow.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>
…ensuring that transaction_timestamp stays up to date.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>
…esn't get recorded.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>
…ed, which allows us to scrub incoming queries for heartbeat updates.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>
@PrismaPhonic PrismaPhonic force-pushed the update-transaction-with-heartbeat branch 2 times, most recently from a47c176 to a134bb8 Compare August 27, 2020 21:27
@PrismaPhonic PrismaPhonic marked this pull request as ready for review August 27, 2020 21:48
@PrismaPhonic PrismaPhonic requested a review from sougou as a code owner August 27, 2020 21:48
create unpredictable results for unit testing.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>
@PrismaPhonic PrismaPhonic force-pushed the update-transaction-with-heartbeat branch from a134bb8 to 68b0d74 Compare August 27, 2020 21:51
Copy link
Copy Markdown
Member

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

lgtm

continue
}
var got string
heartbeatRe := regexp.MustCompile(`update _vt.vreplication set time_updated=\d+, transaction_timestamp=\d+ where id=\d+`)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

possibly make the query case insensitive? Granted, _vt.vreplication is case sensitive, but all other elements, keywords & columns, are not.

Suggested change
heartbeatRe := regexp.MustCompile(`update _vt.vreplication set time_updated=\d+, transaction_timestamp=\d+ where id=\d+`)
heartbeatRe := regexp.MustCompile(`(?i)update _vt.vreplication set time_updated=\d+, transaction_timestamp=\d+ where id=\d+`)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In this case we are the ones writing the heartbeat queries and they are always written as lower case. If there actually was a query written where that wasn't the case, it would be a sure sign that it was not a heartbeat update query. Therefore, I think it being case sensitive is a better catch method.

case got = <-globalDBQueries:

if got == "begin" || got == "commit" || got == "rollback" || strings.Contains(got, "update _vt.vreplication set pos") {
if got == "begin" || got == "commit" || got == "rollback" || strings.Contains(got, "update _vt.vreplication set pos") || heartbeatRe.MatchString(got) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

perhaps the query gets lower cased beforehand? Otherwise, BEGIN, COMMIT, ROLLBACK should also be accepted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These were already here so I assume whoever built this had some wisdom with writing this catch. I believe that we always write them as lowercase (in vplayer), so this is safe. It's also just testing logic so if it breaks at some point, whoever broke it (by changing the casing that vplayer writes queries with) could adjust it then to fit their needs.

case got = <-globalDBQueries:

if got == "begin" || got == "commit" || got == "rollback" || strings.Contains(got, "update _vt.vreplication set pos") {
if got == "begin" || got == "commit" || got == "rollback" || strings.Contains(got, "update _vt.vreplication set pos") || heartbeatRe.MatchString(got) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there any risk at all for some query to contain the text update _vt.vreplication set pos? Does it make sense to convert strings.Contains() to strings.HasPrefix()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's a good question. I'm not sure why the original author of this test helper used Contains. It might be in an effort to strip potential whitespace? Or potentially to strip leading / which somehow end up in some of the test queries at the start?

Copy link
Copy Markdown
Member

@enisoc enisoc left a comment

Choose a reason for hiding this comment

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

LGTM

@dkhenry dkhenry merged commit 96c9400 into vitessio:master Aug 31, 2020
@shlomi-noach shlomi-noach deleted the update-transaction-with-heartbeat branch September 1, 2020 05:29
@askdba askdba added this to the v8.0 milestone Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants