@Override public void initializeSecurity(TCredentials credentials, String principal, byte[] token) throws AccumuloSecurityException { 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 zoo.putPersistentData(ZKUserPath, principal.getBytes(UTF_8), NodeExistsPolicy.FAIL); constructUser(principal, ZKSecurityTool.createPass(token)); } } catch (KeeperException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } catch (InterruptedException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } catch (AccumuloException e) { log.error("{}", e.getMessage(), e); throw new RuntimeException(e); } }
/** @param args : the name or UUID of the instance to be deleted */ public static void main(String[] args) throws Exception { Opts opts = new Opts(); opts.parseArgs(DeleteZooInstance.class.getName(), args); IZooReaderWriter zk = ZooReaderWriter.getInstance(); // try instance name: Set<String> instances = new HashSet<String>(zk.getChildren(Constants.ZROOT + Constants.ZINSTANCES)); Set<String> uuids = new HashSet<String>(zk.getChildren(Constants.ZROOT)); uuids.remove("instances"); if (instances.contains(opts.instance)) { String path = Constants.ZROOT + Constants.ZINSTANCES + "/" + opts.instance; byte[] data = zk.getData(path, null); deleteRetry(zk, path); deleteRetry(zk, Constants.ZROOT + "/" + new String(data, UTF_8)); } else if (uuids.contains(opts.instance)) { // look for the real instance name for (String instance : instances) { String path = Constants.ZROOT + Constants.ZINSTANCES + "/" + instance; byte[] data = zk.getData(path, null); if (opts.instance.equals(new String(data, UTF_8))) deleteRetry(zk, path); } deleteRetry(zk, Constants.ZROOT + "/" + opts.instance); } }
public static void removeUnusedWALEntries( KeyExtent extent, List<LogEntry> logEntries, ZooLock zooLock) { if (extent.isRootTablet()) { for (LogEntry entry : logEntries) { String root = getZookeeperLogLocation(); while (true) { try { IZooReaderWriter zoo = ZooReaderWriter.getInstance(); if (zoo.isLockHeld(zooLock.getLockID())) zoo.recursiveDelete(root + "/" + entry.filename, NodeMissingPolicy.SKIP); break; } catch (Exception e) { log.error(e, e); } UtilWaitThread.sleep(1000); } } } else { Mutation m = new Mutation(extent.getMetadataEntry()); for (LogEntry entry : logEntries) { m.putDelete(LogColumnFamily.NAME, new Text(entry.toString())); } update(SystemCredentials.get(), zooLock, m, extent); } }
public static void addLogEntry(Credentials credentials, LogEntry entry, ZooLock zooLock) { if (entry.extent.isRootTablet()) { String root = getZookeeperLogLocation(); while (true) { try { IZooReaderWriter zoo = ZooReaderWriter.getInstance(); if (zoo.isLockHeld(zooLock.getLockID())) { String[] parts = entry.filename.split("/"); String uniqueId = parts[parts.length - 1]; zoo.putPersistentData( root + "/" + uniqueId, entry.toBytes(), NodeExistsPolicy.OVERWRITE); } break; } catch (KeeperException e) { log.error(e, e); } catch (InterruptedException e) { log.error(e, e); } catch (IOException e) { log.error(e, e); } UtilWaitThread.sleep(1000); } } else { Mutation m = new Mutation(entry.getRow()); m.put(entry.getColumnFamily(), entry.getColumnQualifier(), entry.getValue()); update(credentials, zooLock, m, entry.extent); } }
/** * Sets up the user in ZK for the provided user. No checking for existence is done here, it should * be done before calling. */ private void constructUser(String user, byte[] pass) throws KeeperException, InterruptedException { synchronized (zooCache) { zooCache.clear(); IZooReaderWriter zoo = ZooReaderWriter.getInstance(); zoo.putPrivatePersistentData(ZKUserPath + "/" + user, pass, NodeExistsPolicy.FAIL); } }
public static String getRootTabletDir() throws IOException { IZooReaderWriter zoo = ZooReaderWriter.getInstance(); String zpath = ZooUtil.getRoot(HdfsZooInstance.getInstance()) + RootTable.ZROOT_TABLET_PATH; try { return new String(zoo.getData(zpath, null), Constants.UTF8); } catch (KeeperException e) { throw new IOException(e); } catch (InterruptedException e) { throw new IOException(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); } }
@Override public Repo<Master> call(long id, Master master) throws Exception { Instance instance = master.getInstance(); IZooReaderWriter zoo = ZooReaderWriter.getInstance(); Utils.tableNameLock.lock(); try { Utils.checkNamespaceDoesNotExist(instance, newName, namespaceId, TableOperation.RENAME); final String tap = ZooUtil.getRoot(instance) + Constants.ZNAMESPACES + "/" + namespaceId + Constants.ZNAMESPACE_NAME; zoo.mutate( tap, null, null, new Mutator() { @Override public byte[] mutate(byte[] current) throws Exception { final String currentName = new String(current); if (currentName.equals(newName)) return null; // assume in this case the operation is running again, so we are done if (!currentName.equals(oldName)) { throw new AcceptableThriftTableOperationException( null, oldName, TableOperation.RENAME, TableOperationExceptionType.NAMESPACE_NOTFOUND, "Name changed while processing"); } return newName.getBytes(); } }); Tables.clearCache(instance); } finally { Utils.tableNameLock.unlock(); Utils.unreserveNamespace(namespaceId, id, true); } LoggerFactory.getLogger(RenameNamespace.class) .debug("Renamed namespace " + namespaceId + " " + oldName + " " + newName); return null; }
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; } } }
private static void getRootLogEntries(ArrayList<LogEntry> result) throws KeeperException, InterruptedException, IOException { IZooReaderWriter zoo = ZooReaderWriter.getInstance(); String root = getZookeeperLogLocation(); // there's a little race between getting the children and fetching // the data. The log can be removed in between. while (true) { result.clear(); for (String child : zoo.getChildren(root)) { LogEntry e = new LogEntry(); try { e.fromBytes(zoo.getData(root + "/" + child, null)); // upgrade from !0;!0<< -> +r<< e.extent = RootTable.EXTENT; result.add(e); } catch (KeeperException.NoNodeException ex) { continue; } } break; } }
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()); zoo.exists(path, this); }