|
48 | 48 | import org.elasticsearch.transport.RemoteClusterService;
|
49 | 49 | import org.elasticsearch.transport.Transport;
|
50 | 50 | import org.elasticsearch.transport.TransportActionProxy;
|
| 51 | +import org.elasticsearch.transport.TransportChannel; |
51 | 52 | import org.elasticsearch.transport.TransportException;
|
52 | 53 | import org.elasticsearch.transport.TransportRequest;
|
53 | 54 | import org.elasticsearch.transport.TransportRequestOptions;
|
@@ -111,9 +112,9 @@ public void sendFreeContext(Transport.Connection connection, long contextId, fin
|
111 | 112 | }
|
112 | 113 |
|
113 | 114 | public void sendCanMatch(Transport.Connection connection, final ShardSearchTransportRequest request, SearchTask task, final
|
114 |
| - ActionListener<CanMatchResponse> listener) { |
| 115 | + ActionListener<SearchService.CanMatchResponse> listener) { |
115 | 116 | transportService.sendChildRequest(connection, QUERY_CAN_MATCH_NAME, request, task,
|
116 |
| - TransportRequestOptions.EMPTY, new ActionListenerResponseHandler<>(listener, CanMatchResponse::new)); |
| 117 | + TransportRequestOptions.EMPTY, new ActionListenerResponseHandler<>(listener, SearchService.CanMatchResponse::new)); |
117 | 118 | }
|
118 | 119 |
|
119 | 120 | public void sendClearAllScrollContexts(Transport.Connection connection, final ActionListener<TransportResponse> listener) {
|
@@ -348,99 +349,74 @@ public void onFailure(Exception e) {
|
348 | 349 |
|
349 | 350 | transportService.registerRequestHandler(QUERY_ACTION_NAME, ThreadPool.Names.SAME, ShardSearchTransportRequest::new,
|
350 | 351 | (request, channel, task) -> {
|
351 |
| - searchService.executeQueryPhase(request, (SearchTask) task, new ActionListener<SearchPhaseResult>() { |
352 |
| - @Override |
353 |
| - public void onResponse(SearchPhaseResult searchPhaseResult) { |
354 |
| - try { |
355 |
| - channel.sendResponse(searchPhaseResult); |
356 |
| - } catch (IOException e) { |
357 |
| - throw new UncheckedIOException(e); |
358 |
| - } |
359 |
| - } |
360 |
| - |
361 |
| - @Override |
362 |
| - public void onFailure(Exception e) { |
363 |
| - try { |
364 |
| - channel.sendResponse(e); |
365 |
| - } catch (IOException e1) { |
366 |
| - throw new UncheckedIOException(e1); |
367 |
| - } |
368 |
| - } |
369 |
| - }); |
| 352 | + searchService.executeQueryPhase(request, (SearchTask) task, new ChannelActionListener<>(channel)); |
370 | 353 | });
|
371 | 354 | TransportActionProxy.registerProxyAction(transportService, QUERY_ACTION_NAME,
|
372 | 355 | (request) -> ((ShardSearchRequest)request).numberOfShards() == 1 ? QueryFetchSearchResult::new : QuerySearchResult::new);
|
373 | 356 |
|
374 |
| - transportService.registerRequestHandler(QUERY_ID_ACTION_NAME, ThreadPool.Names.SEARCH, QuerySearchRequest::new, |
| 357 | + transportService.registerRequestHandler(QUERY_ID_ACTION_NAME, ThreadPool.Names.SAME, QuerySearchRequest::new, |
375 | 358 | (request, channel, task) -> {
|
376 |
| - QuerySearchResult result = searchService.executeQueryPhase(request, (SearchTask)task); |
377 |
| - channel.sendResponse(result); |
| 359 | + searchService.executeQueryPhase(request, (SearchTask)task, new ChannelActionListener<>(channel)); |
378 | 360 | });
|
379 | 361 | TransportActionProxy.registerProxyAction(transportService, QUERY_ID_ACTION_NAME, QuerySearchResult::new);
|
380 | 362 |
|
381 |
| - transportService.registerRequestHandler(QUERY_SCROLL_ACTION_NAME, ThreadPool.Names.SEARCH, InternalScrollSearchRequest::new, |
| 363 | + transportService.registerRequestHandler(QUERY_SCROLL_ACTION_NAME, ThreadPool.Names.SAME, InternalScrollSearchRequest::new, |
382 | 364 | (request, channel, task) -> {
|
383 |
| - ScrollQuerySearchResult result = searchService.executeQueryPhase(request, (SearchTask)task); |
384 |
| - channel.sendResponse(result); |
| 365 | + searchService.executeQueryPhase(request, (SearchTask)task, new ChannelActionListener<>(channel)); |
385 | 366 | });
|
386 | 367 | TransportActionProxy.registerProxyAction(transportService, QUERY_SCROLL_ACTION_NAME, ScrollQuerySearchResult::new);
|
387 | 368 |
|
388 |
| - transportService.registerRequestHandler(QUERY_FETCH_SCROLL_ACTION_NAME, ThreadPool.Names.SEARCH, InternalScrollSearchRequest::new, |
| 369 | + transportService.registerRequestHandler(QUERY_FETCH_SCROLL_ACTION_NAME, ThreadPool.Names.SAME, InternalScrollSearchRequest::new, |
389 | 370 | (request, channel, task) -> {
|
390 |
| - ScrollQueryFetchSearchResult result = searchService.executeFetchPhase(request, (SearchTask)task); |
391 |
| - channel.sendResponse(result); |
| 371 | + searchService.executeFetchPhase(request, (SearchTask)task, new ChannelActionListener<>(channel)); |
392 | 372 | });
|
393 | 373 | TransportActionProxy.registerProxyAction(transportService, QUERY_FETCH_SCROLL_ACTION_NAME, ScrollQueryFetchSearchResult::new);
|
394 | 374 |
|
395 |
| - transportService.registerRequestHandler(FETCH_ID_SCROLL_ACTION_NAME, ThreadPool.Names.SEARCH, ShardFetchRequest::new, |
| 375 | + transportService.registerRequestHandler(FETCH_ID_SCROLL_ACTION_NAME, ThreadPool.Names.SAME, ShardFetchRequest::new, |
396 | 376 | (request, channel, task) -> {
|
397 |
| - FetchSearchResult result = searchService.executeFetchPhase(request, (SearchTask)task); |
398 |
| - channel.sendResponse(result); |
| 377 | + searchService.executeFetchPhase(request, (SearchTask)task, new ChannelActionListener<>(channel)); |
399 | 378 | });
|
400 | 379 | TransportActionProxy.registerProxyAction(transportService, FETCH_ID_SCROLL_ACTION_NAME, FetchSearchResult::new);
|
401 | 380 |
|
402 |
| - transportService.registerRequestHandler(FETCH_ID_ACTION_NAME, ThreadPool.Names.SEARCH, true, true, ShardFetchSearchRequest::new, |
| 381 | + transportService.registerRequestHandler(FETCH_ID_ACTION_NAME, ThreadPool.Names.SAME, true, true, ShardFetchSearchRequest::new, |
403 | 382 | (request, channel, task) -> {
|
404 |
| - FetchSearchResult result = searchService.executeFetchPhase(request, (SearchTask)task); |
405 |
| - channel.sendResponse(result); |
| 383 | + searchService.executeFetchPhase(request, (SearchTask)task, new ChannelActionListener<>(channel)); |
406 | 384 | });
|
407 | 385 | TransportActionProxy.registerProxyAction(transportService, FETCH_ID_ACTION_NAME, FetchSearchResult::new);
|
408 | 386 |
|
409 | 387 | // this is cheap, it does not fetch during the rewrite phase, so we can let it quickly execute on a networking thread
|
410 | 388 | transportService.registerRequestHandler(QUERY_CAN_MATCH_NAME, ThreadPool.Names.SAME, ShardSearchTransportRequest::new,
|
411 | 389 | (request, channel, task) -> {
|
412 |
| - boolean canMatch = searchService.canMatch(request); |
413 |
| - channel.sendResponse(new CanMatchResponse(canMatch)); |
| 390 | + searchService.canMatch(request, new ChannelActionListener<>(channel)); |
414 | 391 | });
|
415 | 392 | TransportActionProxy.registerProxyAction(transportService, QUERY_CAN_MATCH_NAME,
|
416 |
| - (Supplier<TransportResponse>) CanMatchResponse::new); |
| 393 | + (Supplier<TransportResponse>) SearchService.CanMatchResponse::new); |
417 | 394 | }
|
418 | 395 |
|
419 |
| - public static final class CanMatchResponse extends SearchPhaseResult { |
420 |
| - private boolean canMatch; |
| 396 | + private static class ChannelActionListener<T extends TransportResponse> implements ActionListener<T>{ |
421 | 397 |
|
422 |
| - public CanMatchResponse() { |
423 |
| - } |
| 398 | + private final TransportChannel channel; |
424 | 399 |
|
425 |
| - public CanMatchResponse(boolean canMatch) { |
426 |
| - this.canMatch = canMatch; |
| 400 | + private ChannelActionListener(TransportChannel channel) { |
| 401 | + this.channel = channel; |
427 | 402 | }
|
428 | 403 |
|
429 |
| - |
430 | 404 | @Override
|
431 |
| - public void readFrom(StreamInput in) throws IOException { |
432 |
| - super.readFrom(in); |
433 |
| - canMatch = in.readBoolean(); |
| 405 | + public void onResponse(T result) { |
| 406 | + try { |
| 407 | + channel.sendResponse(result); |
| 408 | + } catch (IOException e) { |
| 409 | + throw new UncheckedIOException(e); |
| 410 | + } |
434 | 411 | }
|
435 | 412 |
|
436 | 413 | @Override
|
437 |
| - public void writeTo(StreamOutput out) throws IOException { |
438 |
| - super.writeTo(out); |
439 |
| - out.writeBoolean(canMatch); |
440 |
| - } |
441 |
| - |
442 |
| - public boolean canMatch() { |
443 |
| - return canMatch; |
| 414 | + public void onFailure(Exception e) { |
| 415 | + try { |
| 416 | + channel.sendResponse(e); |
| 417 | + } catch (IOException e1) { |
| 418 | + throw new UncheckedIOException(e1); |
| 419 | + } |
444 | 420 | }
|
445 | 421 | }
|
446 | 422 |
|
|
0 commit comments