Skip to content

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

Merged
gopalldb merged 30 commits into
mainfrom
gopalldb/uc-retry
Mar 30, 2025
Merged

gopalldb merged 30 commits into
mainfrom
gopalldb/uc-retry

Conversation

@gopalldb

@gopalldb gopalldb commented Mar 20, 2025 •

Copy link
Copy Markdown
Collaborator

Description

Add support for retry timeout for UC vol operations

Added custom retry strategy for UC Volume operations and added support for creating different HttpClients based on HttpClientType, a new enum, which can have following values:

  1. COMMON (all existing use cases)
  2. VOLUME (UC Volume operations)

Later this can be extended to use cases like Cloud fetch, Auth etc

Testing

Ran unit tests

Additional Notes to the Reviewer

@@ -23,12 +25,25 @@ public static DatabricksHttpClientFactory getInstance() {
}

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.

Do we need this class to be singleton? we can make it simpler

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.

required lots of class changes, also consistent with our other factory classes

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.

the name is a bit misleading. it is more like a container for all http client instances (per connection)

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.

True, it is misleading for other factories as well, like TelemetryClient factory. We can take this up in separate PR. Don't want to change scope of this PR.

long elapsedTime = Duration.between(startTime, Instant.now()).toMillis();
return elapsedTime <= connectionContext.getUCIngestionRetryTimeoutMinutes() * 60 * 1000L;
}

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 define a new retry handler for UC extending this class and override these methods instead of adding if conditions?

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.

done

@jayantsing-db jayantsing-db left a comment

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.

hi, lg with some minor comments inline.

however, major Question (couldn't find in description): what is the specific behaviour of this retry handler and why is it different from the normal retry of the same HTTP codes? and, do we absolutely need this difference for volume client?

i am asking this because for server-side-retry HTTP codes (429, etc.), i see no strong reason for why different modules should have different retry behaviour

@@ -23,12 +25,25 @@ public static DatabricksHttpClientFactory getInstance() {
}

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.

the name is a bit misleading. it is more like a container for all http client instances (per connection)

}

private static void sleepForDelay(long delayInSeconds) {
static void sleepForDelay(long delayInMillis) {

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.

do we need to modify the caller of this method to supply the delay in millis?

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.

delay was supplied in millis, but they were mutiplied by 1000 again, resulting in long wait as I observed from unit test. Fixed that now.

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.

can you perhaps pull the latest from main.. the issue here was that retryInterval is present and passed in seconds whereas exponential backoff is in millis, i fixed this in my PR

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.

done

@@ -0,0 +1,6 @@
package com.databricks.jdbc.dbclient.impl.http;

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.

i think a better place is com.databricks.jdbc.dbclient.impl.common package or com.databricks.jdbc.common package

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.

Done

@@ -0,0 +1,6 @@
package com.databricks.jdbc.dbclient.impl.http;

public enum HttpClientType {

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.

please add Javadoc and the expected usage of this enum.

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.

Done

Instant startTime = (Instant) httpContext.getAttribute(RETRY_START_TIME);
if (startTime == null) {
startTime = Instant.now();
httpContext.setAttribute(RETRY_START_TIME, startTime);

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.

nit: RETRY_START_TIME_KEY

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.

done

Comment on lines +26 to +49
/**
* Processes an HTTP response to handle retryable status codes and set up retry logic.
*
* <p>This method is responsible for examining the HTTP response, determining if it's retryable,
* and setting up the necessary context for potential retry attempts.
*
* @param httpResponse The HTTP response to be processed.
* @param httpContext The HTTP context associated with the request and response.
* @throws IOException If there's an issue processing the response.
* @throws DatabricksRetryHandlerException If the status code is retryable, triggering the retry
* mechanism.
* @implNote The method performs the following steps:
* <ul>
* <li>Checks if the status code is retryable.
* <li>Extracts the retry interval from the response for status codes 503 and 429.
* <li>Sets up the context state for retry logic.
* <li>Throws a {@code DatabricksRetryHandlerException} to trigger the retry mechanism,
* including relevant error information from the response.
* </ul>
*
* @implSpec This method adheres to the contract specified by its parent interface or class. It's
* designed to be called as part of the HTTP response handling pipeline.
* @see DatabricksRetryHandlerException
*/

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.

do we need to change the Javadoc to highlight what is different in this retry handler? For example:

{@inheritDoc}

<p>....(new Javadoc here)

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.

Done

Comment on lines +74 to +95
/**
* Determines whether a request should be retried after encountering an IOException.
*
* <p>This method implements retry strategy for HTTP requests for UC Volume operations,
* considering various factors such as status codes, retry intervals, and execution counts.
*
* @param exception The IOException encountered during the request execution.
* @param executionCount The number of times this request has been executed.
* @param context The HttpContext containing attributes related to the request and retry logic.
* @return boolean True if the request should be retried, false otherwise.
* @throws RuntimeException If an invalid retry interval is found in the context for status codes
* 503 (Service Unavailable) or 429 (Too Many Requests).
* @implNote The method performs the following checks:
* <ul>
* <li>Verifies if the status code is retryable.
* </ul>
* If all checks pass, the method updates retry counters, calculates a delay, and sleeps for
* the calculated duration before allowing a retry.
* @see #isRequestMethodRetryable(String)
* @see #calculateDelay(int, int, int)
* @see #sleepForDelay(long)
*/

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.

do we need to change the Javadoc to highlight what is different in this method from the parent class? For example:

{@inheritDoc}

<p>....(new Javadoc here)

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.

Done

Comment on lines +114 to +115
long elapsedTime = Duration.between(startTime, Instant.now()).toMillis();
return elapsedTime <= connectionContext.getUCIngestionRetryTimeoutMinutes() * 60 * 1000L;

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.

please add comments or Javadoc

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.

done

@gopalldb

Copy link
Copy Markdown
Collaborator Author

hi, lg with some minor comments inline.

however, major Question (couldn't find in description): what is the specific behaviour of this retry handler and why is it different from the normal retry of the same HTTP codes? and, do we absolutely need this difference for volume client?

i am asking this because for server-side-retry HTTP codes (429, etc.), i see no strong reason for why different modules should have different retry behaviour

UC volume operations has much longer timeouts, the http error codes can also be different and we need to support separate codes and handling for parity with existing driver.

retryHandler =
type.equals(HttpClientType.COMMON)
? new DatabricksHttpRetryHandler(connectionContext)
: new UCVolumeHttpRetryHandler(connectionContext);

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.

we made a improvements to our common HTTP retry logic recently (#764), is it possible to use that, along with the new connectionContext parameters? This is because we need to test out 2 different HTTPRetry strategies now.

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.

We will still need some different handlingne for UC Volume opns. I have merged changes from that PR as well, and we reuse many common methods from the common retry handler.

@VisibleForTesting
protected void doSleepForDelay(long delayMillis) {
try {

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.

remove empty line

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.

done

@@ -0,0 +1,6 @@
package com.databricks.jdbc.common;

public enum HttpClientType {

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.

can we add javadoc?

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.

done

assertEquals(0, httpContext.getAttribute(RETRY_INTERVAL_KEY));
}

@Test

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.

Can we create a new test class corresponding to UCVolumeHttpRetryHandler and move tests there?

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.

I think, this is test class only. As we reuse so many common setup here, reusing the same test class should be fine.

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.

Refactored the test class into separate volume specific file

IOException exception = new DatabricksRetryHandlerException("Test", HttpStatus.SC_BAD_REQUEST);
assertTrue(retryHandler.retryRequest(exception, 1, httpContext));
}

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.

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.

Added test for multi-attempt timeout.

@gopalldb
gopalldb merged commit 314ae81 into databricks:main Mar 30, 2025
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]>

This branch had an error being deployed

1 failed deployment
azure-prod — af7f944f Deployed Mar 30, 2025 by gopalldb
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.

4 participants