org.apache.zookeeper.server.DataTree Java Examples
The following examples show how to use
org.apache.zookeeper.server.DataTree.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EmbeddedZooKeeper.java From centraldogma with Apache License 2.0 | 6 votes |
@Nullable private static DataTree dataTree(@Nullable EmbeddedZooKeeper peer) { if (peer == null) { return null; } final ZooKeeperServer activeServer = peer.getActiveServer(); if (activeServer == null) { return null; } final ZKDatabase database = activeServer.getZKDatabase(); if (database == null) { return null; } return database.getDataTree(); }
Example #2
Source File: ZKLogFormatter.java From helix with Apache License 2.0 | 6 votes |
private static void readSnapshotLog(String snapshotPath) throws Exception { FileInputStream fis = new FileInputStream(snapshotPath); BinaryInputArchive ia = BinaryInputArchive.getArchive(fis); Map<Long, Integer> sessions = new HashMap<Long, Integer>(); DataTree dt = new DataTree(); FileHeader header = new FileHeader(); header.deserialize(ia, "fileheader"); if (header.getMagic() != FileSnap.SNAP_MAGIC) { throw new IOException("mismatching magic headers " + header.getMagic() + " != " + FileSnap.SNAP_MAGIC); } SerializeUtils.deserializeSnapshot(dt, ia, sessions); if (bw != null) { bw.write(sessions.toString()); bw.newLine(); } else { System.out.println(sessions); } traverse(dt, 1, "/"); }
Example #3
Source File: ReconfigBuilderImpl.java From curator with Apache License 2.0 | 5 votes |
@Override public void performBackgroundOperation(final OperationAndData<Void> data) throws Exception { try { final TimeTrace trace = client.getZookeeperClient().startTracer("ReconfigBuilderImpl-Background"); AsyncCallback.DataCallback callback = new AsyncCallback.DataCallback() { @Override public void processResult(int rc, String path, Object ctx, byte[] bytes, Stat stat) { trace.commit(); if ( (responseStat != null) && (stat != null) ) { DataTree.copyStat(stat, responseStat); } CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.RECONFIG, rc, path, null, ctx, stat, bytes, null, null, null, null); client.processBackgroundOperation(data, event); } }; ((ZooKeeperAdmin)client.getZooKeeper()).reconfigure(joining, leaving, newMembers, fromConfig, callback, backgrounding.getContext()); } catch ( Throwable e ) { backgrounding.checkError(e, null); } }
Example #4
Source File: CachedModeledFrameworkImpl.java From curator with Apache License 2.0 | 5 votes |
@Override public AsyncStage<T> read(Stat storingStatIn) { return internalRead(n -> { if ( storingStatIn != null ) { DataTree.copyStat(n.stat(), storingStatIn); } return n.model(); }, this::exceptionally); }
Example #5
Source File: ZkCacheBaseDataAccessor.java From helix with Apache License 2.0 | 5 votes |
@Override public T get(String path, Stat stat, int options) { String clientPath = path; String serverPath = prependChroot(clientPath); Cache<T> cache = getCache(serverPath); if (cache != null) { T record = null; ZNode znode = cache.get(serverPath); if (znode != null) { // TODO: shall return a deep copy instead of reference record = ((T) znode.getData()); if (stat != null) { DataTree.copyStat(znode.getStat(), stat); } return record; } else { // if cache miss, fall back to zk and update cache try { cache.lockWrite(); record = _baseAccessor .get(serverPath, stat, options | AccessOption.THROW_EXCEPTION_IFNOTEXIST); cache.update(serverPath, record, stat); } catch (ZkNoNodeException e) { if (AccessOption.isThrowExceptionIfNotExist(options)) { throw e; } } finally { cache.unlockWrite(); } return record; } } // no cache return _baseAccessor.get(serverPath, stat, options); }
Example #6
Source File: ZKLogFormatter.java From helix with Apache License 2.0 | 5 votes |
private static void traverse(DataTree dt, int startId, String startPath) throws Exception { LinkedList<Pair> queue = new LinkedList<Pair>(); queue.add(new Pair(startPath, startId)); while (!queue.isEmpty()) { Pair pair = queue.removeFirst(); String path = pair._path; DataNode head = dt.getNode(path); Stat stat = new Stat(); byte[] data = null; try { data = dt.getData(path, stat, null); } catch (NoNodeException e) { e.printStackTrace(); } // print the node format(startId, pair, head, data); Set<String> children = head.getChildren(); if (children != null) { for (String child : children) { String childPath; if (path.endsWith("/")) { childPath = path + child; } else { childPath = path + "/" + child; } queue.add(new Pair(childPath, startId)); } } startId = startId + 1; } }
Example #7
Source File: MockHelixPropertyStore.java From ambry with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * * This is not thread safe if some thread is setting {@link #readLatch}. */ @Override public T get(String path, Stat stat, int options) { if (readLatch != null) { readLatch.countDown(); } T result = pathToRecords.get(path); if (result != null && stat != null) { Stat resultStat = pathToStats.get(path); DataTree.copyStat(resultStat, stat); } return result; }
Example #8
Source File: TestConfigSetsAPIZkFailure.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public DataTree getDataTree() { return zkdb.getDataTree(); }
Example #9
Source File: CreateBuilderImpl.java From curator with Apache License 2.0 | 4 votes |
@Override public void performBackgroundOperation(final OperationAndData<PathAndBytes> operationAndData) throws Exception { try { final OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("CreateBuilderImpl-Background"); final byte[] data = operationAndData.getData().getData(); AsyncCallback.Create2Callback callback = new AsyncCallback.Create2Callback() { @Override public void processResult(int rc, String path, Object ctx, String name, Stat stat) { trace.setReturnCode(rc).setRequestBytesLength(data).setPath(path).commit(); if ( (stat != null) && (storingStat != null) ) { DataTree.copyStat(stat, storingStat); } if ( (rc == KeeperException.Code.NONODE.intValue()) && createParentsIfNeeded ) { backgroundCreateParentsThenNode(client, operationAndData, operationAndData.getData().getPath(), backgrounding, acling.getACLProviderForParents(), createParentsAsContainers); } else if ( (rc == KeeperException.Code.NODEEXISTS.intValue()) && setDataIfExists ) { backgroundSetData(client, operationAndData, operationAndData.getData().getPath(), backgrounding); } else { sendBackgroundResponse(rc, path, ctx, name, stat, operationAndData); } } }; client.getZooKeeper().create ( operationAndData.getData().getPath(), data, acling.getAclList(operationAndData.getData().getPath()), createMode, callback, backgrounding.getContext(), ttl ); } catch ( Throwable e ) { backgrounding.checkError(e, null); } }