@VisibleForTesting protected boolean isTooSoonToCorrect(String tableNameWithType, String segmentId, long now) { Stat stat = new Stat(); LLCRealtimeSegmentZKMetadata metadata = getRealtimeSegmentZKMetadata(tableNameWithType, segmentId, stat); long metadataUpdateTime = stat.getMtime(); if (now < metadataUpdateTime + TimeUnit.MILLISECONDS.convert(MAX_SEGMENT_COMPLETION_TIME_MINS, TimeUnit.MINUTES)) { LOGGER.info("Too soon to correct segment:{} updateTime: {} now:{}", segmentId, metadataUpdateTime, now); return true; } return false; }
@Override public long getRegistryCenterTime(final String key) { long result = 0L; try { persist(key, ""); result = client.checkExists().forPath(key).getMtime(); //CHECKSTYLE:OFF } catch (final Exception ex) { //CHECKSTYLE:ON RegExceptionHandler.handleException(ex); } Preconditions.checkState(0L != result, "Cannot get registry center time."); return result; }
public void print(Stat stat) { out.println("cZxid = 0x" + Long.toHexString(stat.getCzxid())); out.println("ctime = " + new Date(stat.getCtime()).toString()); out.println("mZxid = 0x" + Long.toHexString(stat.getMzxid())); out.println("mtime = " + new Date(stat.getMtime()).toString()); out.println("pZxid = 0x" + Long.toHexString(stat.getPzxid())); out.println("cversion = " + stat.getCversion()); out.println("dataVersion = " + stat.getVersion()); out.println("aclVersion = " + stat.getAversion()); out.println("ephemeralOwner = 0x" + Long.toHexString(stat.getEphemeralOwner())); out.println("dataLength = " + stat.getDataLength()); out.println("numChildren = " + stat.getNumChildren()); } }
ZKStat(org.apache.zookeeper.data.Stat stat) { this.version = stat.getVersion(); this.creationTimestamp = stat.getCtime(); this.modificationTimestamp = stat.getMtime(); }
private static void printStat(Stat stat) { System.err.println("cZxid = 0x" + Long.toHexString(stat.getCzxid())); System.err.println("ctime = " + new Date(stat.getCtime()).toString()); System.err.println("mZxid = 0x" + Long.toHexString(stat.getMzxid())); System.err.println("mtime = " + new Date(stat.getMtime()).toString()); System.err.println("pZxid = 0x" + Long.toHexString(stat.getPzxid())); System.err.println("cversion = " + stat.getCversion()); System.err.println("dataVersion = " + stat.getVersion()); System.err.println("aclVersion = " + stat.getAversion()); System.err.println("ephemeralOwner = 0x" + Long.toHexString(stat.getEphemeralOwner())); System.err.println("dataLength = " + stat.getDataLength()); System.err.println("numChildren = " + stat.getNumChildren()); }
@Nullable public static ZNRecord getZnRecord(@Nonnull ZkHelixPropertyStore<ZNRecord> propertyStore, @Nonnull String path) { Stat stat = new Stat(); ZNRecord znRecord = propertyStore.get(path, stat, AccessOption.PERSISTENT); if (znRecord != null) { znRecord.setCreationTime(stat.getCtime()); znRecord.setModifiedTime(stat.getMtime()); znRecord.setVersion(stat.getVersion()); } return znRecord; }
/** * Locate the controller leader so that we can send LLC segment completion requests to it. * Checks the {@link ControllerLeaderLocator::_cachedControllerLeaderInvalid} flag and fetches the leader from helix if cached value is invalid * * @return The host:port string of the current controller leader. */ public synchronized Pair<String, Integer> getControllerLeader() { if (!_cachedControllerLeaderInvalid) { return _controllerLeaderHostPort; } BaseDataAccessor<ZNRecord> dataAccessor = _helixManager.getHelixDataAccessor().getBaseDataAccessor(); Stat stat = new Stat(); try { ZNRecord znRecord = dataAccessor.get("/" + _clusterName + "/CONTROLLER/LEADER", stat, AccessOption.THROW_EXCEPTION_IFNOTEXIST); String leader = znRecord.getId(); int index = leader.lastIndexOf('_'); String leaderHost = leader.substring(0, index); int leaderPort = Integer.valueOf(leader.substring(index + 1)); _controllerLeaderHostPort = new Pair<>(leaderHost, leaderPort); _cachedControllerLeaderInvalid = false; LOGGER.info("Setting controller leader to be {}:{} as per znode version {}, mtime {}", leaderHost, leaderPort, stat.getVersion(), stat.getMtime()); return _controllerLeaderHostPort; } catch (Exception e) { LOGGER.warn("Could not locate controller leader, exception", e); _cachedControllerLeaderInvalid = true; return null; } }
final Stat hostInfoStat = client.stat(hostInfoPath); if (hostInfoStat != null) { final long mtime = hostInfoStat.getMtime(); final long diff = clock.now().getMillis() - mtime; if (diff < zooKeeperRegistrationTtlMillis) {
private boolean isRolloutTimedOut(final ZooKeeperClient client, final DeploymentGroup deploymentGroup) { final String groupName = deploymentGroup.getName(); final RolloutOptions defaultOptions = RolloutOptions.getDefault(); final long groupTimeoutSetting = deploymentGroup.getRolloutOptions() == null ? defaultOptions.getTimeout() : deploymentGroup.getRolloutOptions().withFallback(defaultOptions).getTimeout(); final long secondsSinceDeploy; try { final String statusPath = Paths.statusDeploymentGroupTasks(groupName); secondsSinceDeploy = MILLISECONDS.toSeconds( System.currentTimeMillis() - client.getNode(statusPath).getStat().getMtime()); } catch (KeeperException e) { // statusPath doesn't exist or some other ZK issue. probably this deployment group // was removed. log.warn("error determining deployment group modification time: name={}", groupName, e); return false; } if (secondsSinceDeploy > groupTimeoutSetting) { log.info("rolling-update on deployment-group name={} has timed out after " + "{} seconds (rolloutOptions.timeout={})", groupName, secondsSinceDeploy, groupTimeoutSetting); return true; } return false; }
Assert.assertEquals(stat.getCtime(), stat.getMtime()); Assert.assertEquals(i + 1, stat.getCversion()); Assert.assertEquals(0, stat.getVersion());
@Test public void testChildren() throws IOException, KeeperException, InterruptedException { String name = "/foo"; zk.create(name, name.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); for(int i = 0; i < 10; i++) { String childname = name + "/bar" + i; zk.create(childname, childname.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); Stat stat; stat = newStat(); zk.getData(name, false, stat); Assert.assertEquals(stat.getCzxid(), stat.getMzxid()); Assert.assertEquals(stat.getCzxid() + i + 1, stat.getPzxid()); Assert.assertEquals(stat.getCtime(), stat.getMtime()); Assert.assertEquals(i + 1, stat.getCversion()); Assert.assertEquals(0, stat.getVersion()); Assert.assertEquals(0, stat.getAversion()); Assert.assertEquals(0, stat.getEphemeralOwner()); Assert.assertEquals(name.length(), stat.getDataLength()); Assert.assertEquals(i + 1, stat.getNumChildren()); } }
@Test public void testBasic() throws IOException, KeeperException, InterruptedException { String name = "/foo"; zk.create(name, name.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); Stat stat; stat = newStat(); zk.getData(name, false, stat); Assert.assertEquals(stat.getCzxid(), stat.getMzxid()); Assert.assertEquals(stat.getCzxid(), stat.getPzxid()); Assert.assertEquals(stat.getCtime(), stat.getMtime()); Assert.assertEquals(0, stat.getCversion()); Assert.assertEquals(0, stat.getVersion()); Assert.assertEquals(0, stat.getAversion()); Assert.assertEquals(0, stat.getEphemeralOwner()); Assert.assertEquals(name.length(), stat.getDataLength()); Assert.assertEquals(0, stat.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()); }
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()); }
private void validateCreateStat(Stat stat, String name) { Assert.assertEquals(stat.getCzxid(), stat.getMzxid()); Assert.assertEquals(stat.getCzxid(), stat.getPzxid()); Assert.assertEquals(stat.getCtime(), stat.getMtime()); Assert.assertEquals(0, stat.getCversion()); Assert.assertEquals(0, stat.getVersion()); Assert.assertEquals(0, stat.getAversion()); Assert.assertEquals(0, stat.getEphemeralOwner()); Assert.assertEquals(name.length(), stat.getDataLength()); Assert.assertEquals(0, stat.getNumChildren()); } }
private void validateCreateStat(Stat stat, String name) { Assert.assertEquals(stat.getCzxid(), stat.getMzxid()); Assert.assertEquals(stat.getCzxid(), stat.getPzxid()); Assert.assertEquals(stat.getCtime(), stat.getMtime()); Assert.assertEquals(0, stat.getCversion()); Assert.assertEquals(0, stat.getVersion()); Assert.assertEquals(0, stat.getAversion()); Assert.assertEquals(0, stat.getEphemeralOwner()); Assert.assertEquals(name.length(), stat.getDataLength()); Assert.assertEquals(0, stat.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()); }