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

[KYUUBI #5392] Add query timeout monitor on server-side in ExecuteStatement #5398

Closed
wants to merge 1 commit into from

Conversation

bowenliang123
Copy link
Contributor

@bowenliang123 bowenliang123 commented Oct 11, 2023

Why are the changes needed?

As reported in #5392, currently the server is unable to guarantee that the statement timed-out when the engine may have no proper response for the server's request therefore the query timeout does not work.

Introduce a server-side statement query timeout monitor, to ensure the time-out query statements are set to TIMEOUT state and help the JDBC client get out of the blocked status.

How was this patch tested?

  • Add some test cases that check the changes thoroughly including negative and positive cases if possible

  • Add screenshots for manual tests if appropriate

  • Run test locally before make a pull request

Was this patch authored or co-authored using generative AI tooling?

No.

@codecov-commenter
Copy link

codecov-commenter commented Oct 11, 2023

Codecov Report

Merging #5398 (f5733b3) into master (c5854f7) will not change coverage.
Report is 1 commits behind head on master.
The diff coverage is 0.00%.

@@          Coverage Diff           @@
##           master   #5398   +/-   ##
======================================
  Coverage    0.00%   0.00%           
======================================
  Files         588     588           
  Lines       33454   33465   +11     
  Branches     4401    4401           
======================================
- Misses      33454   33465   +11     
Files Coverage Δ
...in/scala/org/apache/kyuubi/config/KyuubiConf.scala 0.00% <0.00%> (ø)
...org/apache/kyuubi/operation/ExecuteStatement.scala 0.00% <0.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@bowenliang123
Copy link
Contributor Author

Have a check on this draft implementation for server-side timeout monitoring.
Is this close to what we discussed in #5392 (comment) ?
cc @pan3793 @wForget @turboFei

}

object ExecuteStatement {
private[kyuubi] lazy val timeoutCheckPool: ScheduledExecutorService =
Copy link
Member

Choose a reason for hiding this comment

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

Reusing a SingleThreadScheduledExecutor for all operations may cause scheduling delays.

Copy link
Member

Choose a reason for hiding this comment

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

the scheduled task is quite light, compared with a bunch of monitor threads, is such a delay matter?

Copy link
Member

Choose a reason for hiding this comment

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

Not a big deal, as the thread will be shutdown immediately once query is finished

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change to use the addTimeoutMonitor method, which starts as a single-thread executor pool and seems never closed. It seems never be closed and it's opened for each ExecuteStatement operation.

Does it cause the thread leaks? Or let's force the timeout check in a dedicated global ForkJoinPool ?

@bowenliang123 bowenliang123 force-pushed the stmt-timeout branch 2 times, most recently from 75468b7 to 5913698 Compare October 18, 2023 01:27
@bowenliang123 bowenliang123 changed the title [KYUUBI #5392][Spark] Introduce server-side statement timeout monitor [KYUUBI #5392][Spark] Add query timeout monitor on server-side for ExecuteStatement Oct 18, 2023
@bowenliang123
Copy link
Contributor Author

bowenliang123 commented Oct 18, 2023

cc @pan3793 @turboFei @wForget @jeanlyn

@bowenliang123 bowenliang123 changed the title [KYUUBI #5392][Spark] Add query timeout monitor on server-side for ExecuteStatement [KYUUBI #5392][Spark] Add query timeout monitor on server-side in ExecuteStatement Oct 18, 2023
@pan3793 pan3793 changed the title [KYUUBI #5392][Spark] Add query timeout monitor on server-side in ExecuteStatement [KYUUBI #5392] Add query timeout monitor on server-side in ExecuteStatement Oct 18, 2023
@bowenliang123 bowenliang123 self-assigned this Oct 18, 2023
@bowenliang123 bowenliang123 added this to the v1.8.0 milestone Oct 18, 2023
@bowenliang123 bowenliang123 marked this pull request as ready for review October 18, 2023 05:58
val asyncOperation: Runnable = () =>
try {
if (isTimeoutMonitorEnabled) {
addTimeoutMonitor(queryTimeout)
Copy link
Member

Choose a reason for hiding this comment

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

how about moving it before executeStatement() as we did on the engine side?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's done on purpose for considering and tolerating the time for connecting and submitting statement to the engine.
But let's move it before executeStatement this time for semantic consistency.

bowenliang123 added a commit that referenced this pull request Oct 18, 2023
…tement

### _Why are the changes needed?_

As reported in #5392, currently the server is unable to guarantee that the statement timed-out when the engine may have no proper response for the server's request therefore the query timeout does not work.

Introduce a server-side statement query timeout monitor, to ensure the time-out query statements are set to TIMEOUT state and help the JDBC client get out of the blocked status.

### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [ ] Add screenshots for manual tests if appropriate

- [x] [Run test](https://kyuubi.readthedocs.io/en/master/contributing/code/testing.html#running-tests) locally before make a pull request

### _Was this patch authored or co-authored using generative AI tooling?_

No.

Closes #5398 from bowenliang123/stmt-timeout.

Closes #5392

f5733b3 [Bowen Liang] use addTimeoutMonitor for server-side query timeout checks

Authored-by: Bowen Liang <[email protected]>
Signed-off-by: liangbowen <[email protected]>
(cherry picked from commit bdc28ac)
Signed-off-by: liangbowen <[email protected]>
@bowenliang123
Copy link
Contributor Author

Thanks, merged to master(1.9.0) and branch-1.8 (1.8.0).

@bowenliang123 bowenliang123 deleted the stmt-timeout branch October 18, 2023 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants