Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Use Lucene `pack` method for `half_float` and `usigned_long` when using `ApproximatePointRangeQuery`.
- Add a mapper for context aware segments grouping criteria ([#19233](https://github.com/opensearch-project/OpenSearch/pull/19233))
- Return full error for GRPC error response ([#19568](https://github.com/opensearch-project/OpenSearch/pull/19568))
- Introduced internal API for retrieving metadata about requested indices from transport actions ([#18523](https://github.com/opensearch-project/OpenSearch/pull/18523))

### Changed
- Faster `terms` query creation for `keyword` field with index and docValues enabled ([#19350](https://github.com/opensearch-project/OpenSearch/pull/19350))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.opensearch.script.mustache;

import org.opensearch.action.search.TransportSearchAction;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.common.inject.Inject;
import org.opensearch.core.xcontent.NamedXContentRegistry;
Expand All @@ -23,8 +24,17 @@ public TransportRenderSearchTemplateAction(
ActionFilters actionFilters,
ScriptService scriptService,
NamedXContentRegistry xContentRegistry,
NodeClient client
NodeClient client,
TransportSearchAction transportSearchAction
) {
super(RenderSearchTemplateAction.NAME, transportService, actionFilters, scriptService, xContentRegistry, client);
super(
RenderSearchTemplateAction.NAME,
transportService,
actionFilters,
scriptService,
xContentRegistry,
client,
transportSearchAction
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@

import org.opensearch.action.search.SearchRequest;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.action.search.TransportSearchAction;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.action.support.HandledTransportAction;
import org.opensearch.action.support.TransportIndicesResolvingAction;
import org.opensearch.cluster.metadata.OptionallyResolvedIndices;
import org.opensearch.cluster.metadata.ResolvedIndices;
import org.opensearch.common.inject.Inject;
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
import org.opensearch.core.action.ActionListener;
Expand All @@ -57,26 +61,30 @@
import java.io.IOException;
import java.util.Collections;

public class TransportSearchTemplateAction extends HandledTransportAction<SearchTemplateRequest, SearchTemplateResponse> {

public class TransportSearchTemplateAction extends HandledTransportAction<SearchTemplateRequest, SearchTemplateResponse>
implements
TransportIndicesResolvingAction<SearchTemplateRequest> {
private static final String TEMPLATE_LANG = MustacheScriptEngine.NAME;

protected final ScriptService scriptService;
protected final NamedXContentRegistry xContentRegistry;
protected final NodeClient client;
private final TransportSearchAction transportSearchAction;

@Inject
public TransportSearchTemplateAction(
TransportService transportService,
ActionFilters actionFilters,
ScriptService scriptService,
NamedXContentRegistry xContentRegistry,
NodeClient client
NodeClient client,
TransportSearchAction transportSearchAction
) {
super(SearchTemplateAction.NAME, transportService, actionFilters, SearchTemplateRequest::new);
this.scriptService = scriptService;
this.xContentRegistry = xContentRegistry;
this.client = client;
this.transportSearchAction = transportSearchAction;
}

public TransportSearchTemplateAction(
Expand All @@ -85,12 +93,14 @@ public TransportSearchTemplateAction(
ActionFilters actionFilters,
ScriptService scriptService,
NamedXContentRegistry xContentRegistry,
NodeClient client
NodeClient client,
TransportSearchAction transportSearchAction
) {
super(actionName, transportService, actionFilters, SearchTemplateRequest::new);
this.scriptService = scriptService;
this.xContentRegistry = xContentRegistry;
this.client = client;
this.transportSearchAction = transportSearchAction;
}

@Override
Expand Down Expand Up @@ -180,4 +190,14 @@ private static void checkRestTotalHitsAsInt(SearchRequest searchRequest, SearchS
}
}
}

@Override
public OptionallyResolvedIndices resolveIndices(SearchTemplateRequest request) {
if (request.getRequest() != null) {
return transportSearchAction.resolveIndices(request.getRequest());
} else {
// For the RenderSearchTemplateAction, request.getRequest() will be null.
return ResolvedIndices.unknown();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@

package org.opensearch.index.reindex;

import org.opensearch.action.search.TransportSearchAction;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.action.support.HandledTransportAction;
import org.opensearch.action.support.TransportIndicesResolvingAction;
import org.opensearch.cluster.metadata.ResolvedIndices;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.inject.Inject;
import org.opensearch.core.action.ActionListener;
Expand All @@ -45,12 +48,15 @@
import org.opensearch.transport.client.Client;
import org.opensearch.transport.client.ParentTaskAssigningClient;

public class TransportDeleteByQueryAction extends HandledTransportAction<DeleteByQueryRequest, BulkByScrollResponse> {
public class TransportDeleteByQueryAction extends HandledTransportAction<DeleteByQueryRequest, BulkByScrollResponse>
implements
TransportIndicesResolvingAction<DeleteByQueryRequest> {

private final ThreadPool threadPool;
private final Client client;
private final ScriptService scriptService;
private final ClusterService clusterService;
private final TransportSearchAction transportSearchAction;

@Inject
public TransportDeleteByQueryAction(
Expand All @@ -59,7 +65,8 @@ public TransportDeleteByQueryAction(
Client client,
TransportService transportService,
ScriptService scriptService,
ClusterService clusterService
ClusterService clusterService,
TransportSearchAction transportSearchAction
) {
super(
DeleteByQueryAction.NAME,
Expand All @@ -71,6 +78,7 @@ public TransportDeleteByQueryAction(
this.client = client;
this.scriptService = scriptService;
this.clusterService = clusterService;
this.transportSearchAction = transportSearchAction;
}

@Override
Expand All @@ -95,4 +103,9 @@ public void doExecute(Task task, DeleteByQueryRequest request, ActionListener<Bu
}
);
}

@Override
public ResolvedIndices resolveIndices(DeleteByQueryRequest request) {
return transportSearchAction.resolveIndices(request.getSearchRequest());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@

package org.opensearch.index.reindex;

import org.opensearch.action.index.IndexAction;
import org.opensearch.action.search.TransportSearchAction;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.action.support.AutoCreateIndex;
import org.opensearch.action.support.HandledTransportAction;
import org.opensearch.action.support.TransportIndicesResolvingAction;
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
import org.opensearch.cluster.metadata.ResolvedIndices;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.inject.Inject;
import org.opensearch.common.settings.Setting;
Expand All @@ -56,7 +60,9 @@

import static java.util.Collections.emptyList;

public class TransportReindexAction extends HandledTransportAction<ReindexRequest, BulkByScrollResponse> {
public class TransportReindexAction extends HandledTransportAction<ReindexRequest, BulkByScrollResponse>
implements
TransportIndicesResolvingAction<ReindexRequest> {
public static final Setting<List<String>> REMOTE_CLUSTER_ALLOWLIST = Setting.listSetting(
"reindex.remote.allowlist",
emptyList(),
Expand Down Expand Up @@ -88,6 +94,8 @@ public class TransportReindexAction extends HandledTransportAction<ReindexReques
private final Reindexer reindexer;

private final ClusterService clusterService;
private final TransportSearchAction transportSearchAction;
private final IndexNameExpressionResolver indexNameExpressionResolver;

@Inject
public TransportReindexAction(
Expand All @@ -100,12 +108,15 @@ public TransportReindexAction(
AutoCreateIndex autoCreateIndex,
Client client,
TransportService transportService,
ReindexSslConfig sslConfig
ReindexSslConfig sslConfig,
TransportSearchAction transportSearchAction
) {
super(ReindexAction.NAME, transportService, actionFilters, ReindexRequest::new);
this.reindexValidator = new ReindexValidator(settings, clusterService, indexNameExpressionResolver, autoCreateIndex);
this.reindexer = new Reindexer(clusterService, client, threadPool, scriptService, sslConfig, remoteExtension);
this.clusterService = clusterService;
this.transportSearchAction = transportSearchAction;
this.indexNameExpressionResolver = indexNameExpressionResolver;
}

@Override
Expand All @@ -129,4 +140,13 @@ public void onFailure(Exception e) {
}
});
}

@Override
public ResolvedIndices resolveIndices(ReindexRequest request) {
return transportSearchAction.resolveIndices(request.getSearchRequest())
.withLocalSubActions(
IndexAction.INSTANCE,
ResolvedIndices.Local.of(indexNameExpressionResolver.resolveDateMathExpression(request.getDestination().index()))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@

import org.apache.logging.log4j.Logger;
import org.opensearch.action.index.IndexRequest;
import org.opensearch.action.search.TransportSearchAction;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.action.support.HandledTransportAction;
import org.opensearch.action.support.TransportIndicesResolvingAction;
import org.opensearch.cluster.ClusterState;
import org.opensearch.cluster.metadata.ResolvedIndices;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.inject.Inject;
import org.opensearch.core.action.ActionListener;
Expand All @@ -55,12 +58,15 @@
import java.util.Map;
import java.util.function.BiFunction;

public class TransportUpdateByQueryAction extends HandledTransportAction<UpdateByQueryRequest, BulkByScrollResponse> {
public class TransportUpdateByQueryAction extends HandledTransportAction<UpdateByQueryRequest, BulkByScrollResponse>
implements
TransportIndicesResolvingAction<UpdateByQueryRequest> {

private final ThreadPool threadPool;
private final Client client;
private final ScriptService scriptService;
private final ClusterService clusterService;
private final TransportSearchAction transportSearchAction;

@Inject
public TransportUpdateByQueryAction(
Expand All @@ -69,7 +75,8 @@ public TransportUpdateByQueryAction(
Client client,
TransportService transportService,
ScriptService scriptService,
ClusterService clusterService
ClusterService clusterService,
TransportSearchAction transportSearchAction
) {
super(
UpdateByQueryAction.NAME,
Expand All @@ -81,6 +88,7 @@ public TransportUpdateByQueryAction(
this.client = client;
this.scriptService = scriptService;
this.clusterService = clusterService;
this.transportSearchAction = transportSearchAction;
}

@Override
Expand All @@ -107,6 +115,11 @@ protected void doExecute(Task task, UpdateByQueryRequest request, ActionListener
);
}

@Override
public ResolvedIndices resolveIndices(UpdateByQueryRequest request) {
return transportSearchAction.resolveIndices(request.getSearchRequest());
}

/**
* Simple implementation of update-by-query using scrolling and bulk.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.opensearch.action.search.SearchAction;
import org.opensearch.action.support.ActionFilter;
import org.opensearch.action.support.ActionFilterChain;
import org.opensearch.action.support.ActionRequestMetadata;
import org.opensearch.action.support.WriteRequest.RefreshPolicy;
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
import org.opensearch.cluster.service.ClusterService;
Expand Down Expand Up @@ -233,6 +234,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void app
Task task,
String action,
Request request,
ActionRequestMetadata<Request, Response> actionRequestMetadata,
ActionListener<Response> listener,
ActionFilterChain<Request, Response> chain
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.index.reindex;

import org.opensearch.action.index.IndexAction;
import org.opensearch.action.index.IndexRequest;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.action.search.TransportSearchAction;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
import org.opensearch.cluster.metadata.ResolvedIndices;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.script.ScriptService;
import org.opensearch.test.OpenSearchTestCase;
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.transport.TransportService;
import org.opensearch.transport.client.Client;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class TransportReindexActionTests extends OpenSearchTestCase {
public void testResolveIndices() {
ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
ThreadPool threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(threadContext);
TransportSearchAction transportSearchAction = mock(TransportSearchAction.class);
when(transportSearchAction.resolveIndices(any())).thenAnswer(i -> ResolvedIndices.of(((SearchRequest) i.getArgument(0)).indices()));
IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext);

TransportReindexAction action = new TransportReindexAction(
Settings.EMPTY,
threadPool,
mock(ActionFilters.class),
indexNameExpressionResolver,
mock(ClusterService.class),
mock(ScriptService.class),
null,
mock(Client.class),
mock(TransportService.class),
mock(ReindexSslConfig.class),
transportSearchAction
);

{
ResolvedIndices resolvedIndices = action.resolveIndices(
new ReindexRequest(new SearchRequest("searched-index"), new IndexRequest("target-index"))
);
assertEquals(
ResolvedIndices.of("searched-index").withLocalSubActions(IndexAction.INSTANCE, ResolvedIndices.Local.of("target-index")),
resolvedIndices
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ protected TransportUpdateByQueryAction.AsyncIndexBySearchAction action(ScriptSer
null,
transportService,
scriptService,
null,
null
);
return new TransportUpdateByQueryAction.AsyncIndexBySearchAction(
Expand Down
Loading
Loading