@Override public void run() { closeAndReleaseInstance(); } });
@Override public void unlock(HiveLock hiveLock) throws LockException { unlockWithRetry(hiveLock, parent); }
/** * @param key * The object to be locked * @param mode * The mode of the lock * @param keepAlive * Whether the lock is to be persisted after the statement Acquire the * lock. Return null if a conflicting lock is present. **/ @Override public ZooKeeperHiveLock lock(HiveLockObject key, HiveLockMode mode, boolean keepAlive) throws LockException { return lock(key, mode, keepAlive, false); }
@Override public boolean equals(Object o) { if (!(o instanceof ZooKeeperHiveLock)) { return false; } ZooKeeperHiveLock zLock = (ZooKeeperHiveLock)o; return path.equals(zLock.getPath()) && obj.equals(zLock.getHiveLockObject()) && mode == zLock.getHiveLockMode(); }
private void unlockWithRetry(HiveLock hiveLock, String parent) throws LockException { int tryNum = 0; do { try { tryNum++; if (tryNum > 1) { Thread.sleep(sleepTime); } unlockPrimitive(hiveLock, parent, curatorFramework); break; } catch (Exception e) { if (tryNum >= numRetriesForUnLock) { String name = ((ZooKeeperHiveLock)hiveLock).getPath(); throw new LockException("Node " + name + " can not be deleted after " + numRetriesForUnLock + " attempts.", e); } } } while (tryNum < numRetriesForUnLock); return; }
@Override public List<HiveLock> getLocks(HiveLockObject key, boolean verifyTablePartitions, boolean fetchData) throws LockException { return getLocks(ctx.getConf(), key, parent, verifyTablePartitions, fetchData); }
/** Remove all redundant nodes **/ private void removeAllRedundantNodes() { try { checkRedundantNode("/" + parent); } catch (Exception e) { LOG.warn("Exception while removing all redundant nodes", e); } }
@Override public void close() throws LockException { try { if (HiveConf.getBoolVar(ctx.getConf(), HiveConf.ConfVars.HIVE_ZOOKEEPER_CLEAN_EXTRA_NODES)) { removeAllRedundantNodes(); } } catch (Exception e) { LOG.error("Failed to close zooKeeper client: " + e); throw new LockException(e); } }
@Override public void afterMethod(HiveTestEnvContext ctx) throws Exception { zooKeeper.close(); ZooKeeperHiveLockManager.releaseAllLocks(ctx.hiveConf); }
@Override public boolean equals(Object o) { if (!(o instanceof ZooKeeperHiveLock)) { return false; } ZooKeeperHiveLock zLock = (ZooKeeperHiveLock)o; return path.equals(zLock.getPath()) && obj.equals(zLock.getHiveLockObject()) && mode == zLock.getHiveLockMode(); }
private void unlockWithRetry(HiveLock hiveLock, String parent) throws LockException { int tryNum = 0; do { try { tryNum++; if (tryNum > 1) { Thread.sleep(sleepTime); } unlockPrimitive(hiveLock, parent, curatorFramework); break; } catch (Exception e) { if (tryNum >= numRetriesForUnLock) { String name = ((ZooKeeperHiveLock)hiveLock).getPath(); LOG.error("Node " + name + " can not be deleted after " + numRetriesForUnLock + " attempts."); throw new LockException(e); } } } while (tryNum < numRetriesForUnLock); return; }
@Override public void run() { closeAndReleaseInstance(); } });
@Override public List<HiveLock> getLocks(boolean verifyTablePartition, boolean fetchData) throws LockException { return getLocks(ctx.getConf(), null, parent, verifyTablePartition, fetchData); }
/** * @param key * The object to be locked * @param mode * The mode of the lock * @param keepAlive * Whether the lock is to be persisted after the statement Acquire the * lock. Return null if a conflicting lock is present. **/ @Override public ZooKeeperHiveLock lock(HiveLockObject key, HiveLockMode mode, boolean keepAlive) throws LockException { return lock(key, mode, keepAlive, false); }
/** Remove all redundant nodes **/ private void removeAllRedundantNodes() { try { checkRedundantNode("/" + parent); } catch (Exception e) { LOG.warn("Exception while removing all redundant nodes", e); } }
@Override public void close() throws LockException { try { if (HiveConf.getBoolVar(ctx.getConf(), HiveConf.ConfVars.HIVE_ZOOKEEPER_CLEAN_EXTRA_NODES)) { removeAllRedundantNodes(); } } catch (Exception e) { LOG.error("Failed to close zooKeeper client: " + e); throw new LockException(e); } }
@Override public void unlock(HiveLock hiveLock) throws LockException { unlockWithRetry(hiveLock, parent); }
@Override public void afterClass(HiveTestEnvContext ctx) throws Exception { CuratorFrameworkSingleton.closeAndReleaseInstance(); if (zooKeeperCluster != null) { zooKeeperCluster.shutdown(); zooKeeperCluster = null; } }
@Override public List<HiveLock> getLocks(boolean verifyTablePartition, boolean fetchData) throws LockException { return getLocks(ctx.getConf(), null, parent, verifyTablePartition, fetchData); }
@Override public List<HiveLock> getLocks(HiveLockObject key, boolean verifyTablePartitions, boolean fetchData) throws LockException { return getLocks(ctx.getConf(), key, parent, verifyTablePartitions, fetchData); }