/** * Unregisters this table user from ZooKeeper. * * @throws IOException on unrecoverable ZooKeeper error. */ private void unregister() throws IOException { synchronized (mMonitor) { if (mCurrentNode != null) { try { ZooKeeperMonitor.this.mZKClient.delete(mCurrentNode, -1); LOG.debug("TableUserRegistration node {} removed.", mCurrentNode); mCurrentNode = null; } catch (KeeperException e) { throw new IOException(e); } } } }
/** * Removes a ZooKeeper node and all of its children, if necessary. * * @param path of the node to remove. * @throws KeeperException on I/O error. */ public void deleteNodeRecursively(File path) throws KeeperException { Stat stat = exists(path); // Race condition if someone else updates the znode in the meantime if (stat == null) { return; } List<String> children = getChildren(path, null, null); for (String child : children) { deleteNodeRecursively(new File(path, child)); } delete(path, stat.getVersion()); }
/** * Releases the lock. * * @throws InterruptedException if the thread is interrupted. * @throws KeeperException on error. */ private void unlockInternal() throws InterruptedException, KeeperException { File pathToDelete = null; synchronized (this) { Preconditions.checkState(null != mCreatedPath, "unlock() cannot be called while lock is unlocked."); pathToDelete = mCreatedPath; LOG.debug("Releasing lock {}: deleting {}", this, mCreatedPath); mCreatedPath = null; } mZKClient.delete(pathToDelete, -1); // -1 means any version }
/** {@inheritDoc} */ @Override public void close() throws IOException { synchronized (mMonitor) { if (mCurrentNode != null) { try { if (ZooKeeperMonitor.this.mZKClient.exists(mCurrentNode) != null) { ZooKeeperMonitor.this.mZKClient.delete(mCurrentNode, -1); } } catch (KeeperException e) { throw new IOException(e); } } } } }
LOG.debug("{}: out of time while acquiring lock, deleting {}", this, mCreatedPath); mZKClient.delete(mCreatedPath, -1); // -1 means any version mCreatedPath = null; return false;