use of org.apache.accumulo.fate.zookeeper.ZooUtil.LockID in project accumulo by apache.
the class ConditionalWriterImpl method invalidateSession.
/**
* The purpose of this code is to ensure that a conditional mutation will not execute when its status is unknown. This allows a user to read the row when the
* status is unknown and not have to worry about the tserver applying the mutation after the scan.
*
* <p>
* If a conditional mutation is taking a long time to process, then this method will wait for it to finish... unless this exceeds timeout.
*/
private void invalidateSession(SessionID sessionId, HostAndPort location) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
long sleepTime = 50;
long startTime = System.currentTimeMillis();
Instance instance = context.getInstance();
LockID lid = new LockID(ZooUtil.getRoot(instance) + Constants.ZTSERVERS, sessionId.lockId);
ZooCacheFactory zcf = new ZooCacheFactory();
while (true) {
if (!ZooLock.isLockHeld(zcf.getZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut()), lid)) {
// ACCUMULO-1152 added a tserver lock check to the tablet location cache, so this invalidation prevents future attempts to contact the
// tserver even its gone zombie and is still running w/o a lock
locator.invalidateCache(context.getInstance(), location.toString());
return;
}
try {
// if the mutation is currently processing, this method will block until its done or times out
invalidateSession(sessionId.sessionID, location);
return;
} catch (TApplicationException tae) {
throw new AccumuloServerException(location.toString(), tae);
} catch (TException e) {
locator.invalidateCache(context.getInstance(), location.toString());
}
if ((System.currentTimeMillis() - startTime) + sleepTime > timeout)
throw new TimedOutException(Collections.singleton(location.toString()));
sleepUninterruptibly(sleepTime, TimeUnit.MILLISECONDS);
sleepTime = Math.min(2 * sleepTime, MAX_SLEEP);
}
}
Aggregations