Search in sources :

Example 1 with ParentTaskAssigningClient

use of org.opensearch.client.ParentTaskAssigningClient in project OpenSearch by opensearch-project.

the class TransportUpdateByQueryAction method doExecute.

@Override
protected void doExecute(Task task, UpdateByQueryRequest request, ActionListener<BulkByScrollResponse> listener) {
    BulkByScrollTask bulkByScrollTask = (BulkByScrollTask) task;
    BulkByScrollParallelizationHelper.startSlicedAction(request, bulkByScrollTask, UpdateByQueryAction.INSTANCE, listener, client, clusterService.localNode(), () -> {
        ClusterState state = clusterService.state();
        ParentTaskAssigningClient assigningClient = new ParentTaskAssigningClient(client, clusterService.localNode(), bulkByScrollTask);
        new AsyncIndexBySearchAction(bulkByScrollTask, logger, assigningClient, threadPool, scriptService, request, state, listener).start();
    });
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) ParentTaskAssigningClient(org.opensearch.client.ParentTaskAssigningClient)

Example 2 with ParentTaskAssigningClient

use of org.opensearch.client.ParentTaskAssigningClient in project OpenSearch by opensearch-project.

the class AsyncBulkByScrollActionTests method testStartNextScrollRetriesOnRejectionAndSucceeds.

public void testStartNextScrollRetriesOnRejectionAndSucceeds() throws Exception {
    // this test primarily tests ClientScrollableHitSource but left it to test integration to status
    client.scrollsToReject = randomIntBetween(0, testRequest.getMaxRetries() - 1);
    // use fail() onResponse handler because mocked search never fires on listener.
    ClientScrollableHitSource hitSource = new ClientScrollableHitSource(logger, buildTestBackoffPolicy(), threadPool, testTask.getWorkerState()::countSearchRetry, r -> fail(), ExceptionsHelper::reThrowIfNotNull, new ParentTaskAssigningClient(client, localNode, testTask), testRequest.getSearchRequest());
    hitSource.setScroll(scrollId());
    hitSource.startNextScroll(TimeValue.timeValueSeconds(0));
    assertBusy(() -> assertEquals(client.scrollsToReject + 1, client.scrollAttempts.get()));
    if (listener.isDone()) {
        Object result = listener.get();
        fail("Expected listener not to be done but it was and had " + result);
    }
    assertBusy(() -> assertNotNull("There should be a scroll attempt pending that we didn't reject", client.lastScroll.get()));
    assertEquals(client.scrollsToReject, testTask.getStatus().getSearchRetries());
}
Also used : ExceptionsHelper(org.opensearch.ExceptionsHelper) ParentTaskAssigningClient(org.opensearch.client.ParentTaskAssigningClient)

Example 3 with ParentTaskAssigningClient

use of org.opensearch.client.ParentTaskAssigningClient in project OpenSearch by opensearch-project.

the class AsyncBulkByScrollActionTests method testStartNextScrollRetriesOnRejectionButFailsOnTooManyRejections.

public void testStartNextScrollRetriesOnRejectionButFailsOnTooManyRejections() throws Exception {
    // this test primarily tests ClientScrollableHitSource but left it to test integration to status
    client.scrollsToReject = testRequest.getMaxRetries() + randomIntBetween(1, 100);
    assertExactlyOnce(onFail -> {
        Consumer<Exception> validingOnFail = e -> {
            assertNotNull(ExceptionsHelper.unwrap(e, OpenSearchRejectedExecutionException.class));
            onFail.run();
        };
        ClientScrollableHitSource hitSource = new ClientScrollableHitSource(logger, buildTestBackoffPolicy(), threadPool, testTask.getWorkerState()::countSearchRetry, r -> fail(), validingOnFail, new ParentTaskAssigningClient(client, localNode, testTask), testRequest.getSearchRequest());
        hitSource.setScroll(scrollId());
        hitSource.startNextScroll(TimeValue.timeValueSeconds(0));
        assertBusy(() -> assertEquals(testRequest.getMaxRetries() + 1, client.scrollAttempts.get()));
    });
    assertNull("There shouldn't be a scroll attempt pending that we didn't reject", client.lastScroll.get());
    assertEquals(testRequest.getMaxRetries(), testTask.getStatus().getSearchRetries());
}
Also used : OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) Matchers.hasToString(org.hamcrest.Matchers.hasToString) RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) IndexResponse(org.opensearch.action.index.IndexResponse) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Version(org.opensearch.Version) ActionRequest(org.opensearch.action.ActionRequest) Collections.singletonList(java.util.Collections.singletonList) ReduceSearchPhaseException(org.opensearch.action.search.ReduceSearchPhaseException) SearchFailure(org.opensearch.index.reindex.ScrollableHitSource.SearchFailure) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) Map(java.util.Map) ActionType(org.opensearch.action.ActionType) ActionListener(org.opensearch.action.ActionListener) ActionResponse(org.opensearch.action.ActionResponse) DeleteRequest(org.opensearch.action.delete.DeleteRequest) Client(org.opensearch.client.Client) TimeValue(org.opensearch.common.unit.TimeValue) Index(org.opensearch.index.Index) SearchHit(org.opensearch.search.SearchHit) NoOpClient(org.opensearch.test.client.NoOpClient) ExceptionsHelper(org.opensearch.ExceptionsHelper) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) TaskManager(org.opensearch.tasks.TaskManager) TimeValue.timeValueSeconds(org.opensearch.common.unit.TimeValue.timeValueSeconds) Failure(org.opensearch.action.bulk.BulkItemResponse.Failure) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ActionFilters(org.opensearch.action.support.ActionFilters) Matchers.contains(org.hamcrest.Matchers.contains) BytesArray(org.opensearch.common.bytes.BytesArray) FilterClient(org.opensearch.client.FilterClient) DocWriteResponse(org.opensearch.action.DocWriteResponse) UpdateRequest(org.opensearch.action.update.UpdateRequest) XContentType(org.opensearch.common.xcontent.XContentType) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.containsString(org.hamcrest.Matchers.containsString) UpdateResponse(org.opensearch.action.update.UpdateResponse) ThreadPool(org.opensearch.threadpool.ThreadPool) DocWriteRequest(org.opensearch.action.DocWriteRequest) SearchHits(org.opensearch.search.SearchHits) ArrayList(java.util.ArrayList) SearchScrollRequest(org.opensearch.action.search.SearchScrollRequest) DeleteResponse(org.opensearch.action.delete.DeleteResponse) SearchRequest(org.opensearch.action.search.SearchRequest) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Before(org.junit.Before) TaskId(org.opensearch.tasks.TaskId) InternalSearchResponse(org.opensearch.search.internal.InternalSearchResponse) TotalHits(org.apache.lucene.search.TotalHits) ExecutionException(java.util.concurrent.ExecutionException) ShardSearchFailure(org.opensearch.action.search.ShardSearchFailure) Hit(org.opensearch.index.reindex.ScrollableHitSource.Hit) SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException) Assert(org.junit.Assert) Matchers.either(org.hamcrest.Matchers.either) AbstractRunnable(org.opensearch.common.util.concurrent.AbstractRunnable) BulkRequest(org.opensearch.action.bulk.BulkRequest) OpenSearchException(org.opensearch.OpenSearchException) Collections.synchronizedSet(java.util.Collections.synchronizedSet) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Collections.singleton(java.util.Collections.singleton) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BackoffPolicy(org.opensearch.action.bulk.BackoffPolicy) BulkItemResponse(org.opensearch.action.bulk.BulkItemResponse) After(org.junit.After) Delayed(java.util.concurrent.Delayed) IdentityHashMap(java.util.IdentityHashMap) Collections.emptyList(java.util.Collections.emptyList) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Result(org.opensearch.action.DocWriteResponse.Result) Task(org.opensearch.tasks.Task) RestStatus(org.opensearch.rest.RestStatus) BackoffPolicy.constantBackoff(org.opensearch.action.bulk.BackoffPolicy.constantBackoff) TransportAction(org.opensearch.action.support.TransportAction) List(java.util.List) Matchers.equalTo(org.hamcrest.Matchers.equalTo) IntStream(java.util.stream.IntStream) TimeValue.timeValueMillis(org.opensearch.common.unit.TimeValue.timeValueMillis) CheckedConsumer(org.opensearch.common.CheckedConsumer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collections.newSetFromMap(java.util.Collections.newSetFromMap) ClearScrollResponse(org.opensearch.action.search.ClearScrollResponse) SearchResponse(org.opensearch.action.search.SearchResponse) Collections.emptyMap(java.util.Collections.emptyMap) Matchers.empty(org.hamcrest.Matchers.empty) ParentTaskAssigningClient(org.opensearch.client.ParentTaskAssigningClient) Iterator(java.util.Iterator) Collections.emptySet(java.util.Collections.emptySet) VersionConflictEngineException(org.opensearch.index.engine.VersionConflictEngineException) ShardId(org.opensearch.index.shard.ShardId) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) BulkResponse(org.opensearch.action.bulk.BulkResponse) ClearScrollRequest(org.opensearch.action.search.ClearScrollRequest) IndexRequest(org.opensearch.action.index.IndexRequest) TestUtil.randomSimpleString(org.apache.lucene.util.TestUtil.randomSimpleString) Collections(java.util.Collections) ParentTaskAssigningClient(org.opensearch.client.ParentTaskAssigningClient) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) ReduceSearchPhaseException(org.opensearch.action.search.ReduceSearchPhaseException) ExecutionException(java.util.concurrent.ExecutionException) SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException) OpenSearchException(org.opensearch.OpenSearchException) VersionConflictEngineException(org.opensearch.index.engine.VersionConflictEngineException)

Example 4 with ParentTaskAssigningClient

use of org.opensearch.client.ParentTaskAssigningClient in project OpenSearch by opensearch-project.

the class TransportDeleteByQueryAction method doExecute.

@Override
public void doExecute(Task task, DeleteByQueryRequest request, ActionListener<BulkByScrollResponse> listener) {
    BulkByScrollTask bulkByScrollTask = (BulkByScrollTask) task;
    BulkByScrollParallelizationHelper.startSlicedAction(request, bulkByScrollTask, DeleteByQueryAction.INSTANCE, listener, client, clusterService.localNode(), () -> {
        ParentTaskAssigningClient assigningClient = new ParentTaskAssigningClient(client, clusterService.localNode(), bulkByScrollTask);
        new AsyncDeleteByQueryAction(bulkByScrollTask, logger, assigningClient, threadPool, request, scriptService, listener).start();
    });
}
Also used : ParentTaskAssigningClient(org.opensearch.client.ParentTaskAssigningClient)

Example 5 with ParentTaskAssigningClient

use of org.opensearch.client.ParentTaskAssigningClient in project OpenSearch by opensearch-project.

the class Reindexer method execute.

public void execute(BulkByScrollTask task, ReindexRequest request, ActionListener<BulkByScrollResponse> listener) {
    ActionListener<BulkByScrollResponse> remoteReindexActionListener = getRemoteReindexWrapperListener(listener, request);
    BulkByScrollParallelizationHelper.executeSlicedAction(task, request, ReindexAction.INSTANCE, listener, client, clusterService.localNode(), () -> {
        ParentTaskAssigningClient assigningClient = new ParentTaskAssigningClient(client, clusterService.localNode(), task);
        AsyncIndexBySearchAction searchAction = new AsyncIndexBySearchAction(task, logger, assigningClient, threadPool, scriptService, reindexSslConfig, request, remoteReindexActionListener, getInterceptor(request));
        searchAction.start();
    });
}
Also used : ParentTaskAssigningClient(org.opensearch.client.ParentTaskAssigningClient)

Aggregations

ParentTaskAssigningClient (org.opensearch.client.ParentTaskAssigningClient)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ExceptionsHelper (org.opensearch.ExceptionsHelper)2 SearchRequest (org.opensearch.action.search.SearchRequest)2 TaskId (org.opensearch.tasks.TaskId)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.emptySet (java.util.Collections.emptySet)1 Collections.newSetFromMap (java.util.Collections.newSetFromMap)1 Collections.singleton (java.util.Collections.singleton)1 Collections.singletonList (java.util.Collections.singletonList)1 Collections.synchronizedSet (java.util.Collections.synchronizedSet)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1