BulkRequestHandler(BiConsumer<BulkRequest, ActionListener<BulkResponse>> consumer, BackoffPolicy backoffPolicy, BulkProcessor.Listener listener, Scheduler scheduler, int concurrentRequests) { assert concurrentRequests >= 0; this.logger = LogManager.getLogger(getClass()); this.consumer = consumer; this.listener = listener; this.concurrentRequests = concurrentRequests; this.retry = new Retry(backoffPolicy, scheduler); this.semaphore = new Semaphore(concurrentRequests > 0 ? concurrentRequests : 1); }
/** * Invokes #accept(BulkRequest, ActionListener). Backs off on the provided exception and delegates results to the * provided listener. Retries will be scheduled using the class's thread pool. * @param consumer The consumer to which apply the request and listener * @param bulkRequest The bulk request that should be executed. * @param listener A listener that is invoked when the bulk request finishes or completes with an exception. The listener is not * @param settings settings * @deprecated Prefer {@link #withBackoff(BiConsumer, BulkRequest, ActionListener)}. The {@link Settings} isn't used. */ @Deprecated public void withBackoff(BiConsumer<BulkRequest, ActionListener<BulkResponse>> consumer, BulkRequest bulkRequest, ActionListener<BulkResponse> listener, Settings settings) { withBackoff(consumer, bulkRequest, listener); }
semaphore.acquire(); acquired = true; Retry.on(EsRejectedExecutionException.class) .policy(backoffPolicy) .withAsyncBackoff(client, bulkRequest, new ActionListener<BulkResponse>() { @Override public void onResponse(BulkResponse response) {
@Override public void execute(BulkRequest bulkRequest, long executionId) { boolean afterCalled = false; try { listener.beforeBulk(executionId, bulkRequest); BulkResponse bulkResponse = Retry .on(EsRejectedExecutionException.class) .policy(backoffPolicy) .withSyncBackoff(client, bulkRequest); afterCalled = true; listener.afterBulk(executionId, bulkRequest, bulkResponse); } catch (InterruptedException e) { Thread.currentThread().interrupt(); logger.info((Supplier<?>) () -> new ParameterizedMessage("Bulk request {} has been cancelled.", executionId), e); if (!afterCalled) { listener.afterBulk(executionId, bulkRequest, e); } } catch (Exception e) { logger.warn((Supplier<?>) () -> new ParameterizedMessage("Failed to execute bulk request {}.", executionId), e); if (!afterCalled) { listener.afterBulk(executionId, bulkRequest, e); } } }
public AbstractAsyncBulkByScrollAction(BulkByScrollTask task, ESLogger logger, Client client, ThreadPool threadPool, Version smallestNonClientVersion, Request mainRequest, SearchRequest firstSearchRequest, ActionListener<Response> listener) { if (smallestNonClientVersion.before(Version.V_2_3_0)) { throw new IllegalStateException( "Refusing to execute [" + mainRequest + "] because the entire cluster has not been upgraded to 2.3"); } this.task = task; this.logger = logger; this.client = client; this.threadPool = threadPool; this.mainRequest = mainRequest; this.firstSearchRequest = firstSearchRequest; this.listener = listener; retry = Retry.on(EsRejectedExecutionException.class).policy(wrapBackoffPolicy(backoffPolicy())); mainRequest.applyDefaults(); }
/** * Send a bulk request, handling retries. */ void sendBulkRequest(BulkRequest request) { if (task.isCancelled()) { finishHim(null); return; } retry.withAsyncBackoff(client, request, new ActionListener<BulkResponse>() { @Override public void onResponse(BulkResponse response) { onBulkResponse(response); } @Override public void onFailure(Throwable e) { finishHim(e); } }); }
semaphore.acquire(); acquired = true; Retry.on(EsRejectedExecutionException.class) .policy(backoffPolicy) .withAsyncBackoff(client, bulkRequest, new ActionListener<BulkResponse>() { @Override public void onResponse(BulkResponse response) {
@Override public void execute(BulkRequest bulkRequest, long executionId) { boolean afterCalled = false; try { listener.beforeBulk(executionId, bulkRequest); BulkResponse bulkResponse = Retry .on(EsRejectedExecutionException.class) .policy(backoffPolicy) .withSyncBackoff(client, bulkRequest); afterCalled = true; listener.afterBulk(executionId, bulkRequest, bulkResponse); } catch (InterruptedException e) { Thread.currentThread().interrupt(); logger.info("Bulk request {} has been cancelled.", e, executionId); if (!afterCalled) { listener.afterBulk(executionId, bulkRequest, e); } } catch (Throwable t) { logger.warn("Failed to execute bulk request {}.", t, executionId); if (!afterCalled) { listener.afterBulk(executionId, bulkRequest, t); } } }
public AbstractAsyncBulkByScrollAction(BulkByScrollTask task, ESLogger logger, Client client, ThreadPool threadPool, Version smallestNonClientVersion, Request mainRequest, SearchRequest firstSearchRequest, ActionListener<Response> listener) { if (smallestNonClientVersion.before(Version.V_2_3_0)) { throw new IllegalStateException( "Refusing to execute [" + mainRequest + "] because the entire cluster has not been upgraded to 2.3"); } this.task = task; this.logger = logger; this.client = client; this.threadPool = threadPool; this.mainRequest = mainRequest; this.firstSearchRequest = firstSearchRequest; this.listener = listener; retry = Retry.on(EsRejectedExecutionException.class).policy(wrapBackoffPolicy(backoffPolicy())); mainRequest.applyDefaults(); }
/** * Send a bulk request, handling retries. */ void sendBulkRequest(BulkRequest request) { if (task.isCancelled()) { finishHim(null); return; } retry.withAsyncBackoff(client, request, new ActionListener<BulkResponse>() { @Override public void onResponse(BulkResponse response) { onBulkResponse(response); } @Override public void onFailure(Throwable e) { finishHim(e); } }); }
public static Retry on(Class<? extends Throwable> retryOnThrowable) { return new Retry(retryOnThrowable); }
/** * Invokes #accept(BulkRequest, ActionListener). Backs off on the provided exception. Retries will be scheduled using * the class's thread pool. * * @param consumer The consumer to which apply the request and listener * @param bulkRequest The bulk request that should be executed. * @param settings settings * @return a future representing the bulk response returned by the client. * @deprecated prefer {@link #withBackoff(BiConsumer, BulkRequest)}. The {@link Settings} isn't used. */ @Deprecated public PlainActionFuture<BulkResponse> withBackoff(BiConsumer<BulkRequest, ActionListener<BulkResponse>> consumer, BulkRequest bulkRequest, Settings settings) { return withBackoff(consumer, bulkRequest); }
public static Retry on(Class<? extends Throwable> retryOnThrowable) { return new Retry(retryOnThrowable); }
/** * Invokes #accept(BulkRequest, ActionListener). Backs off on the provided exception. Retries will be scheduled using * the class's thread pool. * * @param consumer The consumer to which apply the request and listener * @param bulkRequest The bulk request that should be executed. * @return a future representing the bulk response returned by the client. */ public PlainActionFuture<BulkResponse> withBackoff(BiConsumer<BulkRequest, ActionListener<BulkResponse>> consumer, BulkRequest bulkRequest) { PlainActionFuture<BulkResponse> future = PlainActionFuture.newFuture(); withBackoff(consumer, bulkRequest, future); return future; }
BulkRequestHandler(BiConsumer<BulkRequest, ActionListener<BulkResponse>> consumer, BackoffPolicy backoffPolicy, BulkProcessor.Listener listener, Scheduler scheduler, int concurrentRequests) { assert concurrentRequests >= 0; this.logger = Loggers.getLogger(getClass()); this.consumer = consumer; this.listener = listener; this.concurrentRequests = concurrentRequests; this.retry = new Retry(backoffPolicy, scheduler); this.semaphore = new Semaphore(concurrentRequests > 0 ? concurrentRequests : 1); }
toRelease = semaphore::release; CountDownLatch latch = new CountDownLatch(1); retry.withBackoff(consumer, bulkRequest, new ActionListener<BulkResponse>() { @Override public void onResponse(BulkResponse response) {
BulkRequestHandler(BiConsumer<BulkRequest, ActionListener<BulkResponse>> consumer, BackoffPolicy backoffPolicy, BulkProcessor.Listener listener, Scheduler scheduler, int concurrentRequests) { assert concurrentRequests >= 0; this.logger = Loggers.getLogger(getClass()); this.consumer = consumer; this.listener = listener; this.concurrentRequests = concurrentRequests; this.retry = new Retry(backoffPolicy, scheduler); this.semaphore = new Semaphore(concurrentRequests > 0 ? concurrentRequests : 1); }
/** * Invokes #accept(BulkRequest, ActionListener). Backs off on the provided exception and delegates results to the * provided listener. Retries will be scheduled using the class's thread pool. * @param consumer The consumer to which apply the request and listener * @param bulkRequest The bulk request that should be executed. * @param listener A listener that is invoked when the bulk request finishes or completes with an exception. The listener is not * @param settings settings * @deprecated Prefer {@link #withBackoff(BiConsumer, BulkRequest, ActionListener)}. The {@link Settings} isn't used. */ @Deprecated public void withBackoff(BiConsumer<BulkRequest, ActionListener<BulkResponse>> consumer, BulkRequest bulkRequest, ActionListener<BulkResponse> listener, Settings settings) { withBackoff(consumer, bulkRequest, listener); }
public AbstractAsyncBulkByScrollAction(BulkByScrollTask task, Logger logger, ParentTaskAssigningClient client, ThreadPool threadPool, Request mainRequest, ScriptService scriptService, ClusterState clusterState, ActionListener<BulkByScrollResponse> listener) { this.task = task; if (!task.isWorker()) { throw new IllegalArgumentException("Given task [" + task.getId() + "] must have a child worker"); } this.worker = task.getWorkerState(); this.logger = logger; this.client = client; this.threadPool = threadPool; this.scriptService = scriptService; this.clusterState = clusterState; this.mainRequest = mainRequest; this.listener = listener; BackoffPolicy backoffPolicy = buildBackoffPolicy(); bulkRetry = new Retry(BackoffPolicy.wrap(backoffPolicy, worker::countBulkRetry), threadPool); scrollSource = buildScrollableResultSource(backoffPolicy); scriptApplier = Objects.requireNonNull(buildScriptApplier(), "script applier must not be null"); /* * Default to sorting by doc. We can't do this in the request itself because it is normal to *add* to the sorts rather than replace * them and if we add _doc as the first sort by default then sorts will never work.... So we add it here, only if there isn't * another sort. */ List<SortBuilder<?>> sorts = mainRequest.getSearchRequest().source().sorts(); if (sorts == null || sorts.isEmpty()) { mainRequest.getSearchRequest().source().sort(fieldSort("_doc")); } mainRequest.getSearchRequest().source().version(needsSourceDocumentVersions()); }
/** * Invokes #accept(BulkRequest, ActionListener). Backs off on the provided exception. Retries will be scheduled using * the class's thread pool. * * @param consumer The consumer to which apply the request and listener * @param bulkRequest The bulk request that should be executed. * @param settings settings * @return a future representing the bulk response returned by the client. * @deprecated prefer {@link #withBackoff(BiConsumer, BulkRequest)}. The {@link Settings} isn't used. */ @Deprecated public PlainActionFuture<BulkResponse> withBackoff(BiConsumer<BulkRequest, ActionListener<BulkResponse>> consumer, BulkRequest bulkRequest, Settings settings) { return withBackoff(consumer, bulkRequest); }