public interface RetryPolicy extends AutoCloseable
For each request, the driver gets a "query plan" (a list of coordinators to try) from the
LoadBalancingPolicy
, and tries each node in sequence. This policy is invoked if the
request to that node fails.
Modifier and Type | Method and Description |
---|---|
void |
close()
Called when the cluster that this policy is associated with closes.
|
RetryDecision |
onErrorResponse(Request request,
CoordinatorException error,
int retryCount)
Whether to retry when the server replied with a recoverable error (other than
READ_TIMEOUT , WRITE_TIMEOUT or UNAVAILABLE ). |
RetryDecision |
onReadTimeout(Request request,
ConsistencyLevel cl,
int blockFor,
int received,
boolean dataPresent,
int retryCount)
Whether to retry when the server replied with a
READ_TIMEOUT error; this indicates a
server-side timeout during a read query, i.e. |
RetryDecision |
onRequestAborted(Request request,
Throwable error,
int retryCount)
Whether to retry when a request was aborted before we could get a response from the server.
|
RetryDecision |
onUnavailable(Request request,
ConsistencyLevel cl,
int required,
int alive,
int retryCount)
Whether to retry when the server replied with an
UNAVAILABLE error; this indicates that
the coordinator determined that there were not enough replicas alive to perform a query with
the requested consistency level. |
RetryDecision |
onWriteTimeout(Request request,
ConsistencyLevel cl,
WriteType writeType,
int blockFor,
int received,
int retryCount)
Whether to retry when the server replied with a
WRITE_TIMEOUT error; this indicates a
server-side timeout during a write query, i.e. |
RetryDecision onReadTimeout(@NonNull Request request, @NonNull ConsistencyLevel cl, int blockFor, int received, boolean dataPresent, int retryCount)
READ_TIMEOUT
error; this indicates a
server-side timeout during a read query, i.e. some replicas did not reply to the
coordinator in time.request
- the request that timed out.cl
- the requested consistency level.blockFor
- the minimum number of replica acknowledgements/responses that were required to
fulfill the operation.received
- the number of replica that had acknowledged/responded to the operation before
it failed.dataPresent
- whether the actual data was amongst the received replica responses. See
ReadTimeoutException.wasDataPresent()
.retryCount
- how many times the retry policy has been invoked already for this request
(not counting the current invocation).RetryDecision onWriteTimeout(@NonNull Request request, @NonNull ConsistencyLevel cl, @NonNull WriteType writeType, int blockFor, int received, int retryCount)
WRITE_TIMEOUT
error; this indicates a
server-side timeout during a write query, i.e. some replicas did not reply to the
coordinator in time.
Note that this method will only be invoked for Request.isIdempotent()
idempotent}
requests: when a write times out, it is impossible to determine with 100% certainty whether the
mutation was applied or not, so the write is never safe to retry; the driver will rethrow the
error directly, without invoking the retry policy.
request
- the request that timed out.cl
- the requested consistency level.writeType
- the type of the write for which the timeout was raised.blockFor
- the minimum number of replica acknowledgements/responses that were required to
fulfill the operation.received
- the number of replica that had acknowledged/responded to the operation before
it failed.retryCount
- how many times the retry policy has been invoked already for this request
(not counting the current invocation).RetryDecision onUnavailable(@NonNull Request request, @NonNull ConsistencyLevel cl, int required, int alive, int retryCount)
UNAVAILABLE
error; this indicates that
the coordinator determined that there were not enough replicas alive to perform a query with
the requested consistency level.request
- the request that timed out.cl
- the requested consistency level.required
- the number of replica acknowledgements/responses required to perform the
operation (with its required consistency level).alive
- the number of replicas that were known to be alive by the coordinator node when it
tried to execute the operation.retryCount
- how many times the retry policy has been invoked already for this request
(not counting the current invocation).RetryDecision onRequestAborted(@NonNull Request request, @NonNull Throwable error, int retryCount)
This can happen in two cases: if the connection was closed due to an external event (this
will manifest as a ClosedConnectionException
, or HeartbeatException
for a
heartbeat failure); or if there was an unexpected error while decoding the response (this can
only be a driver bug).
Note that this method will only be invoked for Request.isIdempotent()
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.
request
- the request that was aborted.error
- the error.retryCount
- how many times the retry policy has been invoked already for this request
(not counting the current invocation).RetryDecision onErrorResponse(@NonNull Request request, @NonNull CoordinatorException error, int retryCount)
READ_TIMEOUT
, WRITE_TIMEOUT
or UNAVAILABLE
).
This can happen for the following errors: OverloadedException
, ServerError
,
TruncateException
, ReadFailureException
, WriteFailureException
.
The following errors are handled internally by the driver, and therefore will never be encountered in this method:
BootstrappingException
: always retried on the next node;
QueryValidationException
(and its subclasses), FunctionFailureException
and ProtocolError
: always rethrown.
Note that this method will only be invoked for Request.isIdempotent()
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.
request
- the request that failed.error
- the error.retryCount
- how many times the retry policy has been invoked already for this request
(not counting the current invocation).void close()
close
in interface AutoCloseable
Copyright © 2017–2018. All rights reserved.