Skip to content

Instantly share code, notes, and snippets.

@Randgalt
Created June 6, 2019 13:19
Show Gist options
  • Save Randgalt/a5ab016c5dcab8bac9cee223932548c2 to your computer and use it in GitHub Desktop.
Save Randgalt/a5ab016c5dcab8bac9cee223932548c2 to your computer and use it in GitHub Desktop.
checkBackgroundRetry() change
@VisibleForTesting
volatile CountDownLatch debugCheckBackgroundRetryLatch;
@VisibleForTesting
volatile CountDownLatch debugCheckBackgroundRetryReadyLatch;
@SuppressWarnings({"ThrowableResultOfMethodCallIgnored"})
private <DATA_TYPE> boolean checkBackgroundRetry(OperationAndData<DATA_TYPE> operationAndData, CuratorEvent event)
{
boolean doRetry = false;
if ( client.getRetryPolicy().allowRetry(operationAndData.getThenIncrementRetryCount(), operationAndData.getElapsedTimeMs(), operationAndData) )
{
doRetry = true;
}
else
{
if ( operationAndData.getErrorCallback() != null )
{
operationAndData.getErrorCallback().retriesExhausted(operationAndData);
}
if ( operationAndData.getCallback() != null )
{
sendToBackgroundCallback(operationAndData, event);
}
KeeperException.Code code = KeeperException.Code.get(event.getResultCode());
Exception e = null;
try
{
e = (code != null) ? KeeperException.create(code) : null;
}
catch ( Throwable t )
{
ThreadUtils.checkInterrupted(t);
}
if ( e == null )
{
e = new Exception("Unknown result codegetResultCode()");
}
if ( debugCheckBackgroundRetryLatch != null )
{
if ( debugCheckBackgroundRetryReadyLatch != null )
{
debugCheckBackgroundRetryReadyLatch.countDown();
}
try
{
debugCheckBackgroundRetryLatch.await();
}
catch ( InterruptedException ex )
{
Thread.currentThread().interrupt();
}
}
validateConnection(codeToState(code));
logError("Background operation retry gave up", e);
}
return doRetry;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment