Java Code Examples for io.airlift.units.Duration#compareTo()
The following examples show how to use
io.airlift.units.Duration#compareTo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryAssertions.java From presto with Apache License 2.0 | 5 votes |
public static void assertUpdate(QueryRunner queryRunner, Session session, @Language("SQL") String sql, OptionalLong count, Optional<Consumer<Plan>> planAssertion) { long start = System.nanoTime(); MaterializedResult results; Plan queryPlan; if (planAssertion.isPresent()) { MaterializedResultWithPlan resultWithPlan = queryRunner.executeWithPlan(session, sql, WarningCollector.NOOP); queryPlan = resultWithPlan.getQueryPlan(); results = resultWithPlan.getMaterializedResult().toTestTypes(); } else { queryPlan = null; results = queryRunner.execute(session, sql); } Duration queryTime = nanosSince(start); if (queryTime.compareTo(Duration.succinctDuration(1, SECONDS)) > 0) { log.info("FINISHED in presto: %s", queryTime); } if (planAssertion.isPresent()) { planAssertion.get().accept(queryPlan); } if (results.getUpdateType().isEmpty()) { fail("update type is not set"); } if (results.getUpdateCount().isPresent()) { if (count.isEmpty()) { fail("expected no update count, but got " + results.getUpdateCount().getAsLong()); } assertEquals(results.getUpdateCount().getAsLong(), count.getAsLong(), "update count"); } else if (count.isPresent()) { fail("update count is not present"); } }
Example 2
Source File: SqlQueryManager.java From presto with Apache License 2.0 | 5 votes |
/** * 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)); } } }
Example 3
Source File: TaskExecutor.java From presto with Apache License 2.0 | 5 votes |
public String getMaxActiveSplitsInfo() { // Sample output: // // 2 splits have been continuously active for more than 600.00ms seconds // // "20180907_054754_00000_88xi4.1.0-2" tid=99 // at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2708) // at java.util.Formatter.parse(Formatter.java:2560) // at java.util.Formatter.format(Formatter.java:2501) // at ... (more lines of stacktrace) // // "20180907_054754_00000_88xi4.1.0-3" tid=106 // at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2709) // at java.util.Formatter.parse(Formatter.java:2560) // at java.util.Formatter.format(Formatter.java:2501) // at ... (more line of stacktrace) StringBuilder stackTrace = new StringBuilder(); int maxActiveSplitCount = 0; String message = "%s splits have been continuously active for more than %s seconds\n"; for (RunningSplitInfo splitInfo : runningSplitInfos) { Duration duration = Duration.succinctNanos(ticker.read() - splitInfo.getStartTime()); if (duration.compareTo(LONG_SPLIT_WARNING_THRESHOLD) >= 0) { maxActiveSplitCount++; stackTrace.append("\n"); stackTrace.append(format("\"%s\" tid=%s", splitInfo.getThreadId(), splitInfo.getThread().getId())).append("\n"); for (StackTraceElement traceElement : splitInfo.getThread().getStackTrace()) { stackTrace.append("\tat ").append(traceElement).append("\n"); } } } return format(message, maxActiveSplitCount, LONG_SPLIT_WARNING_THRESHOLD).concat(stackTrace.toString()); }
Example 4
Source File: TaskExecutor.java From presto with Apache License 2.0 | 5 votes |
@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; }
Example 5
Source File: LogTestDurationListener.java From presto with Apache License 2.0 | 5 votes |
private void checkForTestHang() { if (hangLogged.get()) { return; } Duration duration = nanosSince(lastChange.get()); if (duration.compareTo(GLOBAL_IDLE_LOGGING_THRESHOLD) < 0) { return; } if (!hangLogged.compareAndSet(false, true)) { return; } Map<String, Long> runningTests = ImmutableMap.copyOf(started); if (!runningTests.isEmpty()) { String testDetails = runningTests.entrySet().stream() .map(entry -> format("%s running for %s", entry.getKey(), nanosSince(entry.getValue()))) .collect(joining("\n\t", "\n\t", "")); dumpAllThreads(format("No test started or completed in %s. Running tests:%s.", GLOBAL_IDLE_LOGGING_THRESHOLD, testDetails)); } else if (finished.get()) { dumpAllThreads(format("Tests finished, but JVM did not shutdown in %s.", GLOBAL_IDLE_LOGGING_THRESHOLD)); } else { dumpAllThreads(format("No test started in %s", GLOBAL_IDLE_LOGGING_THRESHOLD)); } }
Example 6
Source File: LogTestDurationListener.java From presto with Apache License 2.0 | 5 votes |
@Override public void onAfterClass(ITestClass testClass) { if (!enabled) { return; } String name = getName(testClass); Duration duration = endTest(name); if (duration.compareTo(CLASS_LOGGING_THRESHOLD) > 0) { LOG.warn("Tests from %s took %s", name, duration); } }
Example 7
Source File: LogTestDurationListener.java From presto with Apache License 2.0 | 5 votes |
@Override public void afterInvocation(IInvokedMethod method, ITestResult testResult) { if (!enabled) { return; } String name = getName(method); Duration duration = endTest(name); if (duration.compareTo(SINGLE_TEST_LOGGING_THRESHOLD) > 0) { LOG.info("Test %s took %s", name, duration); } }
Example 8
Source File: DriftMethodInvocation.java From drift with Apache License 2.0 | 4 votes |
private synchronized void handleFailure(A address, Throwable throwable) { try { if (throwable instanceof ConnectionFailedException) { failedConnections++; } ExceptionClassification exceptionClassification = retryPolicy.classifyException(throwable, metadata.isIdempotent()); // update stats based on classification attemptedAddresses.add(address); if (exceptionClassification.getHostStatus() == NORMAL) { // only store exception if the server is in a normal state lastException = throwable; invocationAttempts++; } else if (exceptionClassification.getHostStatus() == DOWN || exceptionClassification.getHostStatus() == OVERLOADED) { addressSelector.markdown(address); failedConnectionAttempts.add(address); if (exceptionClassification.getHostStatus() == OVERLOADED) { overloadedRejects++; } } // should retry? Duration duration = succinctNanos(ticker.read() - startTime); if (!exceptionClassification.isRetry().orElse(FALSE)) { // always store exception if non-retryable, so it is added to the exception chain lastException = throwable; fail("Non-retryable exception"); return; } if (invocationAttempts > retryPolicy.getMaxRetries()) { fail(format("Max retry attempts (%s) exceeded", retryPolicy.getMaxRetries())); return; } if (duration.compareTo(retryPolicy.getMaxRetryTime()) >= 0) { fail(format("Max retry time (%s) exceeded", retryPolicy.getMaxRetryTime())); return; } // A request to down or overloaded server is not counted as an attempt // Retries are not delayed based on the invocationAttempts, but may be delayed // based on the failed connection attempts for a selected address if (exceptionClassification.getHostStatus() != NORMAL) { nextAttempt(false); return; } // backoff before next invocation Duration backoffDelay = retryPolicy.getBackoffDelay(invocationAttempts); log.debug("Failed invocation of %s with attempt %s, will retry in %s (overloadedRejects: %s). Exception: %s", metadata.getName(), invocationAttempts, backoffDelay, overloadedRejects, throwable.getMessage()); schedule(backoffDelay, () -> nextAttempt(true)); } catch (Throwable t) { // this should never happen, but ensure that invocation always finishes unexpectedError(t); } }