static void deleteRetry(IZooReaderWriter zk, String path) throws Exception { for (int i = 0; i < 10; i++) { try { zk.recursiveDelete(path, NodeMissingPolicy.SKIP); return; } catch (KeeperException.NotEmptyException ex) { // ignored } catch (Exception ex) { throw ex; } } }
public synchronized void unlock() throws InterruptedException, KeeperException { if (lock == null) { throw new IllegalStateException(); } LockWatcher localLw = lockWatcher; String localLock = lock; lock = null; lockWatcher = null; zooKeeper.recursiveDelete(path + "/" + localLock, NodeMissingPolicy.SKIP); localLw.lostLock(LockLossReason.LOCK_DELETED); }
public synchronized boolean tryToCancelAsyncLockOrUnlock() throws InterruptedException, KeeperException { boolean del = false; if (asyncLock != null) { zooKeeper.recursiveDelete(path + "/" + asyncLock, NodeMissingPolicy.SKIP); del = true; } if (lock != null) { unlock(); del = true; } return del; }
public static void deleteLock(IZooReaderWriter zk, String path) throws InterruptedException, KeeperException { List<String> children; children = zk.getChildren(path); if (children == null || children.size() == 0) { throw new IllegalStateException("No lock is held at " + path); } Collections.sort(children); String lockNode = children.get(0); if (!lockNode.startsWith(LOCK_PREFIX)) { throw new RuntimeException("Node " + lockNode + " at " + path + " is not a lock node"); } zk.recursiveDelete(path + "/" + lockNode, NodeMissingPolicy.SKIP); }
@Override public void removeEntry(long entry) { try { zoo.recursiveDelete(path + String.format("/%s%010d", PREFIX, entry), NodeMissingPolicy.SKIP); try { // try to delete the parent if it has no children zoo.delete(path, -1); } catch (NotEmptyException | NoNodeException nee) { // the path had other lock nodes, no big deal } } catch (Exception ex) { throw new RuntimeException(ex); } } }
public static void release(IZooReaderWriter zk, String path, String reservationID) throws KeeperException, InterruptedException { byte[] zooData; try { zooData = zk.getData(path, null); } catch (NoNodeException e) { // Just logging a warning, if data is gone then our work here is done. LoggerFactory.getLogger(ZooReservation.class).debug("Node does not exist {}", path); return; } String zooDataStr = new String(zooData, UTF_8); String idInZoo = zooDataStr.split(":")[0]; if (!idInZoo.equals(reservationID)) { throw new IllegalStateException("Tried to release reservation " + path + " with data mismatch " + reservationID + " " + zooDataStr); } zk.recursiveDelete(path, NodeMissingPolicy.SKIP); }
public static void cleanup(ServerContext context, String type, long tid) throws KeeperException, InterruptedException { IZooReaderWriter writer = context.getZooReaderWriter(); writer.recursiveDelete(context.getZooKeeperRoot() + "/" + type + "/" + tid, NodeMissingPolicy.SKIP); writer.recursiveDelete(context.getZooKeeperRoot() + "/" + type + "/" + tid + "-running", NodeMissingPolicy.SKIP); }
@Override public void run(IZooReaderWriter rw) throws KeeperException, InterruptedException { String root = getZookeeperLogLocation(context); for (LogEntry entry : entries) { String path = root + "/" + entry.getUniqueID(); log.debug("Removing " + path + " from zookeeper"); rw.recursiveDelete(path, NodeMissingPolicy.SKIP); } } });
@Override public void delete(long tid) { verifyReserved(tid); try { zk.recursiveDelete(getTXPath(tid), NodeMissingPolicy.SKIP); } catch (Exception e) { throw new RuntimeException(e); } }
private static void zapDirectory(IZooReaderWriter zoo, String path, Opts opts) throws KeeperException, InterruptedException { List<String> children = zoo.getChildren(path); for (String child : children) { message("Deleting " + path + "/" + child + " from zookeeper", opts); zoo.recursiveDelete(path + "/" + child, NodeMissingPolicy.SKIP); } } }
public static boolean deleteLock(IZooReaderWriter zk, String path, String lockData) throws InterruptedException, KeeperException { List<String> children; children = zk.getChildren(path); if (children == null || children.size() == 0) { throw new IllegalStateException("No lock is held at " + path); } Collections.sort(children); String lockNode = children.get(0); if (!lockNode.startsWith(LOCK_PREFIX)) { throw new RuntimeException("Node " + lockNode + " at " + path + " is not a lock node"); } byte[] data = zk.getData(path + "/" + lockNode, null); if (lockData.equals(new String(data, UTF_8))) { zk.recursiveDelete(path + "/" + lockNode, NodeMissingPolicy.FAIL); return true; } return false; } }
public synchronized boolean tryLock(LockWatcher lw, byte data[]) throws KeeperException, InterruptedException { TryLockAsyncLockWatcher tlalw = new TryLockAsyncLockWatcher(lw); lockAsync(tlalw, data); if (tlalw.acquiredLock) { return true; } if (asyncLock != null) { zooKeeper.recursiveDelete(path + "/" + asyncLock, NodeMissingPolicy.SKIP); asyncLock = null; } return false; }
public static void stop(ServerContext context, String type, long tid) throws KeeperException, InterruptedException { IZooReaderWriter writer = context.getZooReaderWriter(); writer.recursiveDelete(context.getZooKeeperRoot() + "/" + type + "/" + tid, NodeMissingPolicy.SKIP); }
public void deleteLocks(IZooReaderWriter zk, String path, String txidStr) throws KeeperException, InterruptedException { // delete any locks assoc w/ fate operation List<String> lockedIds = zk.getChildren(path); for (String id : lockedIds) { List<String> lockNodes = zk.getChildren(path + "/" + id); for (String node : lockNodes) { String lockPath = path + "/" + id + "/" + node; byte[] data = zk.getData(path + "/" + id + "/" + node, null); String lda[] = new String(data, UTF_8).split(":"); if (lda[1].equals(txidStr)) zk.recursiveDelete(lockPath, NodeMissingPolicy.SKIP); } } }
@Override public void pop(long tid) { verifyReserved(tid); try { String txpath = getTXPath(tid); String top = findTop(txpath); if (top == null) throw new IllegalStateException("Tried to pop when empty " + tid); zk.recursiveDelete(txpath + "/" + top, NodeMissingPolicy.SKIP); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Update the data file for the root tablet */ private static void updateRootTabletDataFile(ServerContext context, Set<String> unusedWalLogs) { IZooReaderWriter zk = context.getZooReaderWriter(); String root = MetadataTableUtil.getZookeeperLogLocation(context); for (String entry : unusedWalLogs) { String[] parts = entry.split("/"); String zpath = root + "/" + parts[parts.length - 1]; while (true) { try { if (zk.exists(zpath)) { log.debug("Removing WAL reference for root table {}", zpath); zk.recursiveDelete(zpath, NodeMissingPolicy.SKIP); } break; } catch (KeeperException | InterruptedException e) { log.error("{}", e.getMessage(), e); } sleepUninterruptibly(1, TimeUnit.SECONDS); } } }
@Override public void initializeSecurity(String principal, byte[] token) { try { // remove old settings from zookeeper first, if any IZooReaderWriter zoo = context.getZooReaderWriter(); synchronized (zooCache) { zooCache.clear(); if (zoo.exists(ZKUserPath)) { zoo.recursiveDelete(ZKUserPath, NodeMissingPolicy.SKIP); log.info("Removed {}/ from zookeeper", ZKUserPath); } // prep parent node of users with root username zoo.putPersistentData(ZKUserPath, principal.getBytes(UTF_8), NodeExistsPolicy.FAIL); constructUser(principal, ZKSecurityTool.createPass(token)); } } catch (KeeperException | AccumuloException | InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } }
@Override public void dropUser(String user) throws AccumuloSecurityException { try { synchronized (zooCache) { IZooReaderWriter zoo = context.getZooReaderWriter(); zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserAuths, NodeMissingPolicy.SKIP); zooCache.clear(ZKUserPath + "/" + user); } } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } catch (KeeperException e) { log.error("{}", e.getMessage(), e); if (e.code().equals(KeeperException.Code.NONODE)) throw new AccumuloSecurityException(user, SecurityErrorCode.USER_DOESNT_EXIST, e); throw new AccumuloSecurityException(user, SecurityErrorCode.CONNECTION_ERROR, e); } }
private static void deleteInstance(ServerContext context, String oldPass) throws Exception { IZooReaderWriter orig = new ZooReaderWriter(context.getZooKeepers(), context.getZooKeepersSessionTimeOut(), oldPass); orig.recursiveDelete("/accumulo/" + context.getInstanceID(), NodeMissingPolicy.SKIP); } }
@Override public void remove(String path) throws DistributedStoreException { try { log.debug("Removing {}", path); path = relative(path); IZooReaderWriter zoo = context.getZooReaderWriter(); if (zoo.exists(path)) zoo.recursiveDelete(path, NodeMissingPolicy.SKIP); cache.clear(); } catch (Exception ex) { throw new DistributedStoreException(ex); } } }