Skip to content

Commit

Permalink
Fork CCS search-shards handling (#98209)
Browse files Browse the repository at this point in the history
Similar to #98124, this action involves doing potentially O(#shards)
work on both sender and receiver so it'd be best to avoid the transport
worker.
  • Loading branch information
DaveCTurner committed Aug 8, 2023
1 parent 847ec45 commit cd48337
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/98209.yaml
@@ -0,0 +1,5 @@
pr: 98209
summary: Fork CCS search-shards handling
area: Search
type: bug
issues: []
Expand Up @@ -57,7 +57,7 @@ public TransportClusterSearchShardsAction(
ClusterSearchShardsRequest::new,
indexNameExpressionResolver,
ClusterSearchShardsResponse::new,
ThreadPool.Names.SAME
ThreadPool.Names.SEARCH_COORDINATION
);
this.indicesService = indicesService;
}
Expand Down
Expand Up @@ -74,7 +74,6 @@
import org.elasticsearch.transport.RemoteTransportException;
import org.elasticsearch.transport.Transport;
import org.elasticsearch.transport.TransportRequestOptions;
import org.elasticsearch.transport.TransportResponseHandler;
import org.elasticsearch.transport.TransportService;

import java.util.ArrayList;
Expand Down Expand Up @@ -663,6 +662,7 @@ static void collectSearchShards(
) {
@Override
void innerOnResponse(SearchShardsResponse searchShardsResponse) {
assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.SEARCH_COORDINATION);
searchShardsResponses.put(clusterAlias, searchShardsResponse);
}

Expand All @@ -676,6 +676,7 @@ Map<String, SearchShardsResponse> createFinalResponse() {
skipUnavailable == false,
ActionListener.wrap(connection -> {
final String[] indices = entry.getValue().indices();
final Executor responseExecutor = transportService.getThreadPool().executor(ThreadPool.Names.SEARCH_COORDINATION);
// TODO: support point-in-time
if (searchContext == null && connection.getTransportVersion().onOrAfter(TransportVersion.V_8_500_010)) {
SearchShardsRequest searchShardsRequest = new SearchShardsRequest(
Expand All @@ -692,11 +693,7 @@ Map<String, SearchShardsResponse> createFinalResponse() {
SearchShardsAction.NAME,
searchShardsRequest,
TransportRequestOptions.EMPTY,
new ActionListenerResponseHandler<>(
singleListener,
SearchShardsResponse::new,
TransportResponseHandler.TRANSPORT_WORKER
)
new ActionListenerResponseHandler<>(singleListener, SearchShardsResponse::new, responseExecutor)
);
} else {
ClusterSearchShardsRequest searchShardsRequest = new ClusterSearchShardsRequest(indices).indicesOptions(
Expand All @@ -710,7 +707,7 @@ Map<String, SearchShardsResponse> createFinalResponse() {
new ActionListenerResponseHandler<>(
singleListener.map(SearchShardsResponse::fromLegacyResponse),
ClusterSearchShardsResponse::new,
TransportResponseHandler.TRANSPORT_WORKER
responseExecutor
)
);
}
Expand Down
Expand Up @@ -60,7 +60,7 @@ public TransportSearchShardsAction(
SearchTransportService searchTransportService,
IndexNameExpressionResolver indexNameExpressionResolver
) {
super(SearchShardsAction.NAME, transportService, actionFilters, SearchShardsRequest::new);
super(SearchShardsAction.NAME, transportService, actionFilters, SearchShardsRequest::new, ThreadPool.Names.SEARCH_COORDINATION);
this.transportService = transportService;
this.transportSearchAction = transportSearchAction;
this.searchService = searchService;
Expand All @@ -73,6 +73,7 @@ public TransportSearchShardsAction(

@Override
protected void doExecute(Task task, SearchShardsRequest searchShardsRequest, ActionListener<SearchShardsResponse> listener) {
assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.SEARCH_COORDINATION);
final long relativeStartNanos = System.nanoTime();
SearchRequest original = new SearchRequest(searchShardsRequest.indices()).indicesOptions(searchShardsRequest.indicesOptions())
.routing(searchShardsRequest.routing())
Expand Down

0 comments on commit cd48337

Please sign in to comment.