@Override public Set<String> listUsers() { return new TreeSet<>(zooCache.getChildren(ZKUserPath)); }
public static byte[] getLockData(ZooCache zc, String path) { List<String> children = zc.getChildren(path); if (children == null || children.size() == 0) { return null; } children = new ArrayList<>(children); Collections.sort(children); String lockNode = children.get(0); return zc.get(path + "/" + lockNode); }
public static byte[] getLockData(org.apache.accumulo.fate.zookeeper.ZooCache zc, String path, ZcStat stat) { List<String> children = zc.getChildren(path); if (children == null || children.size() == 0) { return null; } children = new ArrayList<>(children); 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"); } return zc.get(path + "/" + lockNode, stat); }
/** * Given a zooCache and instanceId, look up the instance name. */ public static String lookupInstanceName(ZooCache zooCache, UUID instanceId) { checkArgument(zooCache != null, "zooCache is null"); checkArgument(instanceId != null, "instanceId is null"); for (String name : zooCache.getChildren(Constants.ZROOT + Constants.ZINSTANCES)) { String instanceNamePath = Constants.ZROOT + Constants.ZINSTANCES + "/" + name; byte[] bytes = zooCache.get(instanceNamePath); UUID iid = UUID.fromString(new String(bytes, UTF_8)); if (iid.equals(instanceId)) { return name; } } return null; } }
public static boolean isLockHeld(ZooCache zc, LockID lid) { List<String> children = zc.getChildren(lid.path); if (children == null || children.size() == 0) { return false; } children = new ArrayList<>(children); Collections.sort(children); String lockNode = children.get(0); if (!lid.node.equals(lockNode)) return false; ZcStat stat = new ZcStat(); return zc.get(lid.path + "/" + lid.node, stat) != null && stat.getEphemeralOwner() == lid.eid; }
@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; }
@Override public void getProperties(Map<String,String> props, Predicate<String> filter) { parent.getProperties(props, filter); List<String> children = propCache.getChildren(propPathPrefix); if (children != null) { for (String child : children) { if (child != null && filter.test(child)) { String value = getRaw(child); if (value != null) props.put(child, value); } } } }
public static long getSessionId(ZooCache zc, String path) { List<String> children = zc.getChildren(path); if (children == null || children.size() == 0) { return 0; } children = new ArrayList<>(children); Collections.sort(children); String lockNode = children.get(0); ZcStat stat = new ZcStat(); if (zc.get(path + "/" + lockNode, stat) != null) return stat.getEphemeralOwner(); return 0; }
public synchronized void scanServers() { try { final Set<TServerInstance> updates = new HashSet<>(); final Set<TServerInstance> doomed = new HashSet<>(); final String path = context.getZooKeeperRoot() + Constants.ZTSERVERS; HashSet<String> all = new HashSet<>(current.keySet()); all.addAll(getZooCache().getChildren(path)); locklessServers.keySet().retainAll(all); for (String zPath : all) { checkServer(updates, doomed, path, zPath); } // log.debug("Current: " + current.keySet()); this.cback.update(this, doomed, updates); } catch (Exception ex) { log.error("{}", ex.getMessage(), ex); } }
@Override public List<String> getChildren(String path) throws DistributedStoreException { try { return cache.getChildren(relative(path)); } catch (Exception ex) { throw new DistributedStoreException(ex); } }
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()); }
parent.getProperties(props, parentFilter != null ? parentFilter : filter); List<String> children = propCache.getChildren(path); if (children != null) { for (String child : children) {
@Override public void cleanTablePermissions(String table) throws AccumuloSecurityException { try { synchronized (zooCache) { zooCache.clear(); for (String user : zooCache.getChildren(ZKUserPath)) zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table, NodeMissingPolicy.SKIP); } } catch (KeeperException e) { log.error("{}", e.getMessage(), e); throw new AccumuloSecurityException("unknownUser", SecurityErrorCode.CONNECTION_ERROR, e); } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } }
@Override public void cleanNamespacePermissions(String namespace) throws AccumuloSecurityException { try { synchronized (zooCache) { zooCache.clear(); for (String user : zooCache.getChildren(ZKUserPath)) zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserNamespacePerms + "/" + namespace, NodeMissingPolicy.SKIP); } } catch (KeeperException e) { log.error("{}", e.getMessage(), e); throw new AccumuloSecurityException("unknownUser", SecurityErrorCode.CONNECTION_ERROR, e); } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } }
private void updateTableStateCache() { synchronized (tableStateCache) { for (String tableId : zooStateCache.getChildren(zkRoot + Constants.ZTABLES)) if (zooStateCache .get(zkRoot + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_STATE) != null) updateTableStateCache(Table.ID.of(tableId)); } }
/** * 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)); } } }
public TableMap(ClientContext context, ZooCache zooCache) { List<String> tableIds = zooCache.getChildren(context.getZooKeeperRoot() + Constants.ZTABLES); Map<Namespace.ID,String> namespaceIdToNameMap = new HashMap<>(); ImmutableMap.Builder<String,Table.ID> tableNameToIdBuilder = new ImmutableMap.Builder<>();
for (String tserver : zc.getChildren(context.getZooKeeperRoot() + Constants.ZTSERVERS)) { String path = context.getZooKeeperRoot() + Constants.ZTSERVERS + "/" + tserver; byte[] data = ZooUtil.getLockData(zc, path);
public static byte[] getLockData(ZooCache zc, String path) { List<String> children = zc.getChildren(path); if (children == null || children.size() == 0) { return null; } children = new ArrayList<>(children); Collections.sort(children); String lockNode = children.get(0); return zc.get(path + "/" + lockNode); }