private void addOrUpdateToken(TokenIdent ident, DelegationTokenInformation info, boolean isUpdate) throws Exception { String nodeCreatePath = getNodePath(ZK_DTSM_TOKENS_ROOT, DELEGATION_TOKEN_PREFIX + ident.getSequenceNumber()); try (ByteArrayOutputStream tokenOs = new ByteArrayOutputStream(); DataOutputStream tokenOut = new DataOutputStream(tokenOs)) { ident.write(tokenOut); tokenOut.writeLong(info.getRenewDate()); tokenOut.writeInt(info.getPassword().length); tokenOut.write(info.getPassword()); if (LOG.isDebugEnabled()) { LOG.debug((isUpdate ? "Updating " : "Storing ") + "ZKDTSMDelegationToken_" + ident.getSequenceNumber()); } if (isUpdate) { zkClient.setData().forPath(nodeCreatePath, tokenOs.toByteArray()) .setVersion(-1); } else { zkClient.create().withMode(CreateMode.PERSISTENT) .forPath(nodeCreatePath, tokenOs.toByteArray()); } } }
@Override public Stat exists(String path, boolean watch) throws KeeperException, InterruptedException { mutex.lock(); try { checkProgrammedFail(); if (stopped) throw new KeeperException.ConnectionLossException(); if (tree.containsKey(path)) { Stat stat = new Stat(); stat.setVersion(tree.get(path).getRight()); return stat; } else { return null; } } finally { mutex.unlock(); } }
@Override public Stat exists(String path, Watcher watcher) throws KeeperException, InterruptedException { mutex.lock(); try { checkProgrammedFail(); if (stopped) throw new KeeperException.ConnectionLossException(); if (watcher != null) { watchers.put(path, watcher); } if (tree.containsKey(path)) { Stat stat = new Stat(); stat.setVersion(tree.get(path).getRight()); return stat; } else { return null; } } finally { mutex.unlock(); } }
@Override public byte[] getData(String path, Watcher watcher, Stat stat) throws KeeperException { mutex.lock(); try { checkProgrammedFail(); Pair<byte[], Integer> value = tree.get(path); if (value == null) { throw new KeeperException.NoNodeException(path); } else { if (watcher != null) { watchers.put(path, watcher); } if (stat != null) { stat.setVersion(value.getRight()); } return value.getLeft(); } } finally { mutex.unlock(); } }
ACLCB(ZooKeeper zk, CountDownLatch latch) { super(zk, latch); stat.setAversion(0); stat.setCversion(0); stat.setEphemeralOwner(0); stat.setVersion(0); }
DataCB(ZooKeeper zk, CountDownLatch latch) { super(zk, latch); stat.setAversion(0); stat.setCversion(0); stat.setEphemeralOwner(0); stat.setVersion(0); }
StatCB(ZooKeeper zk, CountDownLatch latch) { super(zk, latch); stat.setAversion(0); stat.setCversion(0); stat.setEphemeralOwner(0); stat.setVersion(0); }
@Override public LLCRealtimeSegmentZKMetadata getRealtimeSegmentZKMetadata(String realtimeTableName, String segmentName, Stat stat) { LLCRealtimeSegmentZKMetadata metadata = super.getRealtimeSegmentZKMetadata(realtimeTableName, segmentName, stat); switch (_scenario) { case SCENARIO_1_ZK_VERSION_NUM_HAS_CHANGE: // Mock another controller has already updated the segment metadata, which makes the version number self increase. stat.setVersion(_version + 1); break; case SCENARIO_2_METADATA_STATUS_HAS_CHANGE: // Mock another controller has updated the status of the old segment metadata. metadata.setStatus(CommonConstants.Segment.Realtime.Status.DONE); break; } return metadata; } }
stat.setVersion(newVersion); return stat;
@Override public void getData(final String path, final Watcher watcher, final DataCallback cb, final Object ctx) { executor.execute(() -> { checkReadOpDelay(); mutex.lock(); if (getProgrammedFailStatus()) { mutex.unlock(); cb.processResult(failReturnCode.intValue(), path, ctx, null, null); return; } else if (stopped) { mutex.unlock(); cb.processResult(KeeperException.Code.CONNECTIONLOSS.intValue(), path, ctx, null, null); return; } Pair<byte[], Integer> value = tree.get(path); if (value == null) { mutex.unlock(); cb.processResult(KeeperException.Code.NONODE.intValue(), path, ctx, null, null); } else { if (watcher != null) { watchers.put(path, watcher); } Stat stat = new Stat(); stat.setVersion(value.getRight()); mutex.unlock(); cb.processResult(0, path, ctx, value.getLeft(), stat); } }); }
public void verifySetData() { stat.setVersion(1); new StringCB(zk).verifyCreate(); setData(); verify(); }
@Override public void getData(final String path, boolean watch, final DataCallback cb, final Object ctx) { executor.execute(() -> { checkReadOpDelay(); if (getProgrammedFailStatus()) { cb.processResult(failReturnCode.intValue(), path, ctx, null, null); return; } else if (stopped) { cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx, null, null); return; } Pair<byte[], Integer> value; mutex.lock(); try { value = tree.get(path); } finally { mutex.unlock(); } if (value == null) { cb.processResult(KeeperException.Code.NoNode, path, ctx, null, null); } else { Stat stat = new Stat(); stat.setVersion(value.getRight()); cb.processResult(0, path, ctx, value.getLeft(), stat); } }); }
tree.put(path, Pair.of(data, newVersion)); Stat stat = new Stat(); stat.setVersion(newVersion);
public void copyStat(Stat to) { to.setAversion(stat.getAversion()); to.setCtime(stat.getCtime()); to.setCversion(stat.getCversion()); to.setCzxid(stat.getCzxid()); to.setMtime(stat.getMtime()); to.setMzxid(stat.getMzxid()); to.setVersion(stat.getVersion()); to.setEphemeralOwner(stat.getEphemeralOwner()); to.setDataLength(data.length); to.setNumChildren(children.size()); }
synchronized public void copyStat(Stat to) { to.setAversion(stat.getAversion()); to.setCtime(stat.getCtime()); to.setCzxid(stat.getCzxid()); to.setMtime(stat.getMtime()); to.setMzxid(stat.getMzxid()); to.setPzxid(stat.getPzxid()); to.setVersion(stat.getVersion()); to.setEphemeralOwner(getClientEphemeralOwner(stat)); to.setDataLength(data == null ? 0 : data.length); int numChildren = 0; if (this.children != null) { numChildren = children.size(); } // when we do the Cversion we need to translate from the count of the creates // to the count of the changes (v3 semantics) // for every create there is a delete except for the children still present to.setCversion(stat.getCversion()*2 - numChildren); to.setNumChildren(numChildren); }
/** * Create a new Stat, fill in dummy values trying to catch Assert.failure * to copy in client or server code. * * @return a new stat with dummy values */ private Stat newStat() { Stat stat = new Stat(); stat.setAversion(100); stat.setCtime(100); stat.setCversion(100); stat.setCzxid(100); stat.setDataLength(100); stat.setEphemeralOwner(100); stat.setMtime(100); stat.setMzxid(100); stat.setNumChildren(100); stat.setPzxid(100); stat.setVersion(100); return stat; }
static public void copyStat(Stat from, Stat to) { to.setAversion(from.getAversion()); to.setCtime(from.getCtime()); to.setCversion(from.getCversion()); to.setCzxid(from.getCzxid()); to.setMtime(from.getMtime()); to.setMzxid(from.getMzxid()); to.setPzxid(from.getPzxid()); to.setVersion(from.getVersion()); to.setEphemeralOwner(from.getEphemeralOwner()); to.setDataLength(from.getDataLength()); to.setNumChildren(from.getNumChildren()); }
synchronized public void copyStat(Stat to) { to.setAversion(stat.getAversion()); to.setCtime(stat.getCtime()); to.setCzxid(stat.getCzxid()); to.setMtime(stat.getMtime()); to.setMzxid(stat.getMzxid()); to.setPzxid(stat.getPzxid()); to.setVersion(stat.getVersion()); to.setEphemeralOwner(stat.getEphemeralOwner()); to.setDataLength(data == null ? 0 : data.length); int numChildren = 0; if (this.children != null) { numChildren = children.size(); } // when we do the Cversion we need to translate from the count of the creates // to the count of the changes (v3 semantics) // for every create there is a delete except for the children still present to.setCversion(stat.getCversion()*2 - numChildren); to.setNumChildren(numChildren); }
static public void copyStat(Stat from, Stat to) { to.setAversion(from.getAversion()); to.setCtime(from.getCtime()); to.setCversion(from.getCversion()); to.setCzxid(from.getCzxid()); to.setMtime(from.getMtime()); to.setMzxid(from.getMzxid()); to.setVersion(from.getVersion()); to.setEphemeralOwner(from.getEphemeralOwner()); to.setDataLength(from.getDataLength()); to.setNumChildren(from.getNumChildren()); }
static public void copyStat(Stat from, Stat to) { to.setAversion(from.getAversion()); to.setCtime(from.getCtime()); to.setCversion(from.getCversion()); to.setCzxid(from.getCzxid()); to.setMtime(from.getMtime()); to.setMzxid(from.getMzxid()); to.setPzxid(from.getPzxid()); to.setVersion(from.getVersion()); to.setEphemeralOwner(from.getEphemeralOwner()); to.setDataLength(from.getDataLength()); to.setNumChildren(from.getNumChildren()); }