private static Encoded value(String path) throws KeeperException, InterruptedException { byte[] data = zk.getData(path, null); for (int i = 0; i < data.length; i++) { // does this look like simple ascii? if (data[i] < ' ' || data[i] > '~') return new Encoded("base64", Base64.getEncoder().encodeToString(data)); } return new Encoded(UTF_8.name(), new String(data, UTF_8)); }
public static String getRootTabletDir(ServerContext context) throws IOException { IZooReaderWriter zoo = context.getZooReaderWriter(); String zpath = context.getZooKeeperRoot() + RootTable.ZROOT_TABLET_PATH; try { return new String(zoo.getData(zpath, null), UTF_8); } catch (KeeperException e) { throw new IOException(e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IOException(e); } }
public static void release(IZooReaderWriter zk, String path, String reservationID) throws KeeperException, InterruptedException { byte[] zooData; try { zooData = zk.getData(path, null); } catch (NoNodeException e) { // Just logging a warning, if data is gone then our work here is done. LoggerFactory.getLogger(ZooReservation.class).debug("Node does not exist {}", path); return; } String zooDataStr = new String(zooData, UTF_8); String idInZoo = zooDataStr.split(":")[0]; if (!idInZoo.equals(reservationID)) { throw new IllegalStateException("Tried to release reservation " + path + " with data mismatch " + reservationID + " " + zooDataStr); } zk.recursiveDelete(path, NodeMissingPolicy.SKIP); }
private TStatus _getStatus(long tid) { try { return TStatus.valueOf(new String(zk.getData(getTXPath(tid), null), UTF_8)); } catch (NoNodeException nne) { return TStatus.UNKNOWN; } catch (Exception e) { throw new RuntimeException(e); } }
public static boolean attempt(IZooReaderWriter zk, String path, String reservationID, String debugInfo) throws KeeperException, InterruptedException { if (reservationID.contains(":")) throw new IllegalArgumentException(); while (true) { try { zk.putPersistentData(path, (reservationID + ":" + debugInfo).getBytes(UTF_8), NodeExistsPolicy.FAIL); return true; } catch (NodeExistsException nee) { Stat stat = new Stat(); byte[] zooData; try { zooData = zk.getData(path, stat); } catch (NoNodeException nne) { continue; } String idInZoo = new String(zooData, UTF_8).split(":")[0]; return idInZoo.equals(reservationID); } } }
public static boolean deleteLock(IZooReaderWriter zk, String path, String lockData) throws InterruptedException, KeeperException { List<String> children; children = zk.getChildren(path); if (children == null || children.size() == 0) { throw new IllegalStateException("No lock is held at " + path); } 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"); } byte[] data = zk.getData(path + "/" + lockNode, null); if (lockData.equals(new String(data, UTF_8))) { zk.recursiveDelete(path + "/" + lockNode, NodeMissingPolicy.FAIL); return true; } return false; } }
@Override public SortedMap<Long,byte[]> getEarlierEntries(long entry) { SortedMap<Long,byte[]> result = new TreeMap<>(); try { List<String> children = Collections.emptyList(); try { children = zoo.getChildren(path); } catch (KeeperException.NoNodeException ex) { // the path does not exist (it was deleted or not created yet), that is ok there are no // earlier entries then } for (String name : children) { // this try catch must be done inside the loop because some subset of the children may exist try { byte[] data = zoo.getData(path + "/" + name, null); long order = Long.parseLong(name.substring(PREFIX.length())); if (order <= entry) result.put(order, data); } catch (KeeperException.NoNodeException ex) { // ignored } } } catch (Exception ex) { throw new RuntimeException(ex); } return result; }
public void deleteLocks(IZooReaderWriter zk, String path, String txidStr) throws KeeperException, InterruptedException { // delete any locks assoc w/ fate operation List<String> lockedIds = zk.getChildren(path); for (String id : lockedIds) { List<String> lockNodes = zk.getChildren(path + "/" + id); for (String node : lockNodes) { String lockPath = path + "/" + id + "/" + node; byte[] data = zk.getData(path + "/" + id + "/" + node, null); String lda[] = new String(data, UTF_8).split(":"); if (lda[1].equals(txidStr)) zk.recursiveDelete(lockPath, NodeMissingPolicy.SKIP); } } }
@Override public Serializable getProperty(long tid, String prop) { verifyReserved(tid); try { byte[] data = zk.getData(getTXPath(tid) + "/prop_" + prop, null); if (data[0] == 'O') { byte[] sera = new byte[data.length - 2]; System.arraycopy(data, 2, sera, 0, sera.length); return (Serializable) deserialize(sera); } else if (data[0] == 'S') { return new String(data, 2, data.length - 2, UTF_8); } else { throw new IllegalStateException("Bad property data " + prop); } } catch (NoNodeException nne) { return null; } catch (Exception e) { throw new RuntimeException(e); } }
byte[] ser; try { ser = zk.getData(txpath + "/" + child, null); @SuppressWarnings("unchecked") ReadOnlyRepo<T> repo = (ReadOnlyRepo<T>) deserialize(ser);
.valueOf(new String(zk.getData(path + "/" + txdir, null), UTF_8)); if (status == TStatus.IN_PROGRESS || status == TStatus.FAILED_IN_PROGRESS) { return tid;
@SuppressWarnings("unchecked") @Override public Repo<T> top(long tid) { verifyReserved(tid); for (int i = 0; i < RETRIES; i++) { String txpath = getTXPath(tid); try { String top; try { top = findTop(txpath); if (top == null) { return null; } } catch (KeeperException.NoNodeException ex) { throw new RuntimeException(ex); } byte[] ser = zk.getData(txpath + "/" + top, null); return (Repo<T>) deserialize(ser); } catch (KeeperException.NoNodeException ex) { log.debug("zookeeper error reading " + txpath + ": " + ex, ex); sleepUninterruptibly(100, TimeUnit.MILLISECONDS); continue; } catch (Exception e) { throw new RuntimeException(e); } } return null; }
@Override public Repo<Master> call(long tid, Master environment) throws Exception { String zCompactID = Constants.ZROOT + "/" + environment.getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_ID; String zCancelID = Constants.ZROOT + "/" + environment.getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_CANCEL_ID; IZooReaderWriter zoo = environment.getContext().getZooReaderWriter(); byte[] currentValue = zoo.getData(zCompactID, null); String cvs = new String(currentValue, UTF_8); String[] tokens = cvs.split(","); final long flushID = Long.parseLong(tokens[0]); zoo.mutate(zCancelID, null, null, new Mutator() { @Override public byte[] mutate(byte[] currentValue) { long cid = Long.parseLong(new String(currentValue, UTF_8)); if (cid < flushID) return Long.toString(flushID).getBytes(UTF_8); else return Long.toString(cid).getBytes(UTF_8); } }); return new FinishCancelCompaction(namespaceId, tableId); }
static void getRootLogEntries(ServerContext context, final ArrayList<LogEntry> result) throws KeeperException, InterruptedException, IOException { IZooReaderWriter zoo = context.getZooReaderWriter(); String root = getZookeeperLogLocation(context); // 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)) { try { LogEntry e = LogEntry.fromBytes(zoo.getData(root + "/" + child, null)); // upgrade from !0;!0<< -> +r<< e = new LogEntry(RootTable.EXTENT, 0, e.server, e.filename); result.add(e); } catch (KeeperException.NoNodeException ex) { continue; } } break; } }
for (String instanceName : zk.getChildren(root + Constants.ZINSTANCES)) { String instanceNamePath = root + Constants.ZINSTANCES + "/" + instanceName; byte[] id = zk.getData(instanceNamePath, null); if (id != null && !new String(id, UTF_8).equals(context.getInstanceID())) { try {
byte data[] = zoo.getData(zpath, null); if (new String(data, UTF_8).endsWith("flush")) { flushDefault = true; String path = zooRoot + Constants.ZTABLES + "/" + id + Constants.ZTABLE_CONF + "/" + Property.TABLE_WALOG_ENABLED.getKey(); byte[] data = zoo.getData(path, null); boolean useWAL = Boolean.parseBoolean(new String(data, UTF_8)); zoo.recursiveDelete(path, NodeMissingPolicy.FAIL); : Namespace.ID.DEFAULT; log.debug("Upgrade moving table {} (ID: {}) into namespace with ID {}", new String(zoo.getData(tables + "/" + tableId + Constants.ZTABLE_NAME, null), UTF_8), tableId, targetNamespace); zoo.putPersistentData(tables + "/" + tableId + Constants.ZTABLE_NAMESPACE,
if (Long.parseLong(new String(zoo.getData(zCancelID, null))) >= compactId) {
private static Encoded value(String path) throws KeeperException, InterruptedException, UnsupportedEncodingException { byte[] data = zk.getData(path, null); for (int i = 0; i < data.length; i++) { // does this look like simple ascii? if (data[i] < ' ' || data[i] > '~') return new Encoded("base64", new String(Base64.encodeBase64(data), UTF_8)); } return new Encoded(UTF_8.name().toLowerCase(), new String(data, UTF_8)); }
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), UTF_8); } catch (KeeperException e) { throw new IOException(e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IOException(e); } }
long getCompactionCancelID() { String zTablePath = Constants.ZROOT + "/" + HdfsZooInstance.getInstance().getInstanceID() + Constants.ZTABLES + "/" + extent.getTableId() + Constants.ZTABLE_COMPACT_CANCEL_ID; try { return Long.parseLong(new String(ZooReaderWriter.getRetryingInstance().getData(zTablePath, null), UTF_8)); } catch (KeeperException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } }