public static long getSchemaConvergenceTime(ChronoUnit u) { final long sec = 60L; long l = Temporals.timeUnit(u).convert(sec, TimeUnit.SECONDS); // Check that a narrowing cast to int will not overflow, in case a test decides to try it. Preconditions.checkState(Integer.MIN_VALUE <= l && Integer.MAX_VALUE >= l, "Schema convergence time %d is too large to express as an integer in %s", sec, u); return l; }
@Override public Instant sleepPast(Instant futureTime) throws InterruptedException { Instant now; ChronoUnit unit = getUnit(); /* * Distributed storage managers that rely on timestamps play with the * least significant bit in timestamp longs, turning it on or off to * ensure that deletions are logically ordered before additions within a * single batch mutation. This is not a problem at microsecond * resolution because we pretendulate microsecond resolution by * multiplying currentTimeMillis by 1000, so the LSB can vary freely. * It's also not a problem with nanosecond resolution because the * resolution is just too fine, relative to how long a mutation takes, * for it to matter in practice. But it can lead to corruption at * millisecond resolution (and does, in testing). */ if (unit.equals(TimeUnit.MILLISECONDS)) futureTime = futureTime.plusMillis(1L); while ((now = getTime()).compareTo(futureTime) <= 0) { long delta = getTime(futureTime) - getTime(now); if (0L == delta) delta = 1L; if (log.isTraceEnabled()) { log.trace("Sleeping: now={} targettime={} delta={} {}", new Object[] { now, futureTime, delta, unit }); } Temporals.timeUnit(unit).sleep(delta); } return now; }
@Override public Instant sleepPast(Instant futureTime) throws InterruptedException { Instant now; ChronoUnit unit = getUnit(); /* * Distributed storage managers that rely on timestamps play with the * least significant bit in timestamp longs, turning it on or off to * ensure that deletions are logically ordered before additions within a * single batch mutation. This is not a problem at microsecond * resolution because we pretendulate microsecond resolution by * multiplying currentTimeMillis by 1000, so the LSB can vary freely. * It's also not a problem with nanosecond resolution because the * resolution is just too fine, relative to how long a mutation takes, * for it to matter in practice. But it can lead to corruption at * millisecond resolution (and does, in testing). */ if (unit.equals(TimeUnit.MILLISECONDS)) futureTime = futureTime.plusMillis(1L); while ((now = getTime()).compareTo(futureTime) <= 0) { long delta = getTime(futureTime) - getTime(now); if (0L == delta) delta = 1L; if (log.isTraceEnabled()) { log.trace("Sleeping: now={} targettime={} delta={} {}", new Object[] { now, futureTime, delta, unit }); } Temporals.timeUnit(unit).sleep(delta); } return now; }