public class DefaultRetryPolicy extends Object implements RetryPolicy
DowngradingConsistencyRetryPolicy
.RetryPolicy.RetryDecision
Modifier and Type | Field and Description |
---|---|
static DefaultRetryPolicy |
INSTANCE |
Modifier and Type | Method and Description |
---|---|
void |
close()
Gets invoked at cluster shutdown.
|
void |
init(Cluster cluster)
Gets invoked at cluster startup.
|
RetryPolicy.RetryDecision |
onReadTimeout(Statement statement,
ConsistencyLevel cl,
int requiredResponses,
int receivedResponses,
boolean dataRetrieved,
int nbRetry)
Defines whether to retry and at which consistency level on a read timeout.
|
RetryPolicy.RetryDecision |
onRequestError(Statement statement,
ConsistencyLevel cl,
DriverException e,
int nbRetry)
Defines whether to retry and at which consistency level on an
unexpected error.
|
RetryPolicy.RetryDecision |
onUnavailable(Statement statement,
ConsistencyLevel cl,
int requiredReplica,
int aliveReplica,
int nbRetry)
Defines whether to retry and at which consistency level on an
unavailable exception.
|
RetryPolicy.RetryDecision |
onWriteTimeout(Statement statement,
ConsistencyLevel cl,
WriteType writeType,
int requiredAcks,
int receivedAcks,
int nbRetry)
Defines whether to retry and at which consistency level on a write timeout.
|
public static final DefaultRetryPolicy INSTANCE
public RetryPolicy.RetryDecision onReadTimeout(Statement statement, ConsistencyLevel cl, int requiredResponses, int receivedResponses, boolean dataRetrieved, int nbRetry)
onReadTimeout
in interface RetryPolicy
statement
- the original query that timed out.cl
- the original consistency level of the read that timed out.requiredResponses
- the number of responses that were required to
achieve the requested consistency level.receivedResponses
- the number of responses that had been received
by the time the timeout exception was raised.dataRetrieved
- whether actual data (by opposition to data checksum)
was present in the received responses.nbRetry
- the number of retries already performed for this operation.RetryDecision.retry(cl)
if no retry attempt has yet been tried and
receivedResponses >= requiredResponses && !dataRetrieved
, RetryDecision.rethrow()
otherwise.public RetryPolicy.RetryDecision onWriteTimeout(Statement statement, ConsistencyLevel cl, WriteType writeType, int requiredAcks, int receivedAcks, int nbRetry)
WriteType.BATCH_LOG
write. The reasoning for the retry in
that case is that write to the distributed batch log is tried by the
coordinator of the write against a small subset of all the nodes alive
in the local datacenter. Hence, a timeout usually means that none of
the nodes in that subset were alive but the coordinator hasn't
detected them as dead. By the time we get the timeout the dead
nodes will likely have been detected as dead and the retry has thus a
high chance of success.onWriteTimeout
in interface RetryPolicy
statement
- the original query that timed out.cl
- the original consistency level of the write that timed out.writeType
- the type of the write that timed out.requiredAcks
- the number of acknowledgments that were required to
achieve the requested consistency level.receivedAcks
- the number of acknowledgments that had been received
by the time the timeout exception was raised.nbRetry
- the number of retry already performed for this operation.RetryDecision.retry(cl)
if no retry attempt has yet been tried and
writeType == WriteType.BATCH_LOG
, RetryDecision.rethrow()
otherwise.public RetryPolicy.RetryDecision onUnavailable(Statement statement, ConsistencyLevel cl, int requiredReplica, int aliveReplica, int nbRetry)
RetryDecision.tryNextHost(cl)
,
otherwise it throws an exception. The retry will be processed on the next host
in the query plan according to the current Load Balancing Policy.
Where retrying on the same host in the event of an Unavailable exception
has almost no chance of success, if the first replica tried happens to
be "network" isolated from all the other nodes but can still answer to
the client, it makes sense to retry the query on another node.onUnavailable
in interface RetryPolicy
statement
- the original query for which the consistency level cannot
be achieved.cl
- the original consistency level for the operation.requiredReplica
- the number of replica that should have been
(known) alive for the operation to be attempted.aliveReplica
- the number of replica that were know to be alive by
the coordinator of the operation.nbRetry
- the number of retry already performed for this operation.RetryDecision.rethrow()
.public RetryPolicy.RetryDecision onRequestError(Statement statement, ConsistencyLevel cl, DriverException e, int nbRetry)
SocketOptions.getReadTimeoutMillis()
);OVERLOADED
, IS_BOOTSTRAPPING
, SERVER_ERROR
, etc.RetryPolicy.onRequestError(Statement, ConsistencyLevel, DriverException, int)
:
"a retry should only be attempted if the request is known to be idempotent".onRequestError
in interface RetryPolicy
statement
- the original query that failed.cl
- the original consistency level for the operation.e
- the exception that caused this request to fail.nbRetry
- the number of retries already performed for this operation.RetryDecision.RETHROW
is returned,
the DriverException
passed to this method will be thrown for the operation.public void init(Cluster cluster)
RetryPolicy
init
in interface RetryPolicy
cluster
- the cluster that this policy is associated with.public void close()
RetryPolicy
close
in interface RetryPolicy