Repository navigation
[PECOBLR-182] Add support for retry timeout for UC vol operations - #760
Conversation
| @@ -23,12 +25,25 @@ public static DatabricksHttpClientFactory getInstance() { | |||
| } | |||
There was a problem hiding this comment.
Do we need this class to be singleton? we can make it simpler
There was a problem hiding this comment.
required lots of class changes, also consistent with our other factory classes
There was a problem hiding this comment.
the name is a bit misleading. it is more like a container for all http client instances (per connection)
There was a problem hiding this comment.
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; | ||
| } | ||
|
|
There was a problem hiding this comment.
should we define a new retry handler for UC extending this class and override these methods instead of adding if conditions?
jayantsing-db
left a comment
There was a problem hiding this comment.
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() { | |||
| } | |||
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
do we need to modify the caller of this method to supply the delay in millis?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
| @@ -0,0 +1,6 @@ | |||
| package com.databricks.jdbc.dbclient.impl.http; | |||
There was a problem hiding this comment.
i think a better place is com.databricks.jdbc.dbclient.impl.common package or com.databricks.jdbc.common package
| @@ -0,0 +1,6 @@ | |||
| package com.databricks.jdbc.dbclient.impl.http; | |||
|
|
|||
| public enum HttpClientType { | |||
There was a problem hiding this comment.
please add Javadoc and the expected usage of this enum.
| Instant startTime = (Instant) httpContext.getAttribute(RETRY_START_TIME); | ||
| if (startTime == null) { | ||
| startTime = Instant.now(); | ||
| httpContext.setAttribute(RETRY_START_TIME, startTime); |
There was a problem hiding this comment.
nit: RETRY_START_TIME_KEY
| /** | ||
| * 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 | ||
| */ |
There was a problem hiding this comment.
do we need to change the Javadoc to highlight what is different in this retry handler? For example:
{@inheritDoc}
<p>....(new Javadoc here)
| /** | ||
| * 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) | ||
| */ |
There was a problem hiding this comment.
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)
| long elapsedTime = Duration.between(startTime, Instant.now()).toMillis(); | ||
| return elapsedTime <= connectionContext.getUCIngestionRetryTimeoutMinutes() * 60 * 1000L; |
There was a problem hiding this comment.
please add comments or Javadoc
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { | ||
|
|
| @@ -0,0 +1,6 @@ | |||
| package com.databricks.jdbc.common; | |||
|
|
|||
| public enum HttpClientType { | |||
There was a problem hiding this comment.
can we add javadoc?
| assertEquals(0, httpContext.getAttribute(RETRY_INTERVAL_KEY)); | ||
| } | ||
|
|
||
| @Test |
There was a problem hiding this comment.
Can we create a new test class corresponding to UCVolumeHttpRetryHandler and move tests there?
There was a problem hiding this comment.
I think, this is test class only. As we reuse so many common setup here, reusing the same test class should be fine.
There was a problem hiding this comment.
Refactored the test class into separate volume specific file
| IOException exception = new DatabricksRetryHandlerException("Test", HttpStatus.SC_BAD_REQUEST); | ||
| assertTrue(retryHandler.retryRequest(exception, 1, httpContext)); | ||
| } | ||
|
|
There was a problem hiding this comment.
Can we also add tests like these to ensure that retries are happening as expected and stopping when expect? https://github.com/databricks/databricks-jdbc/pull/760/files?w=1#diff-7ffb48e2b3431cec1225a14888b04d0d59989696fd2545d610362bf02debfb22R113
There was a problem hiding this comment.
Added test for multi-attempt timeout.
* [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]>
* [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]>
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:
Later this can be extended to use cases like Cloud fetch, Auth etc
Testing
Ran unit tests
Additional Notes to the Reviewer