private void updateZkNode(long ts) { if (ts != zkTimestamp) { try { node.setData(LongUtil.toByteArray(ts)); } catch (Exception e) { throw new IllegalStateException(e); } } zkTimestamp = ts; }
public static String getNodePath(Environment env, Long transactorId) { return ZookeeperPath.TRANSACTOR_NODES + "/" + LongUtil.toMaxRadixString(transactorId); } }
/** * Converts given max radix byte array to Long */ public static Long fromMaxRadixByteArray(byte[] value) { return fromMaxRadixString(new String(value, StandardCharsets.UTF_8)); }
private long getOldestTs() throws Exception { CuratorFramework curator = env.getSharedResources().getCurator(); List<String> children; try { children = curator.getChildren().forPath(ZookeeperPath.TRANSACTOR_TIMESTAMPS); } catch (NoNodeException nne) { children = Collections.emptyList(); } long oldestTs = Long.MAX_VALUE; for (String child : children) { Long ts = LongUtil.fromByteArray( curator.getData().forPath(ZookeeperPath.TRANSACTOR_TIMESTAMPS + "/" + child)); if (ts < oldestTs) { oldestTs = ts; } } return oldestTs == Long.MAX_VALUE ? 0 : oldestTs; }
private void updateGcTimestamp() throws Exception { List<String> children; try { children = curator.getChildren().forPath(ZookeeperPath.TRANSACTOR_TIMESTAMPS); } catch (NoNodeException nne) { children = Collections.emptyList(); } long oldestTs = Long.MAX_VALUE; boolean nodeFound = false; for (String child : children) { Long ts = LongUtil.fromByteArray( curator.getData().forPath(ZookeeperPath.TRANSACTOR_TIMESTAMPS + "/" + child)); nodeFound = true; if (ts < oldestTs) { oldestTs = ts; } } if (nodeFound) { updateAdvertisedGcTimestamp(oldestTs); } else { updateAdvertisedGcTimestamp(currentTs); } }
private void updateGcTimestamp() throws Exception { List<String> children; try { children = curator.getChildren().forPath(ZookeeperPath.TRANSACTOR_TIMESTAMPS); } catch (NoNodeException nne) { children = Collections.emptyList(); } long oldestTs = Long.MAX_VALUE; boolean nodeFound = false; for (String child : children) { Long ts = LongUtil.fromByteArray( curator.getData().forPath(ZookeeperPath.TRANSACTOR_TIMESTAMPS + "/" + child)); nodeFound = true; if (ts < oldestTs) { oldestTs = ts; } } if (nodeFound) { updateAdvertisedGcTimestamp(oldestTs); } else { updateAdvertisedGcTimestamp(currentTs); } }
private void updateAdvertisedGcTimestamp(long newTs) throws Exception { if (newTs > advertisedGcTimetamp && isLeader) { // set volatile var before setting in ZK in case Oracle dies... this ensures that client // making a request for timestamps see the new GC time before GC iters advertisedGcTimetamp = newTs; curator.setData().forPath(ZookeeperPath.ORACLE_GC_TIMESTAMP, LongUtil.toByteArray(advertisedGcTimetamp)); } }
public static String getNodePath(Environment env, Long transactorId) { return ZookeeperPath.TRANSACTOR_NODES + "/" + LongUtil.toMaxRadixString(transactorId); } }
void start() throws Exception { advertisedGcTimetamp = LongUtil.fromByteArray(curator.getData().forPath(ZookeeperPath.ORACLE_GC_TIMESTAMP)); TimerTask tt = new TimerTask() { @Override public void run() { try { updateGcTimestamp(); } catch (Exception e) { log.warn("Failed to update GC timestamp.", e); } } }; TimerTask logTask = new TimerTask() { @Override public void run() { log.info("Current timestamp: {}", currentTs); } }; timer = new Timer("Oracle gc update timer", true); long updatePeriod = env.getConfiguration().getLong(FluoConfigurationImpl.ZK_UPDATE_PERIOD_PROP, FluoConfigurationImpl.ZK_UPDATE_PERIOD_MS_DEFAULT); long nextPeriod = 5 * 60 * 1000L; timer.schedule(tt, updatePeriod, updatePeriod); timer.schedule(logTask, 0L, nextPeriod); }
private void updateAdvertisedGcTimestamp(long newTs) throws Exception { if (newTs > advertisedGcTimetamp && isLeader) { // set volatile var before setting in ZK in case Oracle dies... this ensures that client // making a request for timestamps see the new GC time before GC iters advertisedGcTimetamp = newTs; curator.setData().forPath(ZookeeperPath.ORACLE_GC_TIMESTAMP, LongUtil.toByteArray(advertisedGcTimetamp)); } }
/** * Converts given Long to max radix byte array */ public static byte[] toMaxRadixByteArray(Long value) { return toMaxRadixString(value).getBytes(StandardCharsets.UTF_8); }
return LongUtil.fromByteArray(d); } catch (KeeperException | InterruptedException | IOException e) { log.warn("Failed to get oldest timestamp of Oracle from Zookeeper", e);
private void updateZkNode(long ts) { if (ts != zkTimestamp) { try { node.setData(LongUtil.toByteArray(ts)); } catch (Exception e) { throw new IllegalStateException(e); } } zkTimestamp = ts; }
private void logTimedoutTransactor(Long transactorId, long lockTs, Long startTime) { log.warn("Transactor ID {} was unresponsive for {} secs, marking as dead for lockTs <= {}", LongUtil.toMaxRadixString(transactorId), (System.currentTimeMillis() - startTime) / 1000.0, lockTs); }
private long zkNodeValue(TimestampTracker tracker) throws Exception { if (zkNodeExists(tracker) == false) { throw new IllegalStateException("node does not exist"); } return LongUtil.fromByteArray( env.getSharedResources().getCurator().getData().forPath(tracker.getNodePath())); } }
private void allocateTimestamp() throws Exception { Stat stat = new Stat(); byte[] d = curatorFramework.getData().storingStatIn(stat).forPath(maxTsPath); // TODO check that d is expected // TODO check that still server when setting // TODO make num allocated variable... when a server first starts allocate a small amount... the // longer it runs and the busier it is, allocate bigger blocks long newMax = Long.parseLong(new String(d)) + 1000; curatorFramework.setData().withVersion(stat.getVersion()).forPath(maxTsPath, LongUtil.toByteArray(newMax)); maxTs = newMax; if (!isLeader) { throw new IllegalStateException(); } }
private void logTimedoutTransactor(Long transactorId, long lockTs, Long startTime) { log.warn("Transactor ID {} was unresponsive for {} secs, marking as dead for lockTs <= {}", LongUtil.toMaxRadixString(transactorId), (System.currentTimeMillis() - startTime) / 1000.0, lockTs); }
void start() throws Exception { advertisedGcTimetamp = LongUtil.fromByteArray(curator.getData().forPath(ZookeeperPath.ORACLE_GC_TIMESTAMP)); TimerTask tt = new TimerTask() { @Override public void run() { try { updateGcTimestamp(); } catch (Exception e) { log.warn("Failed to update GC timestamp.", e); } } }; TimerTask logTask = new TimerTask() { @Override public void run() { log.info("Current timestamp: {}", currentTs); } }; timer = new Timer("Oracle gc update timer", true); long updatePeriod = env.getConfiguration().getLong(FluoConfigurationImpl.ZK_UPDATE_PERIOD_PROP, FluoConfigurationImpl.ZK_UPDATE_PERIOD_MS_DEFAULT); long nextPeriod = 5 * 60 * 1000L; timer.schedule(tt, updatePeriod, updatePeriod); timer.schedule(logTask, 0L, nextPeriod); }
private void allocateTimestamp() throws Exception { Stat stat = new Stat(); byte[] d = curatorFramework.getData().storingStatIn(stat).forPath(maxTsPath); // TODO check that d is expected // TODO check that still server when setting // TODO make num allocated variable... when a server first starts allocate a small amount... the // longer it runs and the busier it is, allocate bigger blocks long newMax = Long.parseLong(new String(d)) + 1000; curatorFramework.setData().withVersion(stat.getVersion()).forPath(maxTsPath, LongUtil.toByteArray(newMax)); maxTs = newMax; if (!isLeader) { throw new IllegalStateException(); } }
/** * Outputs identifier as String (using max radix) */ @Override public String toString() { return LongUtil.toMaxRadixString(getLongID()); }