Search in sources :

Example 1 with TimedOutException

use of org.apache.cassandra.thrift.TimedOutException in project scale7-pelops by s7.

the class Operand method tryOperation.

protected <ReturnType> ReturnType tryOperation(IOperation<ReturnType> operation, OperandPolicy operandPolicy) throws PelopsException {
    Set<String> avoidNodes = null;
    Exception lastException = null;
    int retries = 0;
    do {
        // Get a connection to a Cassandra node
        IPooledConnection conn = null;
        try {
            conn = thrift.getConnectionExcept(avoidNodes);
        } catch (Exception e) {
            // the pool is responsible for blocking and waiting for a connection, so don't retry
            throw operandPolicy.getExceptionTranslator().translate(e);
        }
        try {
            // Return result!
            return operation.execute(conn);
        } catch (Exception e) {
            // Should we try again?
            if (e instanceof TimedOutException || e instanceof TTransportException || e instanceof UnavailableException) {
                logger.warn("Operation failed as result of network exception. Connection to node {} is being marked as corrupt " + "(and will probably be be destroyed). Cause of failure is {}", conn.getNode().getAddress(), e);
                // This connection is "broken" by network timeout or other problem.
                conn.corrupted();
                // to avoid create the set for every request create the set here
                if (avoidNodes == null)
                    avoidNodes = new HashSet<String>(10);
                avoidNodes.add(conn.getNode().getAddress());
                retries++;
                lastException = e;
            } else if (e instanceof NotFoundException) {
                // Re-throw application-level exceptions immediately.
                throw operandPolicy.getExceptionTranslator().translate(e);
            } else {
                // This connection is "broken" by network timeout or other problem.
                conn.corrupted();
                // Re-throw application-level exceptions immediately.
                throw operandPolicy.getExceptionTranslator().translate(e);
            }
        } finally {
            conn.release();
        }
    } while (retries < operandPolicy.getMaxOpRetries());
    throw operandPolicy.getExceptionTranslator().translate(lastException);
}
Also used : TimedOutException(org.apache.cassandra.thrift.TimedOutException) UnavailableException(org.apache.cassandra.thrift.UnavailableException) TTransportException(org.apache.thrift.transport.TTransportException) NotFoundException(org.apache.cassandra.thrift.NotFoundException) TimedOutException(org.apache.cassandra.thrift.TimedOutException) PelopsException(org.scale7.cassandra.pelops.exceptions.PelopsException) UnavailableException(org.apache.cassandra.thrift.UnavailableException) TTransportException(org.apache.thrift.transport.TTransportException) NotFoundException(org.apache.cassandra.thrift.NotFoundException) IPooledConnection(org.scale7.cassandra.pelops.pool.IThriftPool.IPooledConnection)

Aggregations

NotFoundException (org.apache.cassandra.thrift.NotFoundException)1 TimedOutException (org.apache.cassandra.thrift.TimedOutException)1 UnavailableException (org.apache.cassandra.thrift.UnavailableException)1 TTransportException (org.apache.thrift.transport.TTransportException)1 PelopsException (org.scale7.cassandra.pelops.exceptions.PelopsException)1 IPooledConnection (org.scale7.cassandra.pelops.pool.IThriftPool.IPooledConnection)1