Skip to content

Add client-side statement execution timeout - #767

Merged
jayantsing-db merged 7 commits into
mainfrom
jayantsing-db/query-timeout
Apr 1, 2025
Merged

jayantsing-db merged 7 commits into
mainfrom
jayantsing-db/query-timeout

Conversation

@jayantsing-db

@jayantsing-db jayantsing-db commented Mar 25, 2025 •

Copy link
Copy Markdown
Collaborator

Description

  • DatabricksStatement uses the same-thread executor for the statement's CompletableFuture. By the time the code reaches the futureResultSet.get(timeoutInSeconds, TimeUnit.SECONDS) line, the task has already fully executed (or failed), so the timeout has no practical effect.
  • Create a reusable TimeoutHandler utility class that centralizes timeout logic.
  • Implement timeout checks during statement execution polling instead of relying on the CompletableFuture timeout.
  • Add automatic cancellation of statements when timeouts occur.
  • Ensure consistent timeout behavior across both SDK and Thrift client implementations.
  • Move the DatabricksSdkClientTest class to the test counterpart of its source package. Delete the duplicate DatabricksSdkClientTest class.
  • DatabricksThriftAccessor will now use connection param asyncPollIntervalMillis. Previously, the poll interval was hardcoded to 1 second.

Testing

  • Unit tests
  • E2E testing

Additional Notes to the Reviewer

TODO: Need to add multi-dbr test

@jayantsing-db jayantsing-db changed the title Add client side timeout Add client-side statement execution timeout Mar 26, 2025
@jayantsing-db
jayantsing-db marked this pull request as ready for review March 26, 2025 13:23

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should we throw exception if we are not able to cancel due to any reason?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The timeout logic will always throw Databricks timeout exception. Cancel statement not working will be addressed by the retry logic.

@vikrantpuppala
vikrantpuppala requested a review from Copilot March 26, 2025 15:36

Copilot AI left a comment

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.

Pull Request Overview

This PR adds client-side statement execution timeout support by introducing a reusable TimeoutHandler utility and integrating it in both Thrift and SDK client implementations. Key changes include:

  • Introducing the TimeoutHandler utility and its corresponding tests.
  • Updating DatabricksThriftAccessor and DatabricksSdkClient to check for timeouts during polling and automatically cancel statements.
  • Removing duplicate tests and adjusting polling intervals to support the new timeout logic.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/test/java/com/databricks/jdbc/dbclient/impl/thrift/DatabricksThriftAccessorTest.java Adjusted tests to simulate timeout scenarios and reflect the new timeout behavior
src/test/java/com/databricks/jdbc/dbclient/impl/common/TimeoutHandlerTest.java New tests for validating the TimeoutHandler functionality
src/test/java/com/databricks/jdbc/api/impl/DatabricksSdkClientTest.java Removed duplicate test class to avoid redundancy
src/main/java/com/databricks/jdbc/dbclient/impl/thrift/DatabricksThriftAccessor.java Integrated timeout check via TimeoutHandler and updated polling interval handling
src/main/java/com/databricks/jdbc/dbclient/impl/sqlexec/DatabricksSdkClient.java Added timeout checks using TimeoutHandler for statement execution
src/main/java/com/databricks/jdbc/dbclient/impl/common/TimeoutHandler.java New utility class providing centralized timeout handling and cancellation logic
Comments suppressed due to low confidence (1)

src/main/java/com/databricks/jdbc/dbclient/impl/common/TimeoutHandler.java:47

  • [nitpick] Consider using '>= timeoutSeconds' instead of '> timeoutSeconds' so that the timeout is enforced as soon as the elapsed time equals the specified limit.
if (elapsedTimeSeconds > timeoutSeconds) {

@jayantsing-db
jayantsing-db merged commit 7d509d0 into databricks:main Apr 1, 2025
@jayantsing-db
jayantsing-db deleted the jayantsing-db/query-timeout branch April 1, 2025 11:22
samikshya-db added a commit that referenced this pull request Apr 12, 2025
* [PECOBLR-272] Retry handler fixes for http client (#764)

* Support Azure Managed Identity OAuth in OSS JDBC (#756)

* draft for azure msi

* add unit tests

* remove debug line

* fmt

* Address comments

* Add debug logs

* [PECOBLR-262] implement todos in DBFS volume client (#763)

* [PECOBLR-182] Add support for retry timeout for UC vol operations (#760)

* Add support for retry timeout for UC vol operations

* [PECOBLR-161][PECOBLR-282] add support for configurable row fetch limit in thrift inline and fix setMaxRows (#765)

* [PECOBLR-126] added DefaultStringColumnLength config (#761)

* Add client-side statement execution timeout (#767)

## Description
- DatabricksStatement uses the same-thread executor for the statement's CompletableFuture. By the time the code reaches the `futureResultSet.get(timeoutInSeconds, TimeUnit.SECONDS)` line, the task has already fully executed (or failed), so the timeout has no practical effect.
- Create a reusable TimeoutHandler utility class that centralizes timeout logic.
- Implement timeout checks during statement execution polling instead of relying on the CompletableFuture timeout.
- Add automatic cancellation of statements when timeouts occur.
- Ensure consistent timeout behavior across both SDK and Thrift client implementations.
- Move the DatabricksSdkClientTest class to the test counterpart of its source package. Delete the duplicate DatabricksSdkClientTest class.
- DatabricksThriftAccessor will now use connection param `asyncPollIntervalMillis`. Previously, the poll interval was hardcoded to 1 second.

## Testing
- Unit tests
- E2E testing

* [PECOBLR-106][PECOBLR-235] Fixes Logging Test intermittent failures and adds support for thriftclient in test (#766)

* logging fixes

* fix logging test

* fix logging test

* fix logging test

* fix logging test

* fix logging test

* use printf in place of echo

* use powershell

* try java side fix

* fix comments

* minor fixes

* Hybrid Results are enabled by default in SEA Mode (#771)

* Made Hybrid results default

* Fixed unit test

* Added Fake service stubs

* Added stubs for Default hybrid mode

* Reverted to old stubs

* Reverted stubs

* Fix

* [PECOBLR-289] Throw exception for column not found (#773)

* [PECOBLR-145] Implement OAuth2RedirectUrlPort (#775)

* Support for providing custom headers from URL (#776)

* Support for custom headers

* Made headers case insensitive

* Added back the case matching in headers

* Formatting fix

* Align behaviour for ResultSet#getBoolean (#774)

* Update version to 1.0.3 (#772)

* make changes for 1.0.3 release

* adds changelog

* updates changelog

* updates changelog

* updates changelog

* [PECOBLR-239][PECOBLR-279] added sql types integration tests (#769)

* added edge cases for string and null

* update stubs

* add test for variant type

* add test for timestamp

* [PECOBLR-310] Refactor internal interfaces into internal package, and fix javadoc for public interfaces (#770)

* Fix javadoc for all public interfaces

* [PECOBLR-164] Support connection param SocketTimeout (#777)

- The default value of the param is kept as 900 seconds (same as earlier value and default in databricks-sdk-java)
- Set the param in thrift, dbfs, and sql-exec clients

* Renaming UC Volume retryable codes and retry timeout parameters as per Docs team feedback (#780)

* Rename UC timeout and retryable parameters based on Docs team feedback

* Set default value as null for BigDecimal (#782)

* [PECOBLR-322] Update SDK to the latest version (0.43.0) (#781)

* [PECOBLR-301] Handle server returned Thrift version as part of open session response gracefully (#779)

* init changes

* Refactor TSparkArrowTypes initialization based on protocol version

* added comments

* added several unit tests

* added more unit tests

* ran ProtocolFeatureUtilTest for all protocol versions

* store protocol version as TProtocolVersion enum.

* move db compute check to protocol feature util

---------

Co-authored-by: Vikrant Puppala <[email protected]>
Co-authored-by: Shivam Raj <[email protected]>
Co-authored-by: Gopal Lal <[email protected]>
Co-authored-by: jayant <[email protected]>
Co-authored-by: Madhav Sainanee <[email protected]>
Co-authored-by: Jothi Prakash <[email protected]>
samikshya-db added a commit that referenced this pull request Apr 12, 2025
* [PECOBLR-272] Retry handler fixes for http client (#764)

* Support Azure Managed Identity OAuth in OSS JDBC (#756)

* draft for azure msi

* add unit tests

* remove debug line

* fmt

* Address comments

* Add debug logs

* [PECOBLR-262] implement todos in DBFS volume client (#763)

* [PECOBLR-182] Add support for retry timeout for UC vol operations (#760)

* Add support for retry timeout for UC vol operations

* [PECOBLR-161][PECOBLR-282] add support for configurable row fetch limit in thrift inline and fix setMaxRows (#765)

* [PECOBLR-126] added DefaultStringColumnLength config (#761)

* Add client-side statement execution timeout (#767)

## Description
- DatabricksStatement uses the same-thread executor for the statement's CompletableFuture. By the time the code reaches the `futureResultSet.get(timeoutInSeconds, TimeUnit.SECONDS)` line, the task has already fully executed (or failed), so the timeout has no practical effect.
- Create a reusable TimeoutHandler utility class that centralizes timeout logic.
- Implement timeout checks during statement execution polling instead of relying on the CompletableFuture timeout.
- Add automatic cancellation of statements when timeouts occur.
- Ensure consistent timeout behavior across both SDK and Thrift client implementations.
- Move the DatabricksSdkClientTest class to the test counterpart of its source package. Delete the duplicate DatabricksSdkClientTest class.
- DatabricksThriftAccessor will now use connection param `asyncPollIntervalMillis`. Previously, the poll interval was hardcoded to 1 second.

## Testing
- Unit tests
- E2E testing

* [PECOBLR-106][PECOBLR-235] Fixes Logging Test intermittent failures and adds support for thriftclient in test (#766)

* logging fixes

* fix logging test

* fix logging test

* fix logging test

* fix logging test

* fix logging test

* use printf in place of echo

* use powershell

* try java side fix

* fix comments

* minor fixes

* Hybrid Results are enabled by default in SEA Mode (#771)

* Made Hybrid results default

* Fixed unit test

* Added Fake service stubs

* Added stubs for Default hybrid mode

* Reverted to old stubs

* Reverted stubs

* Fix

* [PECOBLR-289] Throw exception for column not found (#773)

* [PECOBLR-145] Implement OAuth2RedirectUrlPort (#775)

* Support for providing custom headers from URL (#776)

* Support for custom headers

* Made headers case insensitive

* Added back the case matching in headers

* Formatting fix

* Align behaviour for ResultSet#getBoolean (#774)

* Update version to 1.0.3 (#772)

* make changes for 1.0.3 release

* adds changelog

* updates changelog

* updates changelog

* updates changelog

* [PECOBLR-239][PECOBLR-279] added sql types integration tests (#769)

* added edge cases for string and null

* update stubs

* add test for variant type

* add test for timestamp

* [PECOBLR-310] Refactor internal interfaces into internal package, and fix javadoc for public interfaces (#770)

* Fix javadoc for all public interfaces

* [PECOBLR-164] Support connection param SocketTimeout (#777)

- The default value of the param is kept as 900 seconds (same as earlier value and default in databricks-sdk-java)
- Set the param in thrift, dbfs, and sql-exec clients

* Renaming UC Volume retryable codes and retry timeout parameters as per Docs team feedback (#780)

* Rename UC timeout and retryable parameters based on Docs team feedback

* Set default value as null for BigDecimal (#782)

* [PECOBLR-322] Update SDK to the latest version (0.43.0) (#781)

* [PECOBLR-301] Handle server returned Thrift version as part of open session response gracefully (#779)

* init changes

* Refactor TSparkArrowTypes initialization based on protocol version

* added comments

* added several unit tests

* added more unit tests

* ran ProtocolFeatureUtilTest for all protocol versions

* store protocol version as TProtocolVersion enum.

* move db compute check to protocol feature util

---------

Co-authored-by: Vikrant Puppala <[email protected]>
Co-authored-by: Shivam Raj <[email protected]>
Co-authored-by: Gopal Lal <[email protected]>
Co-authored-by: jayant <[email protected]>
Co-authored-by: Madhav Sainanee <[email protected]>
Co-authored-by: Jothi Prakash <[email protected]>
msrathore-db added a commit to msrathore-db/databricks-jdbc that referenced this pull request Apr 21, 2026
Emits at DEBUG level in three paths of parseCustomHeaders:

1. Org-id successfully extracted from ?o= in httpPath — log the value
   so customers diagnosing SPOG routing can confirm the header was added.
2. x-databricks-org-id already provided by the caller (via http.header.*
   URL param) — log that we are not overriding the explicit user value.
3. Malformed httpPath — existing warning, retained and retagged with a
   "SPOG header extraction:" prefix for grep-ability.

Helps with customer support: when a customer reports "SPOG isn't routing
correctly", they can enable DEBUG logging and immediately see whether
the driver saw their ?o= value.

Mirrors equivalent logging added to the Python connector's
_extract_spog_headers in databricks-sql-python (PR databricks#767).

Signed-off-by: Madhavendra Rathore
Signed-off-by: Madhavendra Rathore <[email protected]>

This branch was previously deployed

1 inactive deployment
azure-prod — d3023f73 Deployed Apr 1, 2025 by jayantsing-db
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.

5 participants