public boolean isExpired(Duration idleTimeout) { Long idleStartTime = this.idleStartTime.get(); return idleStartTime != null && Duration.nanosSince(idleStartTime).compareTo(idleTimeout) > 0; }
public synchronized boolean isFailed() { return future == null || // are we disabled? successTransitionTimestamp == null || // are we in success state? Duration.nanosSince(successTransitionTimestamp).compareTo(warmupInterval) < 0; // are we within the warmup period? }
public synchronized boolean isExpired() { return future == null && disabledTimestamp != null && Duration.nanosSince(disabledTimestamp).compareTo(gcGraceInterval) > 0; }
private static void assertUntilTimeout(Runnable assertion, Duration timeout) { long start = System.nanoTime(); while (!currentThread().isInterrupted()) { try { assertion.run(); return; } catch (AssertionError e) { if (nanosSince(start).compareTo(timeout) > 0) { throw e; } } sleepUninterruptibly(50, MILLISECONDS); } }
private <T> T waitUntilStable(Supplier<T> computation, Duration timeout) { T lastValue = computation.get(); long start = System.nanoTime(); while (!currentThread().isInterrupted() && nanosSince(start).compareTo(timeout) < 0) { sleepUninterruptibly(100, MILLISECONDS); T currentValue = computation.get(); if (currentValue.equals(lastValue)) { return currentValue; } lastValue = currentValue; } throw new UncheckedTimeoutException(); }
public static void assertContainsEventually(Supplier<QueryResult> all, QueryResult expectedSubset, Duration timeout) { long start = System.nanoTime(); while (!Thread.currentThread().isInterrupted()) { try { assertContains(all.get(), expectedSubset); return; } catch (AssertionError e) { if (nanosSince(start).compareTo(timeout) > 0) { throw e; } } sleepUninterruptibly(50, MILLISECONDS); } }
public static void assertContainsEventually(Supplier<MaterializedResult> all, MaterializedResult expectedSubset, Duration timeout) { long start = System.nanoTime(); while (!Thread.currentThread().isInterrupted()) { try { assertContains(all.get(), expectedSubset); return; } catch (AssertionError e) { if (nanosSince(start).compareTo(timeout) > 0) { throw e; } } sleepUninterruptibly(50, MILLISECONDS); } }
public synchronized void verifyInitialMinimumWorkersRequirement() { if (minimumWorkerRequirementMet) { return; } if (currentCount < initializationMinCount && nanosSince(createNanos).compareTo(initializationMaxWait) < 0) { throw new PrestoException(SERVER_STARTING_UP, format("Cluster is still initializing, there are insufficient active worker nodes (%s) to run query", currentCount)); } minimumWorkerRequirementMet = true; }
protected static void assertQueryFailsEventually(QueryRunner queryRunner, Session session, @Language("SQL") String sql, @Language("RegExp") String expectedMessageRegExp, Duration timeout) { long start = System.nanoTime(); while (!Thread.currentThread().isInterrupted()) { try { assertQueryFails(queryRunner, session, sql, expectedMessageRegExp); return; } catch (AssertionError e) { if (nanosSince(start).compareTo(timeout) > 0) { throw e; } } sleepUninterruptibly(50, MILLISECONDS); } }
if (attempt >= maxAttempts || Duration.nanosSince(startTime).compareTo(maxRetryTime) >= 0) { addSuppressed(e, suppressedExceptions); throw e;
for (RunningSplitInfo splitInfo : runningSplitInfos) { Duration duration = Duration.succinctNanos(ticker.read() - splitInfo.getStartTime()); if (duration.compareTo(LONG_SPLIT_WARNING_THRESHOLD) >= 0) { maxActiveSplitCount++; stackTrace.append("\n");
if (attempt >= maxAttempts || Duration.nanosSince(startTime).compareTo(maxRetryTime) >= 0) { addSuppressed(e, suppressedExceptions); throw e;
checkArgument(group.getSoftCpuLimit().get().compareTo(group.getHardCpuLimit().get()) <= 0, "Soft CPU limit cannot be greater than hard CPU limit");
if (succinctNanos(System.nanoTime() - lastRefresh.get()).compareTo(maxRefreshInterval) > 0) { lastRefresh.set(0);
@Managed public long getRunAwaySplitCount() { int count = 0; for (RunningSplitInfo splitInfo : runningSplitInfos) { Duration duration = Duration.succinctNanos(ticker.read() - splitInfo.getStartTime()); if (duration.compareTo(LONG_SPLIT_WARNING_THRESHOLD) > 0) { count++; } } return count; }
/** * Enforce query CPU time limits */ private void enforceCpuLimits() { for (QueryExecution query : queryTracker.getAllQueries()) { Duration cpuTime = query.getTotalCpuTime(); Duration sessionLimit = getQueryMaxCpuTime(query.getSession()); Duration limit = Ordering.natural().min(maxQueryCpuTime, sessionLimit); if (cpuTime.compareTo(limit) > 0) { query.fail(new ExceededCpuLimitException(limit)); } } }
public void processRows(StatementClient client) throws IOException { while (client.isRunning()) { Iterable<List<Object>> data = client.currentData().getData(); if (data != null) { for (List<Object> row : data) { processRow(unmodifiableList(row)); } } if (nanosSince(bufferStart).compareTo(MAX_BUFFER_TIME) >= 0) { flush(false); } client.advance(); } }
if (attempts > 0 && sinceStart.compareTo(requestTimeoutNanos) > 0) { state.compareAndSet(State.RUNNING, State.CLIENT_ERROR); throw new RuntimeException(format("Error fetching next (attempts: %s, duration: %s)", attempts, sinceStart), cause);
outOfMemory && !queryKilled && nanosSince(lastTimeNotOutOfMemory).compareTo(killOnOutOfMemoryDelay) > 0) { if (isLastKilledQueryGone()) { callOomKiller(runningQueries);
private synchronized void refreshIfNecessary() { if (Duration.nanosSince(lastUpdateTimestamp).compareTo(MAX_AGE) > 0) { refreshNodesInternal(); } }