-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: fix incorrect follower read and testing knob for sql stats compaction job #69346
Conversation
7647f12
to
5f19d4f
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @Azhng)
pkg/sql/sqlstats/persistedsqlstats/compaction_exec.go, line 199 at r1 (raw file):
SELECT count(*) FROM %[1]s %[3]s
why it was necessary to change to order of this clause?
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.
Reviewed 1 of 1 files at r1.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @Azhng)
-- commits, line 5 at r1:
nit: spelling / grammar: "Previously, the SQL Stats Compaction job did not check for nil testing knobs and constructed its SQL query with incorrect follower read syntax."
-- commits, line 11 at r1:
über-nit: leading space
pkg/sql/sqlstats/persistedsqlstats/compaction_exec.go, line 199 at r1 (raw file):
SELECT count(*) FROM %[1]s %[3]s
Is it possible to write a test for this fix?
pkg/sql/sqlstats/persistedsqlstats/compaction_exec.go, line 199 at r1 (raw file):
SELECT count(*) FROM %[1]s %[3]s
And would you want to reorder the placeholder indexes now to match their positions?
SELECT count(*)
FROM %[1]s
%[2]s
WHERE %[3]s = $1
pkg/sql/sqlstats/persistedsqlstats/compaction_exec.go, line 204 at r1 (raw file):
followerReadClause := "AS OF SYSTEM TIME follower_read_timestamp()" if c.knobs != nil && c.knobs.DisableFollowerRead {
Is it possible to write a test for this fix? Or, better yet, is there a way to make these knobs never nil in the first place?
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.
Reviewed all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @Azhng)
5f19d4f
to
46a0cc9
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @maryliag and @matthewtodd)
Previously, matthewtodd (Matthew Todd) wrote…
nit: spelling / grammar: "Previously, the SQL Stats Compaction job did not check for nil testing knobs and constructed its SQL query with incorrect follower read syntax."
Done.
Previously, matthewtodd (Matthew Todd) wrote…
über-nit: leading space
Done.
pkg/sql/sqlstats/persistedsqlstats/compaction_exec.go, line 199 at r1 (raw file):
Previously, maryliag (Marylia Gutierrez) wrote…
why it was necessary to change to order of this clause?
This is because the ASOT clause was placed in a wrong place.
Originally, it generates queries like:
SELECT count(*)
FROM system.statement_statistics
WHERE ...
AS OF SYSTEM TIME follower_read_timestamp()
but the correct syntax should be
SELECT count(*)
FROM system.statement_statistics
AS OF SYSTEM TIME follower_read_timestamp()
WHERE ...
We disabled follower read in test because this would cause historical reads into a point where system tables are not even created yet. This is a scenario where it doesn't happen outside of testing.
pkg/sql/sqlstats/persistedsqlstats/compaction_exec.go, line 199 at r1 (raw file):
Previously, matthewtodd (Matthew Todd) wrote…
Is it possible to write a test for this fix?
Would be difficult, follower read is difficult for us to test in the SQL land. The only hack would be time.Sleep()
and wait for the follower read timestamp to be higher than the point where system tables are created. But we really want to avoid doing those in test.
pkg/sql/sqlstats/persistedsqlstats/compaction_exec.go, line 199 at r1 (raw file):
Previously, matthewtodd (Matthew Todd) wrote…
And would you want to reorder the placeholder indexes now to match their positions?
SELECT count(*) FROM %[1]s %[2]s WHERE %[3]s = $1
Done.
pkg/sql/sqlstats/persistedsqlstats/compaction_exec.go, line 204 at r1 (raw file):
Previously, matthewtodd (Matthew Todd) wrote…
Is it possible to write a test for this fix? Or, better yet, is there a way to make these knobs never nil in the first place?
Hmm, since this is only used for test, I hope we can avoid the extra allocation unless it's necessary.
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.
Reviewed all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @Azhng, @maryliag, and @matthewtodd)
pkg/sql/sqlstats/persistedsqlstats/compaction_exec.go, line 199 at r1 (raw file):
Previously, Azhng (Archer Zhang) wrote…
Would be difficult, follower read is difficult for us to test in the SQL land. The only hack would be
time.Sleep()
and wait for the follower read timestamp to be higher than the point where system tables are created. But we really want to avoid doing those in test.
Understood. It's a shame we can't protect ourselves from bad SQL. Like maybe we'd want some infrastructure to run the query through the parser or something. But non-blocking for now.
pkg/sql/sqlstats/persistedsqlstats/compaction_exec.go, line 204 at r1 (raw file):
Previously, Azhng (Archer Zhang) wrote…
Hmm, since this is only used for test, I hope we can avoid the extra allocation unless it's necessary.
Fair enough. :-) Thoughts on a test somehow?
46a0cc9
to
19332f7
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @maryliag and @matthewtodd)
pkg/sql/sqlstats/persistedsqlstats/compaction_exec.go, line 204 at r1 (raw file):
Previously, matthewtodd (Matthew Todd) wrote…
Fair enough. :-) Thoughts on a test somehow?
Done.
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.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @maryliag and @matthewtodd)
19332f7
to
8583ec4
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.
Reviewed 1 of 1 files at r2, 1 of 1 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @Azhng)
TFTR! bors r=maryliag,mathewtodd |
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.
Reviewable status: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @Azhng)
pkg/sql/sqlstats/persistedsqlstats/compaction_exec.go, line 199 at r1 (raw file):
Previously, matthewtodd (Matthew Todd) wrote…
Understood. It's a shame we can't protect ourselves from bad SQL. Like maybe we'd want some infrastructure to run the query through the parser or something. But non-blocking for now.
You could pass a different expression in the follower read clause like '-1us'
and then sleep for 1 microsecond. I prefer that to no testing.
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.
Reviewable status: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @Azhng)
pkg/sql/sqlstats/persistedsqlstats/compaction_exec.go, line 199 at r1 (raw file):
Previously, ajwerner wrote…
You could pass a different expression in the follower read clause like
'-1us'
and then sleep for 1 microsecond. I prefer that to no testing.
In fact, maybe that's the answer here. Maybe we get rid of the knob to disable follower reads and replace it with a knob to set up the fixed timestamp to '-1us'
. I don't think you need to sleep 1us.
bors r- |
Canceled. |
8583ec4
to
dfdd8ea
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (and 2 stale) (waiting on @maryliag)
pkg/sql/sqlstats/persistedsqlstats/compaction_exec.go, line 199 at r1 (raw file):
Previously, ajwerner wrote…
In fact, maybe that's the answer here. Maybe we get rid of the knob to disable follower reads and replace it with a knob to set up the fixed timestamp to
'-1us'
. I don't think you need to sleep 1us.
Done.
dfdd8ea
to
fab0c78
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.
Reviewed 2 of 6 files at r5, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (and 2 stale) (waiting on @Azhng and @maryliag)
pkg/sql/sqlstats/persistedsqlstats/reader_test.go, line 57 at r5 (raw file):
// Wait for the system table to be created by ASOT timestamp. time.Sleep(time.Microsecond)
Do you actually need these? I have a feeling the answer is no.
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.
Reviewable status: complete! 1 of 0 LGTMs obtained (and 2 stale) (waiting on @Azhng and @maryliag)
pkg/sql/sqlstats/persistedsqlstats/test_utils.go, line 27 at r5 (raw file):
// ASOTClause overrides the AS OF SYSTEM TIME clause in queries used in // persistedsqlstats. ASOTClause string
nit: Do you want this to be AOSTClause
instead?
I don't know what it is about the acronym AOST but it has been written accidentally as ASOT a lot, including by myself. My brain, for whatever reason, doesn't see the transposition. A simple slack search shows |
Amazing. 🤯 |
fab0c78
to
0f6224f
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.
Human brain is interesting 🤯
Reviewable status: complete! 0 of 0 LGTMs obtained (and 3 stale) (waiting on @ajwerner and @maryliag)
pkg/sql/sqlstats/persistedsqlstats/reader_test.go, line 57 at r5 (raw file):
Previously, ajwerner wrote…
// Wait for the system table to be created by ASOT timestamp. time.Sleep(time.Microsecond)
Do you actually need these? I have a feeling the answer is no.
Removed.
pkg/sql/sqlstats/persistedsqlstats/test_utils.go, line 27 at r5 (raw file):
Previously, matthewtodd (Matthew Todd) wrote…
nit: Do you want this to be
AOSTClause
instead?
Done.
0f6224f
to
0a29bea
Compare
0a29bea
to
5464b74
Compare
compaction job Previously, the SQL Stats Compaction job did not check for nil testing knobs and constructed its SQL query with incorrect follower read syntax This commit address those two bugs. Release justification: Category 2: Bug fixes and low-risk updates to new functionality Release note: None
5464b74
to
2fad679
Compare
TFTR! bors r=ajwerner,maryliag,matthewtodd |
Build succeeded: |
68401: sql: create sql stats compaction scheduled job r=miretskiy,maryliag a=Azhng Depends on #68434, #69346 sql: create sql stats compaction scheduled job This commit introduces SQL Stats Compaction Scheduled job, where it runs in an hourly schedule and invokes the SQL Stats Compaction Job that was created in the previous commit. This commit also introduces `crdb_internal.schedule_sql_stats_compaction()` builtin as a way to manually create SQL Stats compaction schedule. `SHOW SCHEDULES` command'syntax is also extended to support `SHOW SCHEDUELS FOR SQL STATISTICS`. Release justification: category 4 Release note (sql change): introduce crdb_internal.schedule_sql_stats_compaction() to manually create SQL Stats compaction schedule. Extend SHOW SCHEDULES command to support SHOW SCHEDULES FOR SQL STATISTICS. Co-authored-by: Azhng <[email protected]>
Previously, the SQL Stats Compaction job did not check for nil testing
knobs and constructed its SQL query with incorrect follower read syntax.
This commit address those two bugs.
Release justification: Category 2: Bug fixes and low-risk updates
to new functionality
Release note: None