RetryHandler(BackoffPolicy backoffPolicy, BiConsumer<BulkRequest, ActionListener<BulkResponse>> consumer, ActionListener<BulkResponse> listener, Scheduler scheduler) { this.backoff = backoffPolicy.iterator(); this.consumer = consumer; this.listener = listener; this.scheduler = scheduler; // in contrast to System.currentTimeMillis(), nanoTime() uses a monotonic clock under the hood this.startTimestampNanos = System.nanoTime(); }
@Override public Iterator<TimeValue> iterator() { return new WrappedBackoffIterator(delegate.iterator(), onBackoff); } }
private void doStoreResult(TaskResult taskResult, ActionListener<Void> listener) { IndexRequestBuilder index = client.prepareIndex(TASK_INDEX, TASK_TYPE, taskResult.getTask().getTaskId().toString()); try (XContentBuilder builder = XContentFactory.contentBuilder(Requests.INDEX_CONTENT_TYPE)) { taskResult.toXContent(builder, ToXContent.EMPTY_PARAMS); index.setSource(builder); } catch (IOException e) { throw new ElasticsearchException("Couldn't convert task result to XContent for [{}]", e, taskResult.getTask()); } doStoreResult(STORE_BACKOFF_POLICY.iterator(), index, listener); }
RetryHandler(BackoffPolicy backoffPolicy, BiConsumer<BulkRequest, ActionListener<BulkResponse>> consumer, ActionListener<BulkResponse> listener, Scheduler scheduler) { this.backoff = backoffPolicy.iterator(); this.consumer = consumer; this.listener = listener; this.scheduler = scheduler; // in contrast to System.currentTimeMillis(), nanoTime() uses a monotonic clock under the hood this.startTimestampNanos = System.nanoTime(); }
@Override public Iterator<TimeValue> iterator() { return Iterators.limit(wrapped.iterator(), maxRetries); } };
@Override public Iterator<TimeValue> iterator() { return new WrappedBackoffIterator(delegate.iterator(), onBackoff); } }
@Override public Iterator<TimeValue> iterator() { return new WrappedBackoffIterator(delegate.iterator(), onBackoff); } }
@Override public Iterator<TimeValue> iterator() { return new WrappedBackoffIterator(delegate.iterator(), onBackoff); } }
@Override public Iterator<TimeValue> iterator() { final long deadline = System.nanoTime() + timeout.nanos(); final Iterator<TimeValue> wrappedIterator = wrapped.iterator(); return new Iterator<TimeValue>() { @Override public boolean hasNext() { return wrappedIterator.hasNext() && System.nanoTime() < deadline; } @Override public TimeValue next() { return wrappedIterator.next(); } }; } };
@Override public Iterator<TimeValue> iterator() { return Iterators.transform(deterministic.iterator(), delay -> timeValueMillis(ThreadLocalRandom.current().nextLong(delay.millis() + 1))); } };
AbstractRetryHandler(Class<? extends Throwable> retryOnThrowable, BackoffPolicy backoffPolicy, Client client, ActionListener<BulkResponse> listener) { this.retryOnThrowable = retryOnThrowable; this.backoff = backoffPolicy.iterator(); this.client = client; this.listener = listener; this.logger = Loggers.getLogger(getClass(), client.settings()); // in contrast to System.currentTimeMillis(), nanoTime() uses a monotonic clock under the hood this.startTimestampNanos = System.nanoTime(); }
public AbstractRetryHandler(Class<? extends Throwable> retryOnThrowable, BackoffPolicy backoffPolicy, Client client, ActionListener<BulkResponse> listener) { this.retryOnThrowable = retryOnThrowable; this.backoff = backoffPolicy.iterator(); this.client = client; this.listener = listener; this.logger = Loggers.getLogger(getClass(), client.settings()); // in contrast to System.currentTimeMillis(), nanoTime() uses a monotonic clock under the hood this.startTimestampNanos = System.nanoTime(); }
public static ConsulResponse<Value> getWithRetry(KeyValueClient kv, String key, BackoffPolicy backoffPolicy) throws TimeoutException { final Iterator<TimeValue> retryDelays = backoffPolicy.iterator(); while (true) { final ConsulResponse<Value> response = kv.getConsulResponseWithValue(key).orElse(null); if (response != null) { return response; } try { if (!retryDelays.hasNext()) { break; } final TimeValue retryDelay = retryDelays.next(); LOGGER.debug("Document does not exist; sleeping for {} and then trying again to get {}", retryDelay, key); retryDelay.timeUnit().sleep(retryDelay.duration()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); break; } } throw new TimeoutException("getWithRetry timed out for key " + key); }
/** * Opens the bucket, retrying connection failures until the operation succeeds. * Any other kind of exception is propagated. */ public static Bucket waitForBucket(CouchbaseCluster cluster, String bucket) throws InterruptedException { final Iterator<TimeValue> retryDelays = truncatedExponentialBackoff( TimeValue.timeValueSeconds(1), TimeValue.timeValueMinutes(1)).iterator(); while (true) { try { return cluster.openBucket(bucket); } catch (Exception e) { if (!ThrowableHelper.hasCause(e, ConnectException.class, RequestCancelledException.class, TemporaryFailureException.class)) { LOGGER.warn("Failed to open bucket", e); throw e; } final TimeValue delay = retryDelays.next(); LOGGER.debug("failed to open bucket", e); LOGGER.warn("Couchbase connection failure, couldn't open bucket. Retrying in {}", delay); MILLISECONDS.sleep(delay.millis()); } } }
TimeValue.timeValueMillis(50), TimeValue.timeValueSeconds(5))) .fullJitter() .timeout(TimeValue.timeValueSeconds(5)).build().iterator();
public static Version waitForElasticsearchAndRequireVersion(RestHighLevelClient esClient, Version required, Version recommended) throws InterruptedException { final Iterator<TimeValue> retryDelays = truncatedExponentialBackoff( TimeValue.timeValueSeconds(1), TimeValue.timeValueMinutes(1)).iterator(); while (true) { try { org.elasticsearch.Version esVersion = esClient.info().getVersion(); final Version version = new Version(esVersion.major, esVersion.minor, esVersion.revision); if (version.compareTo(required) < 0) { throw new RuntimeException("Elasticsearch version " + required + " or later required; actual version is " + version); } if (version.compareTo(recommended) < 0) { LOGGER.warn("Elasticsearch version " + version + " is lower than recommended version " + recommended + "."); } return version; } catch (Exception e) { final TimeValue delay = retryDelays.next(); LOGGER.warn("Failed to connect to Elasticsearch. Retrying in {}", delay, e); if (ThrowableHelper.hasCause(e, ConnectionClosedException.class)) { LOGGER.warn(" Troubleshooting tip: If the Elasticsearch connection failure persists," + " and if Elasticsearch is configured to require TLS/SSL, then make sure the connector is also configured to use secure connections."); } MILLISECONDS.sleep(delay.millis()); } } }
clearBuffer(); final Iterator<TimeValue> waitIntervals = backoffPolicy.iterator(); final Map<Integer, EventDocWriteRequest> vbucketToLastEvent = lenientIndex(r -> r.getEvent().getVbucket(), requests);