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);
}
Aggregations