-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Update VReplication Timestamp w/ Heartbeat #6635
Update VReplication Timestamp w/ Heartbeat #6635
Conversation
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>
a47c176
to
a134bb8
Compare
create unpredictable results for unit testing. Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>
a134bb8
to
68b0d74
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@@ -458,8 +458,16 @@ func expectDBClientQueries(t *testing.T, queries []string) { | |||
continue | |||
} | |||
var got string | |||
heartbeatRe := regexp.MustCompile(`update _vt.vreplication set time_updated=\d+, transaction_timestamp=\d+ where id=\d+`) |
There was a problem hiding this comment.
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.
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+`) |
There was a problem hiding this comment.
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.
@@ -503,7 +512,7 @@ func expectNontxQueries(t *testing.T, queries []string) { | |||
select { | |||
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@@ -503,7 +512,7 @@ func expectNontxQueries(t *testing.T, queries []string) { | |||
select { | |||
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) { |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR:
_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.Workflow Show
subcommand, which displays the maximum vreplication lag seen across all shards.