Rename SearchRequest#crossClusterSearch (#42363)
The SearchRequest#crossClusterSearch method is currently used only as part of cross cluster search request, when minimizing roundtrips. It will soon be used also when splitting a search into two: one for throttled and one for non throttled indices. It will probably be used for other usecases as well in the future, hence it makes sense to generalize its name to subSearchRequest.
This commit is contained in:
parent
a75964d8fd
commit
31e8bff2ac
|
@ -135,9 +135,10 @@ public final class SearchRequest extends ActionRequest implements IndicesRequest
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a new search request by providing the search request to copy all fields from, the indices to search against, the alias of
|
||||
* the cluster where it will be executed, as well as the start time in milliseconds from the epoch time and whether the reduction
|
||||
* should be final or not. Used when a {@link SearchRequest} is created and executed as part of a cross-cluster search request
|
||||
* Creates a new sub-search request starting from the original search request that is provided.
|
||||
* For internal use only, allows to fork a search request into multiple search requests that will be executed independently.
|
||||
* Such requests will not be finally reduced, so that their results can be merged together in one response at completion.
|
||||
* Used when a {@link SearchRequest} is created and executed as part of a cross-cluster search request
|
||||
* performing reduction on each cluster in order to minimize network round-trips between the coordinating node and the remote clusters.
|
||||
*
|
||||
* @param originalSearchRequest the original search request
|
||||
|
@ -146,8 +147,8 @@ public final class SearchRequest extends ActionRequest implements IndicesRequest
|
|||
* @param absoluteStartMillis the absolute start time to be used on the remote clusters to ensure that the same value is used
|
||||
* @param finalReduce whether the reduction should be final or not
|
||||
*/
|
||||
static SearchRequest crossClusterSearch(SearchRequest originalSearchRequest, String[] indices,
|
||||
String clusterAlias, long absoluteStartMillis, boolean finalReduce) {
|
||||
static SearchRequest subSearchRequest(SearchRequest originalSearchRequest, String[] indices,
|
||||
String clusterAlias, long absoluteStartMillis, boolean finalReduce) {
|
||||
Objects.requireNonNull(originalSearchRequest, "search request must not be null");
|
||||
validateIndices(indices);
|
||||
Objects.requireNonNull(clusterAlias, "cluster alias must not be null");
|
||||
|
@ -300,7 +301,7 @@ public final class SearchRequest extends ActionRequest implements IndicesRequest
|
|||
/**
|
||||
* Returns the current time in milliseconds from the time epoch, to be used for the execution of this search request. Used to
|
||||
* ensure that the same value, determined by the coordinating node, is used on all nodes involved in the execution of the search
|
||||
* request. When created through {@link #crossClusterSearch(SearchRequest, String[], String, long, boolean)}, this method returns
|
||||
* request. When created through {@link #subSearchRequest(SearchRequest, String[], String, long, boolean)}, this method returns
|
||||
* the provided current time, otherwise it will return {@link System#currentTimeMillis()}.
|
||||
*/
|
||||
long getOrCreateAbsoluteStartMillis() {
|
||||
|
@ -308,7 +309,7 @@ public final class SearchRequest extends ActionRequest implements IndicesRequest
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the provided <code>absoluteStartMillis</code> when created through {@link #crossClusterSearch} and
|
||||
* Returns the provided <code>absoluteStartMillis</code> when created through {@link #subSearchRequest} and
|
||||
* -1 otherwise.
|
||||
*/
|
||||
long getAbsoluteStartMillis() {
|
||||
|
|
|
@ -270,7 +270,7 @@ public class TransportSearchAction extends HandledTransportAction<SearchRequest,
|
|||
String clusterAlias = entry.getKey();
|
||||
boolean skipUnavailable = remoteClusterService.isSkipUnavailable(clusterAlias);
|
||||
OriginalIndices indices = entry.getValue();
|
||||
SearchRequest ccsSearchRequest = SearchRequest.crossClusterSearch(searchRequest, indices.indices(),
|
||||
SearchRequest ccsSearchRequest = SearchRequest.subSearchRequest(searchRequest, indices.indices(),
|
||||
clusterAlias, timeProvider.getAbsoluteStartMillis(), true);
|
||||
Client remoteClusterClient = remoteClusterService.getRemoteClusterClient(threadPool, clusterAlias);
|
||||
remoteClusterClient.search(ccsSearchRequest, new ActionListener<SearchResponse>() {
|
||||
|
@ -306,7 +306,7 @@ public class TransportSearchAction extends HandledTransportAction<SearchRequest,
|
|||
String clusterAlias = entry.getKey();
|
||||
boolean skipUnavailable = remoteClusterService.isSkipUnavailable(clusterAlias);
|
||||
OriginalIndices indices = entry.getValue();
|
||||
SearchRequest ccsSearchRequest = SearchRequest.crossClusterSearch(searchRequest, indices.indices(),
|
||||
SearchRequest ccsSearchRequest = SearchRequest.subSearchRequest(searchRequest, indices.indices(),
|
||||
clusterAlias, timeProvider.getAbsoluteStartMillis(), false);
|
||||
ActionListener<SearchResponse> ccsListener = createCCSListener(clusterAlias, skipUnavailable, countDown,
|
||||
skippedClusters, exceptions, searchResponseMerger, totalClusters, listener);
|
||||
|
@ -316,7 +316,7 @@ public class TransportSearchAction extends HandledTransportAction<SearchRequest,
|
|||
if (localIndices != null) {
|
||||
ActionListener<SearchResponse> ccsListener = createCCSListener(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY,
|
||||
false, countDown, skippedClusters, exceptions, searchResponseMerger, totalClusters, listener);
|
||||
SearchRequest ccsLocalSearchRequest = SearchRequest.crossClusterSearch(searchRequest, localIndices.indices(),
|
||||
SearchRequest ccsLocalSearchRequest = SearchRequest.subSearchRequest(searchRequest, localIndices.indices(),
|
||||
RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY, timeProvider.getAbsoluteStartMillis(), false);
|
||||
localSearchConsumer.accept(ccsLocalSearchRequest, ccsListener);
|
||||
}
|
||||
|
|
|
@ -330,7 +330,7 @@ public class SearchPhaseControllerTests extends ESTestCase {
|
|||
}
|
||||
|
||||
private static SearchRequest randomSearchRequest() {
|
||||
return randomBoolean() ? new SearchRequest() : SearchRequest.crossClusterSearch(new SearchRequest(),
|
||||
return randomBoolean() ? new SearchRequest() : SearchRequest.subSearchRequest(new SearchRequest(),
|
||||
Strings.EMPTY_ARRAY, "remote", 0, randomBoolean());
|
||||
}
|
||||
|
||||
|
|
|
@ -53,21 +53,21 @@ public class SearchRequestTests extends AbstractSearchTestCase {
|
|||
return request;
|
||||
}
|
||||
//clusterAlias and absoluteStartMillis do not have public getters/setters hence we randomize them only in this test specifically.
|
||||
return SearchRequest.crossClusterSearch(request, request.indices(),
|
||||
return SearchRequest.subSearchRequest(request, request.indices(),
|
||||
randomAlphaOfLengthBetween(5, 10), randomNonNegativeLong(), randomBoolean());
|
||||
}
|
||||
|
||||
public void testWithLocalReduction() {
|
||||
expectThrows(NullPointerException.class, () -> SearchRequest.crossClusterSearch(null, Strings.EMPTY_ARRAY, "", 0, randomBoolean()));
|
||||
expectThrows(NullPointerException.class, () -> SearchRequest.subSearchRequest(null, Strings.EMPTY_ARRAY, "", 0, randomBoolean()));
|
||||
SearchRequest request = new SearchRequest();
|
||||
expectThrows(NullPointerException.class, () -> SearchRequest.crossClusterSearch(request, null, "", 0, randomBoolean()));
|
||||
expectThrows(NullPointerException.class, () -> SearchRequest.crossClusterSearch(request,
|
||||
expectThrows(NullPointerException.class, () -> SearchRequest.subSearchRequest(request, null, "", 0, randomBoolean()));
|
||||
expectThrows(NullPointerException.class, () -> SearchRequest.subSearchRequest(request,
|
||||
new String[]{null}, "", 0, randomBoolean()));
|
||||
expectThrows(NullPointerException.class, () -> SearchRequest.crossClusterSearch(request,
|
||||
expectThrows(NullPointerException.class, () -> SearchRequest.subSearchRequest(request,
|
||||
Strings.EMPTY_ARRAY, null, 0, randomBoolean()));
|
||||
expectThrows(IllegalArgumentException.class, () -> SearchRequest.crossClusterSearch(request,
|
||||
expectThrows(IllegalArgumentException.class, () -> SearchRequest.subSearchRequest(request,
|
||||
Strings.EMPTY_ARRAY, "", -1, randomBoolean()));
|
||||
SearchRequest searchRequest = SearchRequest.crossClusterSearch(request, Strings.EMPTY_ARRAY, "", 0, randomBoolean());
|
||||
SearchRequest searchRequest = SearchRequest.subSearchRequest(request, Strings.EMPTY_ARRAY, "", 0, randomBoolean());
|
||||
assertNull(searchRequest.validate());
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public class TransportSearchActionSingleNodeTests extends ESSingleNodeTestCase {
|
|||
assertEquals(RestStatus.CREATED, indexResponse.status());
|
||||
|
||||
{
|
||||
SearchRequest searchRequest = SearchRequest.crossClusterSearch(new SearchRequest(), Strings.EMPTY_ARRAY,
|
||||
SearchRequest searchRequest = SearchRequest.subSearchRequest(new SearchRequest(), Strings.EMPTY_ARRAY,
|
||||
"local", nowInMillis, randomBoolean());
|
||||
SearchResponse searchResponse = client().search(searchRequest).actionGet();
|
||||
assertEquals(1, searchResponse.getHits().getTotalHits().value);
|
||||
|
@ -58,7 +58,7 @@ public class TransportSearchActionSingleNodeTests extends ESSingleNodeTestCase {
|
|||
assertEquals("1", hit.getId());
|
||||
}
|
||||
{
|
||||
SearchRequest searchRequest = SearchRequest.crossClusterSearch(new SearchRequest(), Strings.EMPTY_ARRAY,
|
||||
SearchRequest searchRequest = SearchRequest.subSearchRequest(new SearchRequest(), Strings.EMPTY_ARRAY,
|
||||
"", nowInMillis, randomBoolean());
|
||||
SearchResponse searchResponse = client().search(searchRequest).actionGet();
|
||||
assertEquals(1, searchResponse.getHits().getTotalHits().value);
|
||||
|
@ -100,13 +100,13 @@ public class TransportSearchActionSingleNodeTests extends ESSingleNodeTestCase {
|
|||
assertEquals(0, searchResponse.getTotalShards());
|
||||
}
|
||||
{
|
||||
SearchRequest searchRequest = SearchRequest.crossClusterSearch(new SearchRequest(),
|
||||
SearchRequest searchRequest = SearchRequest.subSearchRequest(new SearchRequest(),
|
||||
Strings.EMPTY_ARRAY, "", 0, randomBoolean());
|
||||
SearchResponse searchResponse = client().search(searchRequest).actionGet();
|
||||
assertEquals(2, searchResponse.getHits().getTotalHits().value);
|
||||
}
|
||||
{
|
||||
SearchRequest searchRequest = SearchRequest.crossClusterSearch(new SearchRequest(),
|
||||
SearchRequest searchRequest = SearchRequest.subSearchRequest(new SearchRequest(),
|
||||
Strings.EMPTY_ARRAY, "", 0, randomBoolean());
|
||||
searchRequest.indices("<test-{now/d}>");
|
||||
SearchResponse searchResponse = client().search(searchRequest).actionGet();
|
||||
|
@ -114,7 +114,7 @@ public class TransportSearchActionSingleNodeTests extends ESSingleNodeTestCase {
|
|||
assertEquals("test-1970.01.01", searchResponse.getHits().getHits()[0].getIndex());
|
||||
}
|
||||
{
|
||||
SearchRequest searchRequest = SearchRequest.crossClusterSearch(new SearchRequest(),
|
||||
SearchRequest searchRequest = SearchRequest.subSearchRequest(new SearchRequest(),
|
||||
Strings.EMPTY_ARRAY, "", 0, randomBoolean());
|
||||
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
|
||||
RangeQueryBuilder rangeQuery = new RangeQueryBuilder("date");
|
||||
|
@ -156,7 +156,7 @@ public class TransportSearchActionSingleNodeTests extends ESSingleNodeTestCase {
|
|||
source.aggregation(terms);
|
||||
|
||||
{
|
||||
SearchRequest searchRequest = randomBoolean() ? originalRequest : SearchRequest.crossClusterSearch(originalRequest,
|
||||
SearchRequest searchRequest = randomBoolean() ? originalRequest : SearchRequest.subSearchRequest(originalRequest,
|
||||
Strings.EMPTY_ARRAY, "remote", nowInMillis, true);
|
||||
SearchResponse searchResponse = client().search(searchRequest).actionGet();
|
||||
assertEquals(2, searchResponse.getHits().getTotalHits().value);
|
||||
|
@ -165,7 +165,7 @@ public class TransportSearchActionSingleNodeTests extends ESSingleNodeTestCase {
|
|||
assertEquals(1, longTerms.getBuckets().size());
|
||||
}
|
||||
{
|
||||
SearchRequest searchRequest = SearchRequest.crossClusterSearch(originalRequest,
|
||||
SearchRequest searchRequest = SearchRequest.subSearchRequest(originalRequest,
|
||||
Strings.EMPTY_ARRAY, "remote", nowInMillis, false);
|
||||
SearchResponse searchResponse = client().search(searchRequest).actionGet();
|
||||
assertEquals(2, searchResponse.getHits().getTotalHits().value);
|
||||
|
|
Loading…
Reference in New Issue