/** * Get the parent ZNode for tservers for the given instance * * @param context * ClientContext * @return The tservers znode for the instance */ static String getTServersZkPath(ClientContext context) { requireNonNull(context); return context.getZooKeeperRoot() + Constants.ZTSERVERS; }
@VisibleForTesting static String getLocation(ZooReader zr, ClientContext context) throws KeeperException, InterruptedException { try { byte[] loc = zr.getData(context.getZooKeeperRoot() + Constants.ZMONITOR_HTTP_ADDR, null); return loc == null ? null : new String(loc, UTF_8); } catch (NoNodeException e) { // If there's no node advertising the monitor, there's no monitor. return null; } } }
ZookeeperLockChecker(ClientContext context) { zc = context.getZooCache(); this.root = context.getZooKeeperRoot() + Constants.ZTSERVERS; }
/** * Gets all the namespaces from ZK. The first arg (t) the BiConsumer accepts is the ID and the * second (u) is the namespaceName. */ private static void getAllNamespaces(ClientContext context, BiConsumer<String,String> biConsumer) { final ZooCache zc = context.getZooCache(); List<String> namespaceIds = zc.getChildren(context.getZooKeeperRoot() + Constants.ZNAMESPACES); for (String id : namespaceIds) { byte[] path = zc.get(context.getZooKeeperRoot() + Constants.ZNAMESPACES + "/" + id + Constants.ZNAMESPACE_NAME); if (path != null) { biConsumer.accept(id, new String(path, UTF_8)); } } }
@Override public void invalidateCache(ClientContext context, String server) { ZooCache zooCache = context.getZooCache(); String root = context.getZooKeeperRoot() + Constants.ZTSERVERS; zooCache.clear(root + "/" + server); }
/** * Clears the zoo cache from instance/root/{PATH} * * @param context * The Accumulo client context * @param zooPath * A zookeeper path */ public static void clearCacheByPath(ClientContext context, final String zooPath) { String thePath = zooPath.startsWith("/") ? zooPath : "/" + zooPath; getZooCache(context).clear(context.getZooKeeperRoot() + thePath); instanceToMapCache.invalidate(context.getInstanceID()); }
@Override public List<String> getTabletServers() { ZooCache cache = context.getZooCache(); String path = context.getZooKeeperRoot() + Constants.ZTSERVERS; List<String> results = new ArrayList<>(); for (String candidate : cache.getChildren(path)) { List<String> children = cache.getChildren(path + "/" + candidate); if (children != null && children.size() > 0) { List<String> copy = new ArrayList<>(children); Collections.sort(copy); byte[] data = cache.get(path + "/" + candidate + "/" + copy.get(0)); if (data != null && !"master".equals(new String(data, UTF_8))) { results.add(candidate); } } } return results; }
public static void clearCache(ClientContext context) { getZooCache(context).clear(context.getZooKeeperRoot() + Constants.ZTABLES); getZooCache(context).clear(context.getZooKeeperRoot() + Constants.ZNAMESPACES); instanceToMapCache.invalidate(context.getInstanceID()); }
public static boolean exists(ClientContext context, Namespace.ID namespaceId) { ZooCache zc = context.getZooCache(); List<String> namespaceIds = zc.getChildren(context.getZooKeeperRoot() + Constants.ZNAMESPACES); return namespaceIds.contains(namespaceId.canonicalID()); }
public static boolean exists(ClientContext context, Table.ID tableId) { ZooCache zc = getZooCache(context); List<String> tableIds = zc.getChildren(context.getZooKeeperRoot() + Constants.ZTABLES); return tableIds.contains(tableId.canonicalID()); }
/** * Returns the location(s) of the accumulo master and any redundant servers. * * @return a list of locations in "hostname:port" form */ public List<String> getMasterLocations() { ensureOpen(); String masterLocPath = getZooKeeperRoot() + 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)); }
private String root() throws WalMarkerException { String root = context.getZooKeeperRoot() + ZWALS; try { if (!checkedExistance && !zoo.exists(root)) { zoo.putPersistentData(root, new byte[0], NodeExistsPolicy.SKIP); } checkedExistance = true; } catch (KeeperException | InterruptedException e) { throw new WalMarkerException(e); } return root; }
/** * Returns the location of the tablet server that is serving the root tablet. * * @return location in "hostname:port" form */ public String getRootTabletLocation() { ensureOpen(); String zRootLocPath = getZooKeeperRoot() + RootTable.ZROOT_TABLET_LOCATION; OpTimer timer = null; if (log.isTraceEnabled()) { log.trace("tid={} Looking up root tablet location in zookeeper.", Thread.currentThread().getId()); timer = new OpTimer().start(); } byte[] loc = zooCache.get(zRootLocPath); if (timer != null) { timer.stop(); log.trace("tid={} Found root tablet 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 null; } return new String(loc, UTF_8).split("\\|")[0]; }
public void startWatchingForRecoveryLogs(ThreadPoolExecutor distWorkQThreadPool) throws KeeperException, InterruptedException { this.threadPool = distWorkQThreadPool; new DistributedWorkQueue(context.getZooKeeperRoot() + Constants.ZRECOVERY, conf) .startProcessing(new LogProcessor(), this.threadPool); }
protected TabletLocation getRootTabletLocation(ClientContext context) { String zRootLocPath = context.getZooKeeperRoot() + RootTable.ZROOT_TABLET_LOCATION; ZooCache zooCache = context.getZooCache(); Logger log = LoggerFactory.getLogger(this.getClass()); OpTimer timer = null; if (log.isTraceEnabled()) { log.trace("tid={} Looking up root tablet location in zookeeper.", Thread.currentThread().getId()); timer = new OpTimer().start(); } byte[] loc = zooCache.get(zRootLocPath); if (timer != null) { timer.stop(); log.trace("tid={} Found root tablet at {} in {}", Thread.currentThread().getId(), (loc == null ? "null" : new String(loc)), String.format("%.3f secs", timer.scale(TimeUnit.SECONDS))); } if (loc == null) { return null; } String[] tokens = new String(loc).split("\\|"); if (lockChecker.isLockHeld(tokens[0], tokens[1])) return new TabletLocation(RootTable.EXTENT, tokens[0], tokens[1]); else return null; }
/** * Returns the namespace id for a given table ID. * * @param context * The Accumulo client context * @param tableId * The tableId * @return The namespace id which this table resides in. * @throws IllegalArgumentException * if the table doesn't exist in ZooKeeper */ public static Namespace.ID getNamespaceId(ClientContext context, Table.ID tableId) throws TableNotFoundException { checkArgument(context != null, "instance is null"); checkArgument(tableId != null, "tableId is null"); ZooCache zc = getZooCache(context); byte[] n = zc.get(context.getZooKeeperRoot() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_NAMESPACE); // We might get null out of ZooCache if this tableID doesn't exist if (n == null) { throw new TableNotFoundException(tableId.canonicalID(), null, null); } return Namespace.ID.of(new String(n, UTF_8)); } }
/** * Look for namespace name in ZK. Throw NamespaceNotFoundException if not found. */ public static String getNamespaceName(ClientContext context, Namespace.ID namespaceId) throws NamespaceNotFoundException { String name; ZooCache zc = context.getZooCache(); byte[] path = zc.get(context.getZooKeeperRoot() + Constants.ZNAMESPACES + "/" + namespaceId.canonicalID() + Constants.ZNAMESPACE_NAME); if (path != null) name = new String(path, UTF_8); else throw new NamespaceNotFoundException(namespaceId.canonicalID(), null, "getNamespaceName() failed to find namespace"); return name; }
String zkPath = context.getZooKeeperRoot() + Constants.ZMASTER_REPLICATION_COORDINATOR_ADDR; String replCoordinatorAddr;
/** * Get the current state of the table using the tableid. The boolean clearCache, if true will * clear the table state in zookeeper before fetching the state. Added with ACCUMULO-4574. * * @param context * the Accumulo client context * @param tableId * the table id * @param clearCachedState * if true clear the table state in zookeeper before checking status * @return the table state. */ public static TableState getTableState(ClientContext context, Table.ID tableId, boolean clearCachedState) { String statePath = context.getZooKeeperRoot() + Constants.ZTABLES + "/" + tableId.canonicalID() + Constants.ZTABLE_STATE; if (clearCachedState) { Tables.clearCacheByPath(context, statePath); } ZooCache zc = getZooCache(context); byte[] state = zc.get(statePath); if (state == null) return TableState.UNKNOWN; return TableState.valueOf(new String(state, UTF_8)); }
LockID lid = new LockID(context.getZooKeeperRoot() + Constants.ZTSERVERS, sessionId.lockId);