* @throws InterruptedException
* @throws KeeperException
*/
public void delete(String path, int version)
throws InterruptedException, KeeperException {
RetryCounter retryCounter = retryCounterFactory.create();
boolean isRetry = false; // False for first attempt, true for all retries.
while (true) {
try {
zk.delete(path, version);
return;
} catch (KeeperException e) {
switch (e.code()) {
case NONODE:
if (isRetry) {
LOG.info("Node " + path + " already deleted. Assuming that a " +
"previous attempt succeeded.");
return;
}
LOG.warn("Node " + path + " already deleted, and this is not a " +
"retry");
throw e;
case CONNECTIONLOSS:
case OPERATIONTIMEOUT:
LOG.warn("Possibly transient ZooKeeper exception: " + e);
if (!retryCounter.shouldRetry()) {
LOG.error("ZooKeeper delete failed after "
+ retryCounter.getMaxRetries() + " retries");
throw e;
}
break;
default:
throw e;
}
}
retryCounter.sleepUntilNextRetry();
retryCounter.useRetry();
isRetry = true;
}
}