private void registerInZooKeeper(String name, String root) throws Exception { IZooReaderWriter zoo = context.getZooReaderWriter(); zoo.putPersistentData(root, new byte[0], NodeExistsPolicy.SKIP); log.info("Registering tracer {} at {}", name, root); String path = zoo.putEphemeralSequential(root + "/trace-", name.getBytes(UTF_8)); zoo.exists(path, this); }
/** * 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 // ACCUMULO-4140 The root user needs to be stored un-base64 encoded in the znode's value byte[] principalData = principal.getBytes(UTF_8); zoo.putPersistentData(zkUserPath, principalData, NodeExistsPolicy.FAIL); // Create the root user in ZK using base64 encoded name (since the name is included in the // znode) createUserNodeInZk(Base64.getEncoder().encodeToString(principalData)); } } catch (KeeperException | InterruptedException e) { log.error("Failed to initialize security", e); throw new RuntimeException(e); } }
@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 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); } } }
public static long reserveTable(Master env, Table.ID tableId, long tid, boolean writeLock, boolean tableMustExist, TableOperation op) throws Exception { if (getLock(env.getContext(), tableId, tid, writeLock).tryLock()) { if (tableMustExist) { IZooReaderWriter zk = env.getContext().getZooReaderWriter(); if (!zk.exists(env.getContext().getZooKeeperRoot() + Constants.ZTABLES + "/" + tableId)) throw new AcceptableThriftTableOperationException(tableId.canonicalID(), "", op, TableOperationExceptionType.NOTFOUND, "Table does not exist"); } log.info("table {} ({}) locked for {} operation: {}", tableId, Long.toHexString(tid), (writeLock ? "write" : "read"), op); return 0; } else return 100; }
private void moveRootTabletToRootTable(IZooReaderWriter zoo) throws Exception { String dirZPath = getZooKeeperRoot() + RootTable.ZROOT_TABLET_PATH; if (!zoo.exists(dirZPath)) { Path oldPath = fs.getFullPath(FileType.TABLE, "/" + MetadataTable.ID + "/root_tablet"); if (fs.exists(oldPath)) {
public static long reserveNamespace(Master env, Namespace.ID namespaceId, long id, boolean writeLock, boolean mustExist, TableOperation op) throws Exception { if (getLock(env.getContext(), namespaceId, id, writeLock).tryLock()) { if (mustExist) { IZooReaderWriter zk = env.getContext().getZooReaderWriter(); if (!zk.exists( env.getContext().getZooKeeperRoot() + Constants.ZNAMESPACES + "/" + namespaceId)) throw new AcceptableThriftTableOperationException(namespaceId.canonicalID(), "", op, TableOperationExceptionType.NAMESPACE_NOTFOUND, "Namespace does not exist"); } log.info("namespace {} ({}) locked for {} operation: {}", namespaceId, Long.toHexString(id), (writeLock ? "write" : "read"), op); return 0; } else return 100; }
private static boolean zookeeperAvailable() { try { return zoo.exists("/"); } catch (KeeperException e) { return false; } catch (InterruptedException e) { return false; } }
private static boolean zookeeperAvailable() { try { return zoo.exists("/"); } catch (KeeperException e) { return false; } catch (InterruptedException e) { return false; } }
public static void main(String[] args) throws Exception { String rootDir = args[0]; File reportDir = new File(args[1]); IZooReaderWriter zoo = ZooReaderWriter.getInstance(); if (zoo.exists(rootDir)) { zoo.recursiveDelete(rootDir, NodeMissingPolicy.FAIL); } FileUtils.deleteQuietly(reportDir); if (!reportDir.mkdirs()) { throw new IOException("Unable to (re-)create " + reportDir); } } }
private void registerInZooKeeper(String name, String root) throws Exception { IZooReaderWriter zoo = ZooReaderWriter.getInstance(); zoo.putPersistentData(root, new byte[0], NodeExistsPolicy.SKIP); log.info("Registering tracer " + name + " at " + root); String path = zoo.putEphemeralSequential(root + "/trace-", name.getBytes(UTF_8)); zoo.exists(path, this); }
public static long reserveTable(String tableId, long tid, boolean writeLock, boolean tableMustExist, TableOperation op) throws Exception { if (getLock(tableId, tid, writeLock).tryLock()) { if (tableMustExist) { Instance instance = HdfsZooInstance.getInstance(); IZooReaderWriter zk = ZooReaderWriter.getRetryingInstance(); if (!zk.exists(ZooUtil.getRoot(instance) + Constants.ZTABLES + "/" + tableId)) throw new ThriftTableOperationException(tableId, "", op, TableOperationExceptionType.NOTFOUND, "Table does not exists"); } log.info("table " + tableId + " (" + Long.toHexString(tid) + ") locked for " + (writeLock ? "write" : "read") + " operation: " + op); return 0; } else return 100; }
public static long reserveNamespace(String namespaceId, long id, boolean writeLock, boolean mustExist, TableOperation op) throws Exception { if (getLock(namespaceId, id, writeLock).tryLock()) { if (mustExist) { Instance instance = HdfsZooInstance.getInstance(); IZooReaderWriter zk = ZooReaderWriter.getInstance(); if (!zk.exists(ZooUtil.getRoot(instance) + Constants.ZNAMESPACES + "/" + namespaceId)) throw new AcceptableThriftTableOperationException(namespaceId, "", op, TableOperationExceptionType.NAMESPACE_NOTFOUND, "Namespace does not exist"); } log.info("namespace " + namespaceId + " (" + Long.toHexString(id) + ") locked for " + (writeLock ? "write" : "read") + " operation: " + op); return 0; } else return 100; }
private void registerInZooKeeper(String name) throws Exception { String root = ZooUtil.getRoot(serverConfiguration.getInstance()) + Constants.ZTRACERS; IZooReaderWriter zoo = ZooReaderWriter.getInstance(); String path = zoo.putEphemeralSequential(root + "/trace-", name.getBytes(UTF_8)); zoo.exists(path, this); }
public static long reserveTable(String tableId, long tid, boolean writeLock, boolean tableMustExist, TableOperation op) throws Exception { if (getLock(tableId, tid, writeLock).tryLock()) { if (tableMustExist) { Instance instance = HdfsZooInstance.getInstance(); IZooReaderWriter zk = ZooReaderWriter.getInstance(); if (!zk.exists(ZooUtil.getRoot(instance) + Constants.ZTABLES + "/" + tableId)) throw new AcceptableThriftTableOperationException(tableId, "", op, TableOperationExceptionType.NOTFOUND, "Table does not exist"); } log.info("table " + tableId + " (" + Long.toHexString(tid) + ") locked for " + (writeLock ? "write" : "read") + " operation: " + op); return 0; } else return 100; }
@Override public void remove(String path) throws DistributedStoreException { try { log.debug("Removing " + path); path = relative(path); IZooReaderWriter zoo = ZooReaderWriter.getInstance(); if (zoo.exists(path)) zoo.recursiveDelete(path, NodeMissingPolicy.SKIP); cache.clear(); } catch (Exception ex) { throw new DistributedStoreException(ex); } } }
@Override public void initializeSecurity(TCredentials credentials, String principal, byte[] token) throws AccumuloSecurityException, ThriftSecurityException { try { // remove old settings from zookeeper first, if any IZooReaderWriter zoo = ZooReaderWriter.getInstance(); synchronized (zooCache) { zooCache.clear(); if (zoo.exists(zkUserPath)) { zoo.recursiveDelete(zkUserPath, NodeMissingPolicy.SKIP); log.info("Removed " + zkUserPath + "/" + " from zookeeper"); } // prep parent node of users with root username // ACCUMULO-4140 The root user needs to be stored un-base64 encoded in the znode's value byte[] principalData = principal.getBytes(UTF_8); zoo.putPersistentData(zkUserPath, principalData, NodeExistsPolicy.FAIL); // Create the root user in ZK using base64 encoded name (since the name is included in the // znode) createUserNodeInZk(Base64.encodeBase64String(principalData)); } } catch (KeeperException | InterruptedException e) { log.error("Failed to initialize security", e); throw new RuntimeException(e); } }
@Override public void remove(String path) throws DistributedStoreException { try { log.debug("Removing " + path); path = relative(path); IZooReaderWriter zoo = ZooReaderWriter.getInstance(); if (zoo.exists(path)) zoo.recursiveDelete(path, NodeMissingPolicy.SKIP); cache.clear(); } catch (Exception ex) { throw new DistributedStoreException(ex); } } }
public static String getNamespaceId(Instance instance, String tableId, TableOperation op, String namespaceId) throws Exception { if (namespaceId != null) { return namespaceId; } // For ACCUMULO-4575 namespaceId was added in a bug fix release. Since it was added in bug fix // release, we have to ensure we can properly deserialize // older versions. When deserializing an older version, namespaceId will be null. For this case // revert to the old buggy behavior. try { return Tables.getNamespaceId(instance, tableId); } catch (RuntimeException e) { // see if this was caused because the table does not exists IZooReaderWriter zk = ZooReaderWriter.getInstance(); if (!zk.exists(ZooUtil.getRoot(instance) + Constants.ZTABLES + "/" + tableId)) throw new AcceptableThriftTableOperationException(tableId, "", op, TableOperationExceptionType.NOTFOUND, "Table does not exist"); else throw e; } }