public DeadServerList(ServerContext context, String path) { this.path = path; zoo = context.getZooReaderWriter(); try { context.getZooReaderWriter().mkdirs(path); } catch (Exception ex) { log.error("Unable to make parent directories of " + path, ex); } }
private void deleteServerNode(String serverNode) throws InterruptedException, KeeperException { try { context.getZooReaderWriter().delete(serverNode, -1); } catch (NotEmptyException | NoNodeException ex) { // race condition: tserver created the lock after our last check; we'll see it at the next // check } }
public ZooStore(ServerContext context) { this.context = context; cache = new ZooCache(context.getZooReaderWriter(), null); String zkRoot = context.getZooKeeperRoot(); if (zkRoot.endsWith("/")) zkRoot = zkRoot.substring(0, zkRoot.length() - 1); this.basePath = zkRoot; }
private void createUserNodeInZk(String principal) throws KeeperException, InterruptedException { synchronized (zooCache) { zooCache.clear(); IZooReaderWriter zoo = context.getZooReaderWriter(); zoo.putPrivatePersistentData(zkUserPath + "/" + principal, new byte[0], NodeExistsPolicy.FAIL); } }
@Override public void initialize(ServerContext context, boolean initialize) { this.context = context; zooCache = new ZooCache(context.getZooReaderWriter(), null); ZKUserPath = Constants.ZROOT + "/" + context.getInstanceID() + "/users"; }
public static void stop(ServerContext context, String type, long tid) throws KeeperException, InterruptedException { IZooReaderWriter writer = context.getZooReaderWriter(); writer.recursiveDelete(context.getZooKeeperRoot() + "/" + type + "/" + tid, NodeMissingPolicy.SKIP); }
public static long reserveHdfsDirectory(Master env, String directory, long tid) throws KeeperException, InterruptedException { String resvPath = env.getContext().getZooKeeperRoot() + Constants.ZHDFS_RESERVATIONS + "/" + Base64.getEncoder().encodeToString(directory.getBytes(UTF_8)); IZooReaderWriter zk = env.getContext().getZooReaderWriter(); if (ZooReservation.attempt(zk, resvPath, String.format("%016x", tid), "")) { return 0; } else return 50; }
/** * 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 = context.getZooReaderWriter(); zoo.putPrivatePersistentData(ZKUserPath + "/" + user, pass, NodeExistsPolicy.FAIL); } }
public static void removeNamespaceProperty(ServerContext context, Namespace.ID namespaceId, String property) throws InterruptedException, KeeperException { String zPath = getPath(context, namespaceId) + "/" + property; context.getZooReaderWriter().recursiveDelete(zPath, NodeMissingPolicy.SKIP); }
protected SecurityOperation(ServerContext context) { this.context = context; ZKUserPath = Constants.ZROOT + "/" + context.getInstanceID() + "/users"; zooCache = new ZooCache(context.getZooReaderWriter(), null); }
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); }
public static void unreserveHdfsDirectory(Master env, String directory, long tid) throws KeeperException, InterruptedException { String resvPath = env.getContext().getZooKeeperRoot() + Constants.ZHDFS_RESERVATIONS + "/" + Base64.getEncoder().encodeToString(directory.getBytes(UTF_8)); ZooReservation.release(env.getContext().getZooReaderWriter(), resvPath, String.format("%016x", tid)); }
static ProblemReport decodeZooKeeperEntry(ServerContext context, String node) throws IOException, KeeperException, InterruptedException { byte bytes[] = Encoding.decodeBase64FileName(node); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); DataInputStream dis = new DataInputStream(bais); Table.ID tableId = Table.ID.of(dis.readUTF()); String problemType = dis.readUTF(); String resource = dis.readUTF(); String zpath = context.getZooKeeperRoot() + Constants.ZPROBLEMS + "/" + node; byte[] enc = context.getZooReaderWriter().getData(zpath, null); return new ProblemReport(tableId, ProblemType.valueOf(problemType), resource, enc); }
MasterGoalState getMasterGoalState() { while (true) try { byte[] data = context.getZooReaderWriter() .getData(getZooKeeperRoot() + Constants.ZMASTER_GOAL_STATE, null); return MasterGoalState.valueOf(new String(data)); } catch (Exception e) { log.error("Problem getting real goal state from zookeeper: ", e); sleepUninterruptibly(1, TimeUnit.SECONDS); } }
@Override public void initialize(ServerContext context, boolean initialize) { zooCache = new ZooCache(context.getZooReaderWriter(), null); zoo = context.getZooReaderWriter(); String instanceId = context.getInstanceID(); ZKUserPath = ZKSecurityTool.getInstancePath(instanceId) + "/users"; ZKTablePath = ZKSecurityTool.getInstancePath(instanceId) + "/tables"; ZKNamespacePath = ZKSecurityTool.getInstancePath(instanceId) + "/namespaces"; }
@Override public void initialize(ServerContext context, boolean initialize) { this.context = context; zooCache = new ZooCache(context.getZooReaderWriter(), null); ZKUserPath = ZKSecurityTool.getInstancePath(context.getInstanceID()) + "/users"; }
public static void cleanup(ServerContext context, String type, long tid) throws KeeperException, InterruptedException { IZooReaderWriter writer = context.getZooReaderWriter(); writer.recursiveDelete(context.getZooKeeperRoot() + "/" + type + "/" + tid, NodeMissingPolicy.SKIP); writer.recursiveDelete(context.getZooKeeperRoot() + "/" + type + "/" + tid + "-running", NodeMissingPolicy.SKIP); }
void saveToZooKeeper(ServerContext context) throws IOException, KeeperException, InterruptedException { context.getZooReaderWriter().putPersistentData(getZPath(context.getZooKeeperRoot()), encode(), NodeExistsPolicy.OVERWRITE); }
@Override public Repo<Master> call(long tid, Master master) throws Exception { // suppress assignment of tablets to the server if (force) { ZooReaderWriter zoo = master.getContext().getZooReaderWriter(); String path = master.getZooKeeperRoot() + Constants.ZTSERVERS + "/" + server.getLocation(); ZooLock.deleteLock(zoo, path); path = master.getZooKeeperRoot() + Constants.ZDEADTSERVERS + "/" + server.getLocation(); zoo.putPersistentData(path, "forced down".getBytes(UTF_8), NodeExistsPolicy.OVERWRITE); } return null; }
public static void start(ServerContext context, String type, long tid) throws KeeperException, InterruptedException { IZooReaderWriter writer = context.getZooReaderWriter(); writer.putPersistentData(context.getZooKeeperRoot() + "/" + type, new byte[] {}, NodeExistsPolicy.OVERWRITE); writer.putPersistentData(context.getZooKeeperRoot() + "/" + type + "/" + tid, new byte[] {}, NodeExistsPolicy.OVERWRITE); writer.putPersistentData(context.getZooKeeperRoot() + "/" + type + "/" + tid + "-running", new byte[] {}, NodeExistsPolicy.OVERWRITE); }