Class IdempotenceAwareRetryPolicy

  • All Implemented Interfaces:
    RetryPolicy

    @Deprecated
    public class IdempotenceAwareRetryPolicy
    extends Object
    implements RetryPolicy
    Deprecated.
    As of version 3.1.0, the driver doesn't retry non-idempotent statements for write timeouts or unexpected errors anymore. It is no longer necessary to wrap your retry policies in this policy.
    A retry policy that avoids retrying non-idempotent statements.

    In case of write timeouts or unexpected errors, this policy will always return RetryPolicy.RetryDecision.rethrow() if the statement is deemed non-idempotent (see isIdempotent(Statement)).

    For all other cases, this policy delegates the decision to the child policy.

    • Constructor Detail

      • IdempotenceAwareRetryPolicy

        public IdempotenceAwareRetryPolicy​(RetryPolicy childPolicy)
        Deprecated.
        Creates a new instance.
        Parameters:
        childPolicy - the policy to wrap.
    • Method Detail

      • onReadTimeout

        public RetryPolicy.RetryDecision onReadTimeout​(Statement statement,
                                                       ConsistencyLevel cl,
                                                       int requiredResponses,
                                                       int receivedResponses,
                                                       boolean dataRetrieved,
                                                       int nbRetry)
        Deprecated.
        Description copied from interface: RetryPolicy
        Defines whether to retry and at which consistency level on a read timeout.

        Note that this method may be called even if requiredResponses >= receivedResponses if dataPresent is false (see ReadTimeoutException.wasDataRetrieved()).

        Specified by:
        onReadTimeout in interface RetryPolicy
        Parameters:
        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.
        Returns:
        the retry decision. If RetryDecision.RETHROW is returned, a ReadTimeoutException will be thrown for the operation.
      • onWriteTimeout

        public RetryPolicy.RetryDecision onWriteTimeout​(Statement statement,
                                                        ConsistencyLevel cl,
                                                        WriteType writeType,
                                                        int requiredAcks,
                                                        int receivedAcks,
                                                        int nbRetry)
        Deprecated.
        Description copied from interface: RetryPolicy
        Defines whether to retry and at which consistency level on a write timeout.

        Note that if a statement is not idempotent, the driver will never retry it on a write timeout (this method won't even be called).

        Specified by:
        onWriteTimeout in interface RetryPolicy
        Parameters:
        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.
        Returns:
        the retry decision. If RetryDecision.RETHROW is returned, a WriteTimeoutException will be thrown for the operation.
      • onUnavailable

        public RetryPolicy.RetryDecision onUnavailable​(Statement statement,
                                                       ConsistencyLevel cl,
                                                       int requiredReplica,
                                                       int aliveReplica,
                                                       int nbRetry)
        Deprecated.
        Description copied from interface: RetryPolicy
        Defines whether to retry and at which consistency level on an unavailable exception.
        Specified by:
        onUnavailable in interface RetryPolicy
        Parameters:
        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.
        Returns:
        the retry decision. If RetryDecision.RETHROW is returned, an UnavailableException will be thrown for the operation.
      • onRequestError

        public RetryPolicy.RetryDecision onRequestError​(Statement statement,
                                                        ConsistencyLevel cl,
                                                        DriverException e,
                                                        int nbRetry)
        Deprecated.
        Description copied from interface: RetryPolicy
        Defines whether to retry and at which consistency level on an unexpected error.

        This method might be invoked in the following situations:

        1. On a client timeout, while waiting for the server response (see SocketOptions.getReadTimeoutMillis());
        2. On a connection error (socket closed, etc.);
        3. When the contacted host replies with an OVERLOADED error, SERVER_ERROR, READ_FAILURE or WRITE_FAILURE.

        Note that when such an error occurs, there is no guarantee that the mutation has been applied server-side or not. Therefore, if a statement is not idempotent, the driver will never retry it (this method won't even be called).

        Specified by:
        onRequestError in interface RetryPolicy
        Parameters:
        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.
        Returns:
        the retry decision. If RetryDecision.RETHROW is returned, the DriverException passed to this method will be thrown for the operation.
      • init

        public void init​(Cluster cluster)
        Deprecated.
        Description copied from interface: RetryPolicy
        Gets invoked at cluster startup.
        Specified by:
        init in interface RetryPolicy
        Parameters:
        cluster - the cluster that this policy is associated with.
      • close

        public void close()
        Deprecated.
        Description copied from interface: RetryPolicy
        Gets invoked at cluster shutdown.

        This gives the policy the opportunity to perform some cleanup, for instance stop threads that it might have started.

        Specified by:
        close in interface RetryPolicy
      • isIdempotent

        protected boolean isIdempotent​(Statement statement)
        Deprecated.
        Determines whether the given statement is idempotent or not.

        The current implementation inspects the statement's idempotent flag; if this flag is not set, then it inspects QueryOptions.getDefaultIdempotence().

        Subclasses may override if they have better knowledge of the statement being executed.

        Parameters:
        statement - The statement to execute.
        Returns:
        true if the given statement is idempotent, false otherwise