Class DatabricksHttpRetryHandler
- java.lang.Object
-
- com.databricks.jdbc.dbclient.impl.http.DatabricksHttpRetryHandler
-
- All Implemented Interfaces:
org.apache.http.client.HttpRequestRetryHandler,org.apache.http.HttpResponseInterceptor
- Direct Known Subclasses:
UCVolumeHttpRetryHandler
public class DatabricksHttpRetryHandler extends Object implements org.apache.http.HttpResponseInterceptor, org.apache.http.client.HttpRequestRetryHandler
-
-
Constructor Summary
Constructors Constructor Description DatabricksHttpRetryHandler(IDatabricksConnectionContext connectionContext)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoSleepForDelay(long delayMillis)voidprocess(org.apache.http.HttpResponse httpResponse, org.apache.http.protocol.HttpContext httpContext)Processes an HTTP response to handle retryable status codes and set up retry logic.booleanretryRequest(IOException exception, int executionCount, org.apache.http.protocol.HttpContext context)Determines whether a request should be retried after encountering an IOException.
-
-
-
Constructor Detail
-
DatabricksHttpRetryHandler
public DatabricksHttpRetryHandler(IDatabricksConnectionContext connectionContext)
-
-
Method Detail
-
process
public void process(org.apache.http.HttpResponse httpResponse, org.apache.http.protocol.HttpContext httpContext) throws IOExceptionProcesses an HTTP response to handle retryable status codes and set up retry logic.This method is responsible for examining the HTTP response, determining if it's retryable, and setting up the necessary context for potential retry attempts.
- Specified by:
processin interfaceorg.apache.http.HttpResponseInterceptor- Parameters:
httpResponse- The HTTP response to be processed.httpContext- The HTTP context associated with the request and response.- Throws:
IOException- If there's an issue processing the response.DatabricksRetryHandlerException- If the status code is retryable, triggering the retry mechanism.Implementation note: The method performs the following steps:
- Checks if the status code is retryable.
- Extracts the retry interval from the response for status codes 503 and 429.
- Sets up the context state for retry logic.
- Throws a
DatabricksRetryHandlerExceptionto trigger the retry mechanism, including relevant error information from the response.
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 Also:
isStatusCodeRetryable(int),initializeRetryAccumulatedTimeIfNotExist(HttpContext),DatabricksRetryHandlerException
-
retryRequest
public boolean retryRequest(IOException exception, int executionCount, org.apache.http.protocol.HttpContext context)
Determines whether a request should be retried after encountering an IOException.This method implements a comprehensive retry strategy for HTTP requests, considering various factors such as status codes, retry intervals, and execution counts.
- Specified by:
retryRequestin interfaceorg.apache.http.client.HttpRequestRetryHandler- Parameters:
exception- The IOException encountered during the request execution.executionCount- The number of times this request has been executed.context- The HttpContext containing attributes related to the request and retry logic.- Returns:
- 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).Implementation note: The method performs the following checks:
- Verifies if the status code is retryable.
- Checks the validity of retry intervals for specific status codes.
- Ensures retry timeouts haven't been exceeded for temporary unavailability (503) and rate limiting (429).
- Verifies that the execution count hasn't exceeded the maximum allowed retries.
- Confirms that the HTTP method of the request is retryable.
- See Also:
isStatusCodeRetryable(int),isRequestMethodRetryable(String),calculateDelayInMillis(int, int, int),doSleepForDelay(long)
-
doSleepForDelay
protected void doSleepForDelay(long delayMillis)
-
-