public final class CosmosRetryPolicy extends Object implements com.datastax.oss.driver.api.core.retry.RetryPolicy
RetryPolicy implementation with back-offs for OverloadedException failures.
This is the default retry policy when you take a dependency on azure-cosmos-cassandra-driver-4-extensions. It
provides a good out-of-box experience for communicating with Cosmos Cassandra API instances. Its behavior is
specified in configuration:
datastax-java-driver.advanced.retry-policy {
max-retries = 5 # Maximum number of retries.
fixed-backoff-time = 5000 # Fixed backoff time in milliseconds.
growing-backoff-time = 1000 # Growing backoff time in milliseconds.
read-timeout-retries = true # Whether retries on read timeouts are enabled. Disabling read timeouts may be
# desirable when Cosmos Cassandra API server-side retries are enabled.
write-timeout-retries = true # Whether retries on write timeouts are enabled. Disabling write timeouts may be
# desirable when Cosmos Cassandra API server-side retries are enabled.
}
The number of retries that should be attempted is specified by max-retries. A value of -1 indicates
that an indefinite number of retries should be attempted.
Retry decisions by onErrorResponse(com.datastax.oss.driver.api.core.session.Request, com.datastax.oss.driver.api.core.servererrors.CoordinatorException, int) may be delayed. Delays are triggered in response to OverloadedException errors. The delay time is extracted from the error message, or—if the delay time isn't
present in the error message—computed as follows:
this.maxRetryCount == -1
? fixedBackOffTimeInMillis
: retryCount * growingBackOffTimeInMillis + saltValue;
There are no other uses for fixed-backoff-time and growing-backoff-time. Retry decisions are returned
immediately in all other cases. There is no delay in returning from any method but one: onErrorResponse(com.datastax.oss.driver.api.core.session.Request, com.datastax.oss.driver.api.core.servererrors.CoordinatorException, int) when
it receives an OverloadedException error.
| Constructor and Description |
|---|
CosmosRetryPolicy(com.datastax.oss.driver.api.core.context.DriverContext driverContext,
String profileName)
Initializes a newly created
CosmosRetryPolicy object from configuration. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the current
CosmosRetryPolicy. |
int |
getFixedBackOffTimeInMillis()
Gets the
fixed-backoff-time specified by this CosmosRetryPolicy object. |
int |
getGrowingBackOffTimeInMillis()
Gets the
growing-backoff-time specified by this CosmosRetryPolicy object. |
int |
getMaxRetryCount()
Gets the
max-retries value specified by this CosmosRetryPolicy object. |
boolean |
isReadTimeoutRetriesEnabled()
Gets the
retry-read-timeouts value specified by this CosmosRetryPolicy object. |
boolean |
isWriteTimeoutRetriesEnabled()
Gets the
retry-write-timeouts value specified by this CosmosRetryPolicy object. |
com.datastax.oss.driver.api.core.retry.RetryDecision |
onErrorResponse(com.datastax.oss.driver.api.core.session.Request request,
com.datastax.oss.driver.api.core.servererrors.CoordinatorException error,
int retryCount)
Returns a retry decision in response to a recoverable error other than READ_TIMEOUT, WRITE_TIMEOUT or
UNAVAILABLE.
|
com.datastax.oss.driver.api.core.retry.RetryDecision |
onReadTimeout(com.datastax.oss.driver.api.core.session.Request request,
com.datastax.oss.driver.api.core.ConsistencyLevel consistencyLevel,
int blockFor,
int received,
boolean dataPresent,
int retryCount)
Returns a
retry-same or RetryDecision.RETHROW decision in response to
a read timeout error. |
com.datastax.oss.driver.api.core.retry.RetryDecision |
onRequestAborted(com.datastax.oss.driver.api.core.session.Request request,
Throwable error,
int retryCount)
Returns a
retry-same or RetryDecision.RETHROW decision when a request is
aborted before a response is received. |
com.datastax.oss.driver.api.core.retry.RetryDecision |
onUnavailable(com.datastax.oss.driver.api.core.session.Request request,
com.datastax.oss.driver.api.core.ConsistencyLevel consistencyLevel,
int required,
int alive,
int retryCount)
Returns a
retry-same or RetryDecision.RETHROW decision in response to an
UNAVAILABLE error. |
com.datastax.oss.driver.api.core.retry.RetryDecision |
onWriteTimeout(com.datastax.oss.driver.api.core.session.Request request,
com.datastax.oss.driver.api.core.ConsistencyLevel consistencyLevel,
com.datastax.oss.driver.api.core.servererrors.WriteType writeType,
int blockFor,
int received,
int retryCount)
Returns a
retry-same or rethrow decision in
response to a write timeout error. |
String |
toString() |
public CosmosRetryPolicy(com.datastax.oss.driver.api.core.context.DriverContext driverContext,
String profileName)
CosmosRetryPolicy object from configuration.driverContext - an object holding the context of the current driver instance.profileName - name of the configuration profile to apply.public int getFixedBackOffTimeInMillis()
fixed-backoff-time specified by this CosmosRetryPolicy object.fixed-backoff-time specified by this CosmosRetryPolicy object.public int getGrowingBackOffTimeInMillis()
growing-backoff-time specified by this CosmosRetryPolicy object.growing-backoff-time specified by this CosmosRetryPolicy object.public int getMaxRetryCount()
max-retries value specified by this CosmosRetryPolicy object.
A value of -1 indicates that an indefinite number of retries should be attempted.
max-retries value specified by this CosmosRetryPolicy object.public boolean isReadTimeoutRetriesEnabled()
retry-read-timeouts value specified by this CosmosRetryPolicy object.
This value indicates whether read timeouts are enabled.
retry-read-timeouts value specified by this CosmosRetryPolicy object.public boolean isWriteTimeoutRetriesEnabled()
retry-write-timeouts value specified by this CosmosRetryPolicy object.
This value indicates whether write timeouts are enabled.
retry-write-timeouts value specified by this CosmosRetryPolicy object.public void close()
CosmosRetryPolicy.close in interface com.datastax.oss.driver.api.core.retry.RetryPolicyclose in interface AutoCloseablepublic com.datastax.oss.driver.api.core.retry.RetryDecision onErrorResponse(@NonNull
com.datastax.oss.driver.api.core.session.Request request,
@NonNull
com.datastax.oss.driver.api.core.servererrors.CoordinatorException error,
int retryCount)
Recoverable errors are represented by these exception types:
OverloadedException,ServerError,TruncateException,ReadFailureException, andWriteFailureException.The following errors are handled internally by the driver, and therefore will never be encountered by this method:
BootstrappingException is always retried on the next node;QueryValidationException (and its subclasses),FunctionFailureException, andProtocolError: always rethrown.idempotent requests. When
execution was aborted before getting a response, it is impossible to determine with 100% certainty whether a
mutation was applied or not, so a write is never safe to retry; the driver will rethrow the error directly,
without invoking the retry policy.onErrorResponse in interface com.datastax.oss.driver.api.core.retry.RetryPolicyrequest - The request that failed.error - The error received.retryCount - The current retry count.RetryDecision based on error and retryCount:
Retry on the same node, if an OverloadedException or
WriteFailureException is received and the retryCount is less than getMaxRetryCount();
RetryDecision.RETHROW otherwise.
When retrying, this method pauses for the duration of the retry interval extracted from
error message or--if there is no retry interval in the error
message--as computed from the options specified for this RetryPolicy. If
getMaxRetryCount()
retryAfterMillis = this.getFixedBackOffTimeInMillis()
+ retryCount * this.getGrowingBackOffTime()
+ RANDOM.nextInt(GROWING_BACKOFF_SALT_IN_MILLIS)
Or, if getMaxRetryCount() is -1:
this.getFixedBackOffTimeInMillis();
public com.datastax.oss.driver.api.core.retry.RetryDecision onReadTimeout(@NonNull
com.datastax.oss.driver.api.core.session.Request request,
@NonNull
com.datastax.oss.driver.api.core.ConsistencyLevel consistencyLevel,
int blockFor,
int received,
boolean dataPresent,
int retryCount)
retry-same or RetryDecision.RETHROW decision in response to
a read timeout error.
Retries on read timeouts can be disabled by setting CosmosRetryPolicyOption.READ_TIMEOUT_RETRIES to
false:
datastax-java-driver.advanced.retry-policy.retry-write-timeouts = false
Disabling retries for read timeouts may be desirable when Cosmos DB server-side retries are enabled.onReadTimeout in interface com.datastax.oss.driver.api.core.retry.RetryPolicyrequest - The request that failed.consistencyLevel - The consistency level of the request that failed.blockFor - The minimum number of replica acknowledgements/responses that were required to fulfill
the operation.received - The number of replica acknowledgements/responses to the operation before it failed.dataPresent - Whether the actual data was amongst the received replica responses. See ReadTimeoutException.wasDataPresent().retryCount - The current retry count.retry to the same node, if the number of replica
acknowledgements/responses received before the operation failed (the value of received) is greater than
or equal to the minimum number of replica acknowledgements/responses required to fulfill the operation (the value
of blockFor), data was not retrieved (dataPresent: false}, and only if retries on read timeouts
are enabled (the default). Otherwise, a rethrow decision is returned.public com.datastax.oss.driver.api.core.retry.RetryDecision onRequestAborted(@NonNull
com.datastax.oss.driver.api.core.session.Request request,
@NonNull
Throwable error,
int retryCount)
retry-same or RetryDecision.RETHROW decision when a request is
aborted before a response is received.
This can happen in two cases:
ClosedConnectionException
(network failure) or a HeartbeatException (missed heartbeat); orThis method is only invoked for idempotent statements.
onRequestAborted in interface com.datastax.oss.driver.api.core.retry.RetryPolicyrequest - The request that failed.error - The error received.retryCount - The current retry count.retry-same decision, if a ClosedConnectionException or
HeartbeatException is received and retryCount is less than getMaxRetryCount(); otherwise,
a rethrow decision.public com.datastax.oss.driver.api.core.retry.RetryDecision onUnavailable(@NonNull
com.datastax.oss.driver.api.core.session.Request request,
@NonNull
com.datastax.oss.driver.api.core.ConsistencyLevel consistencyLevel,
int required,
int alive,
int retryCount)
retry-same or RetryDecision.RETHROW decision in response to an
UNAVAILABLE error.onUnavailable in interface com.datastax.oss.driver.api.core.retry.RetryPolicyrequest - The request that failed.consistencyLevel - The consistency level of the request that failed.required - The number of replica acknowledgements/responses required to perform the operation given
its consistencyLevel.alive - The number of replicas that were known to be alive by the coordinator node when it tried
to execute the operation.retryCount - The current retry count.retry-same decision, if retryCount is less than the
getMaxRetryCount().public com.datastax.oss.driver.api.core.retry.RetryDecision onWriteTimeout(@NonNull
com.datastax.oss.driver.api.core.session.Request request,
@NonNull
com.datastax.oss.driver.api.core.ConsistencyLevel consistencyLevel,
@NonNull
com.datastax.oss.driver.api.core.servererrors.WriteType writeType,
int blockFor,
int received,
int retryCount)
retry-same or rethrow decision in
response to a write timeout error.
This method is only invoked for idempotent statements. It is similar to {link #onReadTimeout}, but for write operations.
Retries on write timeouts can be disabled by setting CosmosRetryPolicyOption.WRITE_TIMEOUT_RETRIES to
false:
datastax-java-driver.advanced.retry-policy.retry-write-timeouts = false
Disabling retries for write timeouts may be desirable when Cosmos DB server-side retries are enabled.onWriteTimeout in interface com.datastax.oss.driver.api.core.retry.RetryPolicyrequest - The request that failed.consistencyLevel - The consistency level of the request that failed.writeType - The kind of write query.blockFor - The minimum number of replica acknowledgements/responses that were required to fulfill
the operation.received - The number of replica acknowledgements/responses to the operation before it failed.retryCount - The current retry count.retry to the same node, and only for
batch log operations, if and only if retries on write-timeouts are enabled (the
default). Otherwise, a rethrow decision is returned.Copyright © 2021. All rights reserved.