@Override public List<ACL> getACL(String zPath, Stat stat) throws KeeperException, InterruptedException { return ZooUtil.getACL(info, zPath, stat); }
/** * Iterate over the queued work to remove entries that have been completed. */ @Override protected void cleanupFinishedWork() { final Iterator<String> work = queuedWork.iterator(); final String instanceId = client.getInstanceID(); while (work.hasNext()) { String filename = work.next(); // Null equates to the work was finished if (zooCache.get(ZooUtil.getRoot(instanceId) + ReplicationConstants.ZOO_WORK_QUEUE + "/" + filename) == null) { work.remove(); } } }
public static boolean exists(ZooKeeperConnectionInfo info, String zPath) throws KeeperException, InterruptedException { return getStatus(info, zPath) != null; }
public static byte[] getData(ZooKeeperConnectionInfo info, String zPath, Stat stat) throws KeeperException, InterruptedException { final Retry retry = RETRY_FACTORY.createRetry(); while (true) { try { return getZooKeeper(info).getData(zPath, false, stat); } catch (KeeperException e) { final Code c = e.code(); if (c == Code.CONNECTIONLOSS || c == Code.OPERATIONTIMEOUT || c == Code.SESSIONEXPIRED) { retryOrThrow(retry, e); } else { throw e; } } retry.waitForNextAttempt(); } }
@Override public List<String> getMasterLocations() { String masterLocPath = ZooUtil.getRoot(getInstanceID()) + Constants.ZMASTER_LOCK; OpTimer timer = null; if (log.isTraceEnabled()) { log.trace("tid={} Looking up master location in zookeeper.", Thread.currentThread().getId()); timer = new OpTimer().start(); } byte[] loc = ZooUtil.getLockData(zooCache, masterLocPath); if (timer != null) { timer.stop(); log.trace("tid={} Found master at {} in {}", Thread.currentThread().getId(), (loc == null ? "null" : new String(loc, UTF_8)), String.format("%.3f secs", timer.scale(TimeUnit.SECONDS))); } if (loc == null) { return Collections.emptyList(); } return Collections.singletonList(new String(loc, UTF_8)); }
public static void recursiveCopyPersistent(ZooKeeperConnectionInfo info, String source, String destination, NodeExistsPolicy policy) throws KeeperException, InterruptedException { Stat stat = null; if (!exists(info, source)) throw KeeperException.create(Code.NONODE, source); if (exists(info, destination)) { switch (policy) { case OVERWRITE: byte[] data = getData(info, source, stat); putPersistentData(info, destination, data, policy); if (stat.getNumChildren() > 0) { List<String> children; while (true) { try { children = getZooKeeper(info).getChildren(source, false); break; } catch (KeeperException e) { if (c == Code.CONNECTIONLOSS || c == Code.OPERATIONTIMEOUT || c == Code.SESSIONEXPIRED) { retryOrThrow(retry, e); } else { throw e; recursiveCopyPersistent(info, source + "/" + child, destination + "/" + child, policy);
while (true) { try { children = getZooKeeper(info).getChildren(zPath, false); break; } catch (KeeperException e) { final Code c = e.code(); if (c == Code.CONNECTIONLOSS || c == Code.OPERATIONTIMEOUT || c == Code.SESSIONEXPIRED) { retryOrThrow(retry, e); } else { throw e; recursiveDelete(info, zPath + "/" + child, NodeMissingPolicy.SKIP); stat = getZooKeeper(info).exists(zPath, null); getZooKeeper(info).delete(zPath, -1); return; } catch (NoNodeException e) { final Code c = e.code(); if (c == Code.CONNECTIONLOSS || c == Code.OPERATIONTIMEOUT || c == Code.SESSIONEXPIRED) { retryOrThrow(retry, e); } else { throw e;
public static boolean putPersistentData(ZooKeeperConnectionInfo info, String zPath, byte[] data, int version, NodeExistsPolicy policy, List<ACL> acls) throws KeeperException, InterruptedException { return putData(info, zPath, data, CreateMode.PERSISTENT, version, policy, acls); }
@Override public String putEphemeralData(String zPath, byte[] data) throws KeeperException, InterruptedException { return ZooUtil.putEphemeralData(info, zPath, data); }
@Override public String putEphemeralSequential(String zPath, byte[] data) throws KeeperException, InterruptedException { return ZooUtil.putEphemeralSequential(info, zPath, data); }
@Override public boolean isLockHeld(ZooUtil.LockID lockID) throws KeeperException, InterruptedException { return ZooUtil.isLockHeld(info, lockID); }
protected static ZooKeeper getZooKeeper(ZooKeeperConnectionInfo info) { return getZooKeeper(info.keepers, info.timeout, info.scheme, info.auth); }
public static void recursiveCopyPersistent(ZooKeeperConnectionInfo info, String source, String destination, NodeExistsPolicy policy) throws KeeperException, InterruptedException { Stat stat = null; if (!exists(info, source)) throw KeeperException.create(Code.NONODE, source); if (exists(info, destination)) { switch (policy) { case OVERWRITE: byte[] data = getData(info, source, stat); putPersistentData(info, destination, data, policy); if (stat.getNumChildren() > 0) { List<String> children; while (true) { try { children = getZooKeeper(info).getChildren(source, false); break; } catch (KeeperException e) { if (c == Code.CONNECTIONLOSS || c == Code.OPERATIONTIMEOUT || c == Code.SESSIONEXPIRED) { retryOrThrow(retry, e); } else { throw e; recursiveCopyPersistent(info, source + "/" + child, destination + "/" + child, policy);
public static String putEphemeralData(ZooKeeperConnectionInfo info, String zPath, byte[] data) throws KeeperException, InterruptedException { final Retry retry = RETRY_FACTORY.createRetry(); while (true) { try { return getZooKeeper(info).create(zPath, data, ZooUtil.PUBLIC, CreateMode.EPHEMERAL); } catch (KeeperException e) { final Code c = e.code(); if (c == Code.CONNECTIONLOSS || c == Code.OPERATIONTIMEOUT || c == Code.SESSIONEXPIRED) { retryOrThrow(retry, e); } else { throw e; } } retry.waitForNextAttempt(); } }
while (true) { try { children = getZooKeeper(info).getChildren(zPath, false); break; } catch (KeeperException e) { final Code c = e.code(); if (c == Code.CONNECTIONLOSS || c == Code.OPERATIONTIMEOUT || c == Code.SESSIONEXPIRED) { retryOrThrow(retry, e); } else { throw e; recursiveDelete(info, zPath + "/" + child, NodeMissingPolicy.SKIP); stat = getZooKeeper(info).exists(zPath, null); getZooKeeper(info).delete(zPath, -1); return; } catch (NoNodeException e) { final Code c = e.code(); if (c == Code.CONNECTIONLOSS || c == Code.OPERATIONTIMEOUT || c == Code.SESSIONEXPIRED) { retryOrThrow(retry, e); } else { throw e;
/** * Create a persistent node with the default ACL * * @return true if the node was created or altered; false if it was skipped */ public static boolean putPersistentData(ZooKeeperConnectionInfo info, String zPath, byte[] data, NodeExistsPolicy policy) throws KeeperException, InterruptedException { return putData(info, zPath, data, CreateMode.PERSISTENT, -1, policy, PUBLIC); }
@Override public String putEphemeralData(String zPath, byte[] data) throws KeeperException, InterruptedException { return ZooUtil.putEphemeralData(info, zPath, data); }
@Override public String putEphemeralSequential(String zPath, byte[] data) throws KeeperException, InterruptedException { return ZooUtil.putEphemeralSequential(info, zPath, data); }
@Override public boolean isLockHeld(ZooUtil.LockID lockID) throws KeeperException, InterruptedException { return ZooUtil.isLockHeld(info, lockID); }
protected static ZooKeeper getZooKeeper(ZooKeeperConnectionInfo info) { return getZooKeeper(info.keepers, info.timeout, info.scheme, info.auth); }