private static Double optionalDurationToSeconds(Duration duration) { return duration != null ? duration.convertTo(SECONDS).getValue() : null; }
@Override public void onFailure(Throwable t) { checkNotHoldsLock(this); log.error("Request to delete %s failed %s", location, t); if (!(t instanceof PrestoException) && backoff.failure()) { String message = format("Error closing remote buffer (%s - %s failures, failure duration %s, total failed request time %s)", location, backoff.getFailureCount(), backoff.getFailureDuration().convertTo(SECONDS), backoff.getFailureRequestTimeTotal().convertTo(SECONDS)); t = new PrestoException(REMOTE_BUFFER_CLOSE_FAILED, message, t); } handleFailure(t, resultFuture); } }, pageBufferClientCallbackExecutor);
@Override public void onFailure(Throwable t) { log.debug("Request to %s failed %s", uri, t); checkNotHoldsLock(this); t = rewriteException(t); if (!(t instanceof PrestoException) && backoff.failure()) { String message = format("%s (%s - %s failures, failure duration %s, total failed request time %s)", WORKER_NODE_ERROR, uri, backoff.getFailureCount(), backoff.getFailureDuration().convertTo(SECONDS), backoff.getFailureRequestTimeTotal().convertTo(SECONDS)); t = new PageTransportTimeoutException(fromUri(uri), message, t); } handleFailure(t, resultFuture); } }, pageBufferClientCallbackExecutor);
private static void executeQueries(List<String> queries, ParallelQueryRunner parallelQueryRunner, int parallelism) throws Exception { Duration duration = parallelQueryRunner.executeCommands(parallelism, queries); System.out.printf("%2d: %s\n", parallelism, duration.convertTo(TimeUnit.SECONDS)); }
private static Double optionalDurationToSeconds(Duration duration) { return duration != null ? duration.convertTo(SECONDS).getValue() : null; }
public Duration convertToMostSuccinctTimeUnit() { TimeUnit unitToUse = NANOSECONDS; for (TimeUnit unitToTest : TIME_UNITS) { // since time units are powers of ten, we can get rounding errors here, so fuzzy match if (getValue(unitToTest) > 0.9999) { unitToUse = unitToTest; } else { break; } } return convertTo(unitToUse); }
private synchronized Duration elapsedErrorDuration() { if (errorStopwatch.isRunning()) { errorStopwatch.stop(); } long nanos = errorStopwatch.elapsed(TimeUnit.NANOSECONDS); return new Duration(nanos, TimeUnit.NANOSECONDS).convertTo(TimeUnit.SECONDS); }
private void startDiscovery() { compactionDiscoveryService.scheduleWithFixedDelay(() -> { try { // jitter to avoid overloading database long interval = (long) compactionDiscoveryInterval.convertTo(SECONDS).getValue(); SECONDS.sleep(ThreadLocalRandom.current().nextLong(1, interval)); discoverShards(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (Throwable t) { log.error(t, "Error discovering shards to compact"); } }, 0, compactionDiscoveryInterval.toMillis(), TimeUnit.MILLISECONDS); }
private void startDiscovery() { compactionDiscoveryService.scheduleWithFixedDelay(() -> { try { // jitter to avoid overloading database long interval = (long) compactionDiscoveryInterval.convertTo(SECONDS).getValue(); SECONDS.sleep(ThreadLocalRandom.current().nextLong(1, interval)); discoverShards(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (Throwable t) { log.error(t, "Error discovering shards to compact"); } }, 0, compactionDiscoveryInterval.toMillis(), TimeUnit.MILLISECONDS); }
new Duration(taskQueuedTime, NANOSECONDS).convertTo(MILLISECONDS), new Duration(taskEnd - taskStart, NANOSECONDS).convertTo(MILLISECONDS), 1.0 * totalCpuTime / (taskEnd - taskStart) ); Duration totalQueueTime = new Duration(split.getQueuedNanos(), NANOSECONDS).convertTo(MILLISECONDS); Duration executionWallTime = new Duration(split.getDoneNanos() - split.getStartNanos(), NANOSECONDS).convertTo(MILLISECONDS); Duration totalWallTime = new Duration(split.getDoneNanos() - split.getCreatedNanos(), NANOSECONDS).convertTo(MILLISECONDS); System.out.printf(" %8s %8s %8s\n", totalQueueTime, executionWallTime, totalWallTime);
@Override public void onFailure(Throwable t) { checkNotHoldsLock(this); log.error("Request to delete %s failed %s", location, t); if (!(t instanceof PrestoException) && backoff.failure()) { String message = format("Error closing remote buffer (%s - %s failures, failure duration %s, total failed request time %s)", location, backoff.getFailureCount(), backoff.getFailureDuration().convertTo(SECONDS), backoff.getFailureRequestTimeTotal().convertTo(SECONDS)); t = new PrestoException(REMOTE_BUFFER_CLOSE_FAILED, message, t); } handleFailure(t, resultFuture); } }, pageBufferClientCallbackExecutor);
@Override public void onFailure(Throwable t) { checkNotHoldsLock(this); log.error("Request to delete %s failed %s", location, t); if (!(t instanceof PrestoException) && backoff.failure()) { String message = format("Error closing remote buffer (%s - %s failures, failure duration %s, total failed request time %s)", location, backoff.getFailureCount(), backoff.getFailureDuration().convertTo(SECONDS), backoff.getFailureRequestTimeTotal().convertTo(SECONDS)); t = new PrestoException(REMOTE_BUFFER_CLOSE_FAILED, message, t); } handleFailure(t, resultFuture); } }, pageBufferClientCallbackExecutor);
@Override public void onFailure(Throwable t) { log.debug("Request to %s failed %s", uri, t); checkNotHoldsLock(this); t = rewriteException(t); if (!(t instanceof PrestoException) && backoff.failure()) { String message = format("%s (%s - %s failures, failure duration %s, total failed request time %s)", WORKER_NODE_ERROR, uri, backoff.getFailureCount(), backoff.getFailureDuration().convertTo(SECONDS), backoff.getFailureRequestTimeTotal().convertTo(SECONDS)); t = new PageTransportTimeoutException(fromUri(uri), message, t); } handleFailure(t, resultFuture); } }, pageBufferClientCallbackExecutor);
@Override public void onFailure(Throwable t) { log.debug("Request to %s failed %s", uri, t); checkNotHoldsLock(this); t = rewriteException(t); if (!(t instanceof PrestoException) && backoff.failure()) { String message = format("%s (%s - %s failures, failure duration %s, total failed request time %s)", WORKER_NODE_ERROR, uri, backoff.getFailureCount(), backoff.getFailureDuration().convertTo(SECONDS), backoff.getFailureRequestTimeTotal().convertTo(SECONDS)); t = new PageTransportTimeoutException(fromUri(uri), message, t); } handleFailure(t, resultFuture); } }, pageBufferClientCallbackExecutor);
taskUri, backoff.getFailureCount(), backoff.getTimeSinceLastSuccess().convertTo(SECONDS))); errorsSinceLastSuccess.forEach(exception::addSuppressed); throw exception;
@Test(dataProvider = "conversions") public void testConversions(TimeUnit unit, TimeUnit toTimeUnit, double factor) { Duration duration = new Duration(1, unit).convertTo(toTimeUnit); assertThat(duration.getUnit()).isEqualTo(toTimeUnit); assertThat(duration.getValue()).isCloseTo(factor, withPercentage(0.1)); assertThat(duration.getValue(toTimeUnit)).isCloseTo(factor, withPercentage(0.1)); }
@SuppressWarnings("ResultOfMethodCallIgnored") @Test public void invalidParameters() { failDurationConstruction(Double.NEGATIVE_INFINITY, MILLISECONDS); failDurationConstruction(Double.POSITIVE_INFINITY, MILLISECONDS); failDurationConstruction(Double.NaN, MILLISECONDS); failDurationConstruction(42, null); failDurationConstruction(-42, MILLISECONDS); Duration duration = new Duration(42, MILLISECONDS); try { duration.convertTo(null); fail("Expected NullPointerException"); } catch (NullPointerException e) { // ok } try { duration.toString(null); fail("Expected NullPointerException"); } catch (NullPointerException e) { // ok } }