[EnhancementRequest] ExponentialRetryPolicy

14 views
Skip to first unread message

Nicolas Guyomar

unread,
Jan 20, 2016, 6:32:44 AM1/20/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi guys,

Would that be possible to have something similar to the ExponentialReconnectionPolicy as a new RetryPolicy ?

What I'd like to do is manage some random WriteTimeout/ReadTimeout during Full GC, but on the driver side. (I know full gc problem should be also adressed ! ). I might just have to wait for a few seconds and retry the exact same statement when the cluster is a bit more available.

The only easy thing I could come up with was to use the same mecanism as the ExponentialReconnectionPolicy, but with a Thread.sleep(exponentialSleep) in the nextDelay method.

We already had a quick talk with Olivier Michallat about this feature, but he told us that using a Thread.sleep is not a good idea because it will block the driver's thread.

Could you point me in the right direction so that I could find a way to do this in a non blocking way ? Maybe this could end up being a new contribution in the driver ?

Regards,

Nicolas

Vishy Kasaravalli

unread,
Jan 20, 2016, 12:17:58 PM1/20/16
to java-dri...@lists.datastax.com

You can implement this at your client layer. This will hold up your application thread as opposed to driver’s thread. Pseudo code:

public void executeWithRetry(Statement statement) throws TimeoutException {
final ResultSetFuture resultSetFuture = session.executeAsync(statement);
try {
     return resultSetFuture.getUninterruptibly(timeOutMillis, TimeUnit.MILLISECONDS);
} catch (final TimeoutException e) {
if (numRetry < maxRetry) {
long waitTimeMillis = getWaitTime(numRetry++);
Uninterruptibles.sleepUninterruptibly(waitTimeMillis, TimeUnit.MILLISECONDS);
executeWithRetry(statement);
}
throw e;
}
}

If you are willing to implement Session interface, you can also have this logic in your session implementation. 

--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.

Reply all
Reply to author
Forward
0 new messages