@Override public String toString() { return "ComputationPolicy{" + "maxRetries=" + retryPolicy.getMaxRetries() + ", delay=" + retryPolicy.getDelay() + ", delayMax=" + retryPolicy.getMaxDelay() + ", continueOnFailure=" + skipFailure + ", batchCapacity=" + batchCapacity + ", batchThreshold=" + batchThreshold + '}'; } }
boolean maxRetriesExceeded = policy.getMaxRetries() != -1 && failedAttempts > policy.getMaxRetries(); boolean maxDurationExceeded = policy.getMaxDuration() != null && elapsedNanos > policy.getMaxDuration().toNanos(); retriesExceeded = maxRetriesExceeded || maxDurationExceeded;
@Override public void init(ComputationContext context) { super.init(context); // note that we don't use setFlushInterval because this is done by our timer continueOnFailure = context.getPolicy().continueOnFailure(); long backoffDelayMs = context.getPolicy().getRetryPolicy().getDelay().toMillis(); int retries = context.getPolicy().getRetryPolicy().getMaxRetries(); bulkProcessor = getESClient().bulkProcessorBuilder(this) .setConcurrentRequests(0) .setBulkSize(new ByteSizeValue(esBulkSize, ByteSizeUnit.BYTES)) .setBulkActions(esBulkActions) .setBackoffPolicy(BackoffPolicy.exponentialBackoff( TimeValue.timeValueMillis(backoffDelayMs), retries)) .build(); codec = BulkCodecs.getDataBucketCodec(); context.setTimer("flush", System.currentTimeMillis() + flushIntervalMs); }
@Test public void testFixedRetry() { TableRetryPolicy retryPolicy = new TableRetryPolicy(); retryPolicy.withFixedBackoff(Duration.ofMillis(1000)); retryPolicy.withJitter(Duration.ofMillis(100)); retryPolicy.withStopAfterAttempts(4); Assert.assertEquals(TableRetryPolicy.BackoffType.FIXED, retryPolicy.getBackoffType()); RetryPolicy fsRetry = FailsafeAdapter.valueOf(retryPolicy); Assert.assertEquals(1000, fsRetry.getDelay().toMillis()); Assert.assertEquals(100, fsRetry.getJitter().toMillis()); Assert.assertEquals(4, fsRetry.getMaxRetries()); Assert.assertNotNull(retryPolicy.getRetryPredicate()); }