com.datastax.driver.core.policies
Class DefaultRetryPolicy

java.lang.Object
  extended by com.datastax.driver.core.policies.DefaultRetryPolicy
All Implemented Interfaces:
RetryPolicy

public class DefaultRetryPolicy
extends Object
implements RetryPolicy

The default retry policy.

This policy retries queries in only two cases:

This retry policy is conservative in that it will never retry with a different consistency level than the one of the initial operation.

In some cases, it may be convenient to use a more aggressive retry policy like DowngradingConsistencyRetryPolicy.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.datastax.driver.core.policies.RetryPolicy
RetryPolicy.RetryDecision
 
Field Summary
static DefaultRetryPolicy INSTANCE
           
 
Method Summary
 RetryPolicy.RetryDecision onReadTimeout(Query query, 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 onUnavailable(Query query, ConsistencyLevel cl, int requiredReplica, int aliveReplica, int nbRetry)
          Defines whether to retry and at which consistency level on an unavailable exception.
 RetryPolicy.RetryDecision onWriteTimeout(Query query, ConsistencyLevel cl, WriteType writeType, int requiredAcks, int receivedAcks, int nbRetry)
          Defines whether to retry and at which consistency level on a write timeout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE

public static final DefaultRetryPolicy INSTANCE
Method Detail

onReadTimeout

public RetryPolicy.RetryDecision onReadTimeout(Query query,
                                               ConsistencyLevel cl,
                                               int requiredResponses,
                                               int receivedResponses,
                                               boolean dataRetrieved,
                                               int nbRetry)
Defines whether to retry and at which consistency level on a read timeout.

This method triggers a maximum of one retry, and only if enough replica had responded to the read request but data was not retrieved amongst those. Indeed, that case usually means that enough replica are alive to satisfy the consistency but the coordinator picked a dead one for data retrieval, not having detected that replica as dead yet. The reasoning for retrying then is that by the time we get the timeout the dead replica will likely have been detected as dead and the retry has a high change of success.

Specified by:
onReadTimeout in interface RetryPolicy
Parameters:
query - the original query that timeouted.
cl - the original consistency level of the read that timeouted.
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 retry already performed for this operation.
Returns:
RetryDecision.retry(cl) if no retry attempt has yet been tried and receivedResponses >= requiredResponses && !dataRetrieved, RetryDecision.rethrow() otherwise.

onWriteTimeout

public RetryPolicy.RetryDecision onWriteTimeout(Query query,
                                                ConsistencyLevel cl,
                                                WriteType writeType,
                                                int requiredAcks,
                                                int receivedAcks,
                                                int nbRetry)
Defines whether to retry and at which consistency level on a write timeout.

This method triggers a maximum of one retry, and only in the case of a 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 node 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 change of success.

Specified by:
onWriteTimeout in interface RetryPolicy
Parameters:
query - the original query that timeouted.
cl - the original consistency level of the write that timeouted.
writeType - the type of the write that timeouted.
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.
Returns:
RetryDecision.retry(cl) if no retry attempt has yet been tried and writeType == WriteType.BATCH_LOG, RetryDecision.rethrow() otherwise.

onUnavailable

public RetryPolicy.RetryDecision onUnavailable(Query query,
                                               ConsistencyLevel cl,
                                               int requiredReplica,
                                               int aliveReplica,
                                               int nbRetry)
Defines whether to retry and at which consistency level on an unavailable exception.

This method never retries as a retry on an unavailable exception using the same consistency level has almost no change of success.

Specified by:
onUnavailable in interface RetryPolicy
Parameters:
query - 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.
Returns:
RetryDecision.rethrow().


Copyright © 2013. All Rights Reserved.