public class LoggingRetryPolicy extends Object implements ExtendedRetryPolicy
RETRY
and
IGNORE
decisions (since
RETHROW
decisions
are just meant to propagate the Cassandra exception).
The logging is done at the INFO level and the logger name is
com.datastax.driver.core.policies.LoggingRetryPolicy
.RetryPolicy.RetryDecision
Constructor and Description |
---|
LoggingRetryPolicy(RetryPolicy policy)
Creates a new
RetryPolicy that logs the decision of policy . |
Modifier and Type | Method and Description |
---|---|
protected void |
logDecision(String template,
Object... parameters)
Logs the decision according to the given template and parameters.
|
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,
Exception 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 LoggingRetryPolicy(RetryPolicy policy)
RetryPolicy
that logs the decision of policy
.policy
- the policy to wrap. The policy created by this constructor
will return the same decision than policy
but will log them.public RetryPolicy.RetryDecision onReadTimeout(Statement statement, ConsistencyLevel cl, int requiredResponses, int receivedResponses, boolean dataRetrieved, int nbRetry)
RetryPolicy
requiredResponses >= receivedResponses
if dataPresent
is
false
(see
ReadTimeoutException.wasDataRetrieved()
).onReadTimeout
in interface RetryPolicy
statement
- the original query that timed out.cl
- the requested consistency level of the read that timed out.
Note that this can never be a serial
consistency level.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.RetryDecision.RETHROW
is returned,
a ReadTimeoutException
will
be thrown for the operation.public RetryPolicy.RetryDecision onWriteTimeout(Statement statement, ConsistencyLevel cl, WriteType writeType, int requiredAcks, int receivedAcks, int nbRetry)
RetryPolicy
onWriteTimeout
in interface RetryPolicy
statement
- the original query that timed out.cl
- the requested consistency level of the write that timed out.
If the timeout occurred at the "paxos" phase of a
Lightweight transaction,
then cl
will actually be the requested serial
consistency level.
Beware that serial consistency levels should never be passed to a RetryDecision
as this would
invariably trigger an InvalidQueryException
.
Also, when cl
is serial
, then writeType
is always CAS
.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.RETHROW
is returned,
a WriteTimeoutException
will
be thrown for the operation.public RetryPolicy.RetryDecision onUnavailable(Statement statement, ConsistencyLevel cl, int requiredReplica, int aliveReplica, int nbRetry)
RetryPolicy
onUnavailable
in interface RetryPolicy
statement
- the original query for which the consistency level cannot
be achieved.cl
- the requested consistency level for the operation.
If the operation failed at the "paxos" phase of a
Lightweight transaction,
then cl
will actually be the requested serial
consistency level.
Beware that serial consistency levels should never be passed to a RetryDecision
as this would
invariably trigger an InvalidQueryException
.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
is returned,
an UnavailableException
will
be thrown for the operation.public RetryPolicy.RetryDecision onRequestError(Statement statement, ConsistencyLevel cl, Exception e, int nbRetry)
ExtendedRetryPolicy
SocketOptions.getReadTimeoutMillis()
);OVERLOADED
, IS_BOOTSTRAPPING
, SERVER_ERROR
, etc.onRequestError
in interface ExtendedRetryPolicy
statement
- the original query that failed.cl
- the requested consistency level for the operation.
Note that this is not necessarily the achieved consistency level (if any),
and it is never a serial
one.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.protected void logDecision(String template, Object... parameters)
template
- The template to use; arguments must be specified in SLF4J style, i.e. "{}"
.parameters
- The template parameters.