do {
try {
return exe.call();
} catch (StorageException e) {
if (e instanceof TemporaryStorageException) lastException = e;
else throw new TitanException("Permanent exception during backend operation",e); //Its permanent
} catch (Throwable e) {
throw new TitanException("Unexpected exception during backend operation",e);
}
//Wait and retry
retryAttempts++;
Preconditions.checkNotNull(lastException);
if (retryAttempts<maxRetryAttempts) {
long waitTime = Math.round(retryWaittime+((Math.random()*WAITTIME_PERTURBATION_PERCENTAGE-WAITTIME_PERTURBATION_PERCENTAGE_HALF)*retryWaittime));
Preconditions.checkArgument(waitTime>=0,"Invalid wait time: %s",waitTime);
log.info("Temporary storage exception during backend operation [{}]. Attempting incremental retry",exe.toString(),lastException);
try {
Thread.sleep(waitTime);
} catch (InterruptedException r) {
throw new TitanException("Interrupted while waiting to retry failed backend operation", r);
}
}
} while (retryAttempts<maxRetryAttempts);
throw new TitanException("Could not successfully complete backend operation due to repeated temporary exceptions after "+maxRetryAttempts+" attempts",lastException);
}