|
@@ -52,6 +52,7 @@ import org.elasticsearch.search.SearchHit;
|
|
|
import org.elasticsearch.search.SearchHits;
|
|
|
import org.elasticsearch.search.aggregations.InternalAggregation;
|
|
|
import org.elasticsearch.search.aggregations.InternalAggregations;
|
|
|
+import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.PipelineTree;
|
|
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|
|
import org.elasticsearch.search.collapse.CollapseBuilder;
|
|
|
import org.elasticsearch.search.internal.AliasFilter;
|
|
@@ -89,6 +90,8 @@ import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.function.BiFunction;
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
+import static java.util.Collections.emptyList;
|
|
|
+import static java.util.Collections.emptyMap;
|
|
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.awaitLatch;
|
|
|
import static org.hamcrest.CoreMatchers.containsString;
|
|
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
|
@@ -385,8 +388,8 @@ public class TransportSearchActionTests extends ESTestCase {
|
|
|
AtomicReference<Exception> failure = new AtomicReference<>();
|
|
|
LatchedActionListener<SearchResponse> listener = new LatchedActionListener<>(
|
|
|
ActionListener.wrap(r -> fail("no response expected"), failure::set), latch);
|
|
|
- TransportSearchAction.ccsRemoteReduce(searchRequest, localIndices, remoteIndicesByCluster, timeProvider, reduceContext,
|
|
|
- remoteClusterService, threadPool, listener, (r, l) -> setOnce.set(Tuple.tuple(r, l)));
|
|
|
+ TransportSearchAction.ccsRemoteReduce(searchRequest, localIndices, remoteIndicesByCluster, timeProvider,
|
|
|
+ aggReduceContextBuilder(), remoteClusterService, threadPool, listener, (r, l) -> setOnce.set(Tuple.tuple(r, l)));
|
|
|
if (localIndices == null) {
|
|
|
assertNull(setOnce.get());
|
|
|
} else {
|
|
@@ -419,8 +422,6 @@ public class TransportSearchActionTests extends ESTestCase {
|
|
|
OriginalIndices localIndices = local ? new OriginalIndices(new String[]{"index"}, SearchRequest.DEFAULT_INDICES_OPTIONS) : null;
|
|
|
int totalClusters = numClusters + (local ? 1 : 0);
|
|
|
TransportSearchAction.SearchTimeProvider timeProvider = new TransportSearchAction.SearchTimeProvider(0, 0, () -> 0);
|
|
|
- Function<Boolean, InternalAggregation.ReduceContext> reduceContext =
|
|
|
- finalReduce -> new InternalAggregation.ReduceContext(null, null, finalReduce);
|
|
|
try (MockTransportService service = MockTransportService.createNewService(settings, Version.CURRENT, threadPool, null)) {
|
|
|
service.start();
|
|
|
service.acceptIncomingRequests();
|
|
@@ -432,8 +433,8 @@ public class TransportSearchActionTests extends ESTestCase {
|
|
|
AtomicReference<SearchResponse> response = new AtomicReference<>();
|
|
|
LatchedActionListener<SearchResponse> listener = new LatchedActionListener<>(
|
|
|
ActionListener.wrap(response::set, e -> fail("no failures expected")), latch);
|
|
|
- TransportSearchAction.ccsRemoteReduce(searchRequest, localIndices, remoteIndicesByCluster, timeProvider, reduceContext,
|
|
|
- remoteClusterService, threadPool, listener, (r, l) -> setOnce.set(Tuple.tuple(r, l)));
|
|
|
+ TransportSearchAction.ccsRemoteReduce(searchRequest, localIndices, remoteIndicesByCluster, timeProvider,
|
|
|
+ aggReduceContextBuilder(), remoteClusterService, threadPool, listener, (r, l) -> setOnce.set(Tuple.tuple(r, l)));
|
|
|
if (localIndices == null) {
|
|
|
assertNull(setOnce.get());
|
|
|
} else {
|
|
@@ -458,8 +459,8 @@ public class TransportSearchActionTests extends ESTestCase {
|
|
|
AtomicReference<Exception> failure = new AtomicReference<>();
|
|
|
LatchedActionListener<SearchResponse> listener = new LatchedActionListener<>(
|
|
|
ActionListener.wrap(r -> fail("no response expected"), failure::set), latch);
|
|
|
- TransportSearchAction.ccsRemoteReduce(searchRequest, localIndices, remoteIndicesByCluster, timeProvider, reduceContext,
|
|
|
- remoteClusterService, threadPool, listener, (r, l) -> setOnce.set(Tuple.tuple(r, l)));
|
|
|
+ TransportSearchAction.ccsRemoteReduce(searchRequest, localIndices, remoteIndicesByCluster, timeProvider,
|
|
|
+ aggReduceContextBuilder(), remoteClusterService, threadPool, listener, (r, l) -> setOnce.set(Tuple.tuple(r, l)));
|
|
|
if (localIndices == null) {
|
|
|
assertNull(setOnce.get());
|
|
|
} else {
|
|
@@ -505,8 +506,8 @@ public class TransportSearchActionTests extends ESTestCase {
|
|
|
AtomicReference<Exception> failure = new AtomicReference<>();
|
|
|
LatchedActionListener<SearchResponse> listener = new LatchedActionListener<>(
|
|
|
ActionListener.wrap(r -> fail("no response expected"), failure::set), latch);
|
|
|
- TransportSearchAction.ccsRemoteReduce(searchRequest, localIndices, remoteIndicesByCluster, timeProvider, reduceContext,
|
|
|
- remoteClusterService, threadPool, listener, (r, l) -> setOnce.set(Tuple.tuple(r, l)));
|
|
|
+ TransportSearchAction.ccsRemoteReduce(searchRequest, localIndices, remoteIndicesByCluster, timeProvider,
|
|
|
+ aggReduceContextBuilder(), remoteClusterService, threadPool, listener, (r, l) -> setOnce.set(Tuple.tuple(r, l)));
|
|
|
if (localIndices == null) {
|
|
|
assertNull(setOnce.get());
|
|
|
} else {
|
|
@@ -534,8 +535,8 @@ public class TransportSearchActionTests extends ESTestCase {
|
|
|
AtomicReference<SearchResponse> response = new AtomicReference<>();
|
|
|
LatchedActionListener<SearchResponse> listener = new LatchedActionListener<>(
|
|
|
ActionListener.wrap(response::set, e -> fail("no failures expected")), latch);
|
|
|
- TransportSearchAction.ccsRemoteReduce(searchRequest, localIndices, remoteIndicesByCluster, timeProvider, reduceContext,
|
|
|
- remoteClusterService, threadPool, listener, (r, l) -> setOnce.set(Tuple.tuple(r, l)));
|
|
|
+ TransportSearchAction.ccsRemoteReduce(searchRequest, localIndices, remoteIndicesByCluster, timeProvider,
|
|
|
+ aggReduceContextBuilder(), remoteClusterService, threadPool, listener, (r, l) -> setOnce.set(Tuple.tuple(r, l)));
|
|
|
if (localIndices == null) {
|
|
|
assertNull(setOnce.get());
|
|
|
} else {
|
|
@@ -574,8 +575,8 @@ public class TransportSearchActionTests extends ESTestCase {
|
|
|
AtomicReference<SearchResponse> response = new AtomicReference<>();
|
|
|
LatchedActionListener<SearchResponse> listener = new LatchedActionListener<>(
|
|
|
ActionListener.wrap(response::set, e -> fail("no failures expected")), latch);
|
|
|
- TransportSearchAction.ccsRemoteReduce(searchRequest, localIndices, remoteIndicesByCluster, timeProvider, reduceContext,
|
|
|
- remoteClusterService, threadPool, listener, (r, l) -> setOnce.set(Tuple.tuple(r, l)));
|
|
|
+ TransportSearchAction.ccsRemoteReduce(searchRequest, localIndices, remoteIndicesByCluster, timeProvider,
|
|
|
+ aggReduceContextBuilder(), remoteClusterService, threadPool, listener, (r, l) -> setOnce.set(Tuple.tuple(r, l)));
|
|
|
if (localIndices == null) {
|
|
|
assertNull(setOnce.get());
|
|
|
} else {
|
|
@@ -751,13 +752,12 @@ public class TransportSearchActionTests extends ESTestCase {
|
|
|
|
|
|
public void testCreateSearchResponseMerger() {
|
|
|
TransportSearchAction.SearchTimeProvider timeProvider = new TransportSearchAction.SearchTimeProvider(0, 0, () -> 0);
|
|
|
- Function<Boolean, InternalAggregation.ReduceContext> reduceContext = flag -> null;
|
|
|
{
|
|
|
SearchSourceBuilder source = new SearchSourceBuilder();
|
|
|
assertEquals(-1, source.size());
|
|
|
assertEquals(-1, source.from());
|
|
|
assertNull(source.trackTotalHitsUpTo());
|
|
|
- SearchResponseMerger merger = TransportSearchAction.createSearchResponseMerger(source, timeProvider, reduceContext);
|
|
|
+ SearchResponseMerger merger = TransportSearchAction.createSearchResponseMerger(source, timeProvider, aggReduceContextBuilder());
|
|
|
assertEquals(0, merger.from);
|
|
|
assertEquals(10, merger.size);
|
|
|
assertEquals(SearchContext.DEFAULT_TRACK_TOTAL_HITS_UP_TO, merger.trackTotalHitsUpTo);
|
|
@@ -766,7 +766,7 @@ public class TransportSearchActionTests extends ESTestCase {
|
|
|
assertNull(source.trackTotalHitsUpTo());
|
|
|
}
|
|
|
{
|
|
|
- SearchResponseMerger merger = TransportSearchAction.createSearchResponseMerger(null, timeProvider, reduceContext);
|
|
|
+ SearchResponseMerger merger = TransportSearchAction.createSearchResponseMerger(null, timeProvider, aggReduceContextBuilder());
|
|
|
assertEquals(0, merger.from);
|
|
|
assertEquals(10, merger.size);
|
|
|
assertEquals(SearchContext.DEFAULT_TRACK_TOTAL_HITS_UP_TO, merger.trackTotalHitsUpTo);
|
|
@@ -779,7 +779,7 @@ public class TransportSearchActionTests extends ESTestCase {
|
|
|
source.size(originalSize);
|
|
|
int trackTotalHitsUpTo = randomIntBetween(0, Integer.MAX_VALUE);
|
|
|
source.trackTotalHitsUpTo(trackTotalHitsUpTo);
|
|
|
- SearchResponseMerger merger = TransportSearchAction.createSearchResponseMerger(source, timeProvider, reduceContext);
|
|
|
+ SearchResponseMerger merger = TransportSearchAction.createSearchResponseMerger(source, timeProvider, aggReduceContextBuilder());
|
|
|
assertEquals(0, source.from());
|
|
|
assertEquals(originalFrom + originalSize, source.size());
|
|
|
assertEquals(trackTotalHitsUpTo, (int)source.trackTotalHitsUpTo());
|
|
@@ -837,4 +837,18 @@ public class TransportSearchActionTests extends ESTestCase {
|
|
|
assertFalse(TransportSearchAction.shouldMinimizeRoundtrips(searchRequest));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private InternalAggregation.ReduceContextBuilder aggReduceContextBuilder() {
|
|
|
+ return new InternalAggregation.ReduceContextBuilder() {
|
|
|
+ @Override
|
|
|
+ public InternalAggregation.ReduceContext forPartialReduction() {
|
|
|
+ return InternalAggregation.ReduceContext.forPartialReduction(null, null);
|
|
|
+ };
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public InternalAggregation.ReduceContext forFinalReduction() {
|
|
|
+ return InternalAggregation.ReduceContext.forFinalReduction(null, null, b -> {}, new PipelineTree(emptyMap(), emptyList()));
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
}
|