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

feat: authoritative query timeout for vttablet from vtgate #16735

Merged
merged 15 commits into from
Sep 11, 2024

Conversation

harshit-gangal
Copy link
Member

@harshit-gangal harshit-gangal commented Sep 9, 2024

Description

This PR uses the comment directive QUERY_TIMEOUT_MS, session variable query_timeout and VTGate's flag query-timeout to set the query timeout on the execute options sent to vttablet.

VTTablet will consider this as authoritative over VTTablet's default query timeout.
VTGate will set the execution context using the same timeout value.

QUERY_TIMEOUT_MS will override the session value if set. If nothing is set then no timeout value will be sent down to VTTablet.

Order of precedence: Query Comment > Session Value > VTGate flag.

If the query is executed inside a transaction then only the smaller value of query vs transaction timeout will be considered at VTTablet.

Related Issue(s)

Checklist

  • 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 Sep 9, 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 Sep 9, 2024
@harshit-gangal harshit-gangal removed the NeedsBackportReason If backport labels have been applied to a PR, a justification is required label Sep 9, 2024
@github-actions github-actions bot added this to the v21.0.0 milestone Sep 9, 2024
Copy link

codecov bot commented Sep 9, 2024

Codecov Report

Attention: Patch coverage is 90.35088% with 11 lines in your changes missing coverage. Please review.

Project coverage is 68.93%. Comparing base (e0a5069) to head (a857a5e).
Report is 58 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/vtgate/engine/dbddl.go 60.00% 4 Missing ⚠️
go/vt/vtgate/engine/insert_select.go 25.00% 3 Missing ⚠️
go/vt/vttablet/tabletserver/tabletserver.go 90.00% 2 Missing ⚠️
go/vt/sqlparser/comments.go 97.77% 1 Missing ⚠️
go/vt/vtgate/planbuilder/builder.go 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16735      +/-   ##
==========================================
- Coverage   68.94%   68.93%   -0.02%     
==========================================
  Files        1565     1565              
  Lines      201748   201764      +16     
==========================================
- Hits       139093   139083      -10     
- Misses      62655    62681      +26     

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

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
@harshit-gangal harshit-gangal added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: Query Serving 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 labels Sep 9, 2024
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
@shlomi-noach
Copy link
Contributor

I'd expect a test to fail here. Can you please create a test that validates this behavior is wrong?

Or, actually, maybe test coverage is great, and this is why these tests are failing?

2024-09-09T17:50:52.8411015Z === RUN   TestQueryTimeoutWithDual
2024-09-09T17:50:52.8469520Z     timeout_test.go:54: 
2024-09-09T17:50:52.8470778Z         	Error Trace:	/home/runner/work/vitess/vitess/go/test/endtoend/vtgate/queries/timeout/timeout_test.go:54
2024-09-09T17:50:52.8471828Z         	Error:      	Received unexpected error:
2024-09-09T17:50:52.8474220Z         	            	target: ks_misc.-80.primary: vttablet: rpc error: code = Canceled desc = context canceled (errno 1317) (sqlstate 70100) during query: select sleep(0.04) from dual
2024-09-09T17:50:52.8475777Z         	Test:       	TestQueryTimeoutWithDual
2024-09-09T17:50:52.8477427Z     timeout_test.go:62: 
2024-09-09T17:50:52.8478550Z         	Error Trace:	/home/runner/work/vitess/vitess/go/test/endtoend/vtgate/queries/timeout/timeout_test.go:62
2024-09-09T17:50:52.8479395Z         	Error:      	Received unexpected error:
2024-09-09T17:50:52.8481407Z         	            	target: ks_misc.-80.primary: vttablet: rpc error: code = Canceled desc = context canceled (errno 1317) (sqlstate 70100) during query: select sleep(0.01) from dual
2024-09-09T17:50:52.8482534Z         	Test:       	TestQueryTimeoutWithDual
2024-09-09T17:50:52.8482949Z     timeout_test.go:64: 
2024-09-09T17:50:52.8483932Z         	Error Trace:	/home/runner/work/vitess/vitess/go/test/endtoend/vtgate/queries/timeout/timeout_test.go:64
2024-09-09T17:50:52.8484834Z         	Error:      	Received unexpected error:
2024-09-09T17:50:52.8487030Z         	            	target: ks_misc.-80.primary: vttablet: rpc error: code = Canceled desc = context canceled (errno 1317) (sqlstate 70100) during query: select /*vt+ QUERY_TIMEOUT_MS=500 */ sleep(0.24) from dual
2024-09-09T17:50:52.8488277Z         	Test:       	TestQueryTimeoutWithDual
2024-09-09T17:50:52.8488678Z     timeout_test.go:68: 
2024-09-09T17:50:52.8489696Z         	Error Trace:	/home/runner/work/vitess/vitess/go/test/endtoend/vtgate/queries/timeout/timeout_test.go:68
2024-09-09T17:50:52.8490565Z         	Error:      	Received unexpected error:
2024-09-09T17:50:52.8492898Z         	            	target: ks_misc.-80.primary: vttablet: rpc error: code = Canceled desc = context canceled (errno 1317) (sqlstate 70100) during query: select /*vt+ QUERY_TIMEOUT_MS=15 */ sleep(0.001) from dual
2024-09-09T17:50:52.8494478Z         	Test:       	TestQueryTimeoutWithDual
2024-09-09T17:50:52.8494960Z --- FAIL: TestQueryTimeoutWithDual (0.01s)
2024-09-09T17:50:52.8495341Z === RUN   TestQueryTimeoutWithTables
2024-09-09T17:50:52.8508419Z     timeout_test.go:76: 
2024-09-09T17:50:52.8509302Z         	Error Trace:	/home/runner/work/vitess/vitess/go/test/endtoend/utils/utils.go:159
2024-09-09T17:50:52.8511157Z         	            				/home/runner/work/vitess/vitess/go/test/endtoend/vtgate/queries/timeout/timeout_test.go:76
2024-09-09T17:50:52.8512242Z         	Error:      	Received unexpected error:
2024-09-09T17:50:52.8515233Z         	            	target: uks.0.primary: vttablet: rpc error: code = Canceled desc = context canceled (errno 1317) (sqlstate 70100) during query: insert /*vt+ QUERY_TIMEOUT_MS=1000 */ into uks.unsharded(id1) values (1),(2),(3),(4),(5)
2024-09-09T17:50:52.8516625Z         	Test:       	TestQueryTimeoutWithTables
2024-09-09T17:50:52.8517721Z         	Messages:   	for query: insert /*vt+ QUERY_TIMEOUT_MS=1000 */ into uks.unsharded(id1) values (1),(2),(3),(4),(5)
2024-09-09T17:50:52.8518483Z --- FAIL: TestQueryTimeoutWithTables (0.00s)
2024-09-09T17:50:52.8518908Z === RUN   TestQueryTimeoutWithShardTargeting
2024-09-09T17:50:52.8701734Z     timeout_test.go:112: 
2024-09-09T17:50:52.8703065Z         	Error Trace:	/home/runner/work/vitess/vitess/go/test/endtoend/utils/utils.go:159
2024-09-09T17:50:52.8704805Z         	            				/home/runner/work/vitess/vitess/go/test/endtoend/vtgate/queries/timeout/timeout_test.go:112
2024-09-09T17:50:52.8705782Z         	Error:      	Received unexpected error:
2024-09-09T17:50:52.8708339Z         	            	target: ks_misc.-80.primary: vttablet: rpc error: code = Canceled desc = context canceled (errno 1317) (sqlstate 70100) during query: insert into t1(id1, id2) values (1,2),(3,4),(4,5),(5,6)
2024-09-09T17:50:52.8709630Z         	Test:       	TestQueryTimeoutWithShardTargeting
2024-09-09T17:50:52.8710434Z         	Messages:   	for query: insert into t1(id1, id2) values (1,2),(3,4),(4,5),(5,6)
2024-09-09T17:50:52.8711200Z --- FAIL: TestQueryTimeoutWithShardTargeting (0.02s)
2024-09-09T17:50:52.8711685Z FAIL

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
@harshit-gangal harshit-gangal changed the title feat: authoritative query timeout as query hint feat: authoritative query timeout for vttablet from vtgate Sep 10, 2024
Copy link
Contributor

@shlomi-noach shlomi-noach left a comment

Choose a reason for hiding this comment

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

Noting for self reference this usage sample:

select /*vt+ QUERY_TIMEOUT_MS=0 */ sleep(5) from dual

Still unsure about the relevance of the foreign key related changes.

go/vt/vtgate/plan_execute.go Outdated Show resolved Hide resolved
go/vt/vtgate/engine/insert_select.go Show resolved Hide resolved
@harshit-gangal
Copy link
Member Author

harshit-gangal commented Sep 10, 2024

Still unsure about the relevance of the foeign key related changes.

@shlomi-noach
Those are Query Hint related changes, brought all the extraction of query hints into a single struct.

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
@deepthi deepthi added the release notes (needs details) This PR needs to be listed in the release notes in a dedicated section (deprecation notice, etc...) label Sep 10, 2024
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
@systay systay removed the release notes (needs details) This PR needs to be listed in the release notes in a dedicated section (deprecation notice, etc...) label Sep 11, 2024
### <a id="query-timeout"/>Query Timeout Override
VTGate sends an authoritative query timeout to VTTablet when the `QUERY_TIMEOUT_MS` comment directive,
`query_timeout` session system variable, or `query-timeout` flag is set.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`query_timeout` session system variable, or `query-timeout` flag is set.
`query_timeout` session system variable, or `query-timeout` flag are set.

Copy link
Member Author

Choose a reason for hiding this comment

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

even one of them set is enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think is is more apt here.

@harshit-gangal harshit-gangal merged commit e3d2e89 into vitessio:main Sep 11, 2024
132 of 133 checks passed
@harshit-gangal harshit-gangal deleted the query-timeout branch September 11, 2024 08:23
@deepthi deepthi added the Benchmark me Add label to PR to run benchmarks label Oct 2, 2024
Copy link
Contributor

vitess-bot bot commented Oct 2, 2024

Hello! 👋

This Pull Request is now handled by arewefastyet. The current HEAD and future commits will be benchmarked.

You can find the performance comparison on the arewefastyet website.

@deepthi deepthi removed the Benchmark me Add label to PR to run benchmarks label Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: allow DDL statements to run for unlimited time
5 participants