Rename SearchRequest#withLocalReduction (#39108)
`withLocalReduction` is confusing as `local` effectively means "local to the remote clusters" rather than "local the coordinating node" where the method is executed. I propose we rename the method to `crossClusterSearch` which better resembles what the static method is used for.
This commit is contained in:
parent
2f7206ada7
commit
2619f48e4d
|
@ -142,19 +142,19 @@ public final class SearchRequest extends ActionRequest implements IndicesRequest
|
|||
*
|
||||
* @param originalSearchRequest the original search request
|
||||
* @param indices the indices to search against
|
||||
* @param localClusterAlias the alias to prefix index names with in the returned search results
|
||||
* @param clusterAlias the alias to prefix index names with in the returned search results
|
||||
* @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 withLocalReduction(SearchRequest originalSearchRequest, String[] indices,
|
||||
String localClusterAlias, long absoluteStartMillis, boolean finalReduce) {
|
||||
static SearchRequest crossClusterSearch(SearchRequest originalSearchRequest, String[] indices,
|
||||
String clusterAlias, long absoluteStartMillis, boolean finalReduce) {
|
||||
Objects.requireNonNull(originalSearchRequest, "search request must not be null");
|
||||
validateIndices(indices);
|
||||
Objects.requireNonNull(localClusterAlias, "cluster alias must not be null");
|
||||
Objects.requireNonNull(clusterAlias, "cluster alias must not be null");
|
||||
if (absoluteStartMillis < 0) {
|
||||
throw new IllegalArgumentException("absoluteStartMillis must not be negative but was [" + absoluteStartMillis + "]");
|
||||
}
|
||||
return new SearchRequest(originalSearchRequest, indices, localClusterAlias, absoluteStartMillis, finalReduce);
|
||||
return new SearchRequest(originalSearchRequest, indices, clusterAlias, absoluteStartMillis, finalReduce);
|
||||
}
|
||||
|
||||
private SearchRequest(SearchRequest searchRequest, String[] indices, String localClusterAlias, long absoluteStartMillis,
|
||||
|
@ -300,7 +300,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 #withLocalReduction(SearchRequest, String[], String, long, boolean)}, this method returns
|
||||
* request. When created through {@link #crossClusterSearch(SearchRequest, String[], String, long, boolean)}, this method returns
|
||||
* the provided current time, otherwise it will return {@link System#currentTimeMillis()}.
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -265,7 +265,7 @@ public class TransportSearchAction extends HandledTransportAction<SearchRequest,
|
|||
String clusterAlias = entry.getKey();
|
||||
boolean skipUnavailable = remoteClusterService.isSkipUnavailable(clusterAlias);
|
||||
OriginalIndices indices = entry.getValue();
|
||||
SearchRequest ccsSearchRequest = SearchRequest.withLocalReduction(searchRequest, indices.indices(),
|
||||
SearchRequest ccsSearchRequest = SearchRequest.crossClusterSearch(searchRequest, indices.indices(),
|
||||
clusterAlias, timeProvider.getAbsoluteStartMillis(), true);
|
||||
Client remoteClusterClient = remoteClusterService.getRemoteClusterClient(threadPool, clusterAlias);
|
||||
remoteClusterClient.search(ccsSearchRequest, new ActionListener<SearchResponse>() {
|
||||
|
@ -301,7 +301,7 @@ public class TransportSearchAction extends HandledTransportAction<SearchRequest,
|
|||
String clusterAlias = entry.getKey();
|
||||
boolean skipUnavailable = remoteClusterService.isSkipUnavailable(clusterAlias);
|
||||
OriginalIndices indices = entry.getValue();
|
||||
SearchRequest ccsSearchRequest = SearchRequest.withLocalReduction(searchRequest, indices.indices(),
|
||||
SearchRequest ccsSearchRequest = SearchRequest.crossClusterSearch(searchRequest, indices.indices(),
|
||||
clusterAlias, timeProvider.getAbsoluteStartMillis(), false);
|
||||
ActionListener<SearchResponse> ccsListener = createCCSListener(clusterAlias, skipUnavailable, countDown,
|
||||
skippedClusters, exceptions, searchResponseMerger, totalClusters, listener);
|
||||
|
@ -313,7 +313,7 @@ public class TransportSearchAction extends HandledTransportAction<SearchRequest,
|
|||
false, countDown, skippedClusters, exceptions, searchResponseMerger, totalClusters, listener);
|
||||
//here we provide the empty string a cluster alias, which means no prefix in index name,
|
||||
//but the coord node will perform non final reduce as it's not null.
|
||||
SearchRequest ccsLocalSearchRequest = SearchRequest.withLocalReduction(searchRequest, localIndices.indices(),
|
||||
SearchRequest ccsLocalSearchRequest = SearchRequest.crossClusterSearch(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.withLocalReduction(new SearchRequest(),
|
||||
return randomBoolean() ? new SearchRequest() : SearchRequest.crossClusterSearch(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.withLocalReduction(request, request.indices(),
|
||||
return SearchRequest.crossClusterSearch(request, request.indices(),
|
||||
randomAlphaOfLengthBetween(5, 10), randomNonNegativeLong(), randomBoolean());
|
||||
}
|
||||
|
||||
public void testWithLocalReduction() {
|
||||
expectThrows(NullPointerException.class, () -> SearchRequest.withLocalReduction(null, Strings.EMPTY_ARRAY, "", 0, randomBoolean()));
|
||||
expectThrows(NullPointerException.class, () -> SearchRequest.crossClusterSearch(null, Strings.EMPTY_ARRAY, "", 0, randomBoolean()));
|
||||
SearchRequest request = new SearchRequest();
|
||||
expectThrows(NullPointerException.class, () -> SearchRequest.withLocalReduction(request, null, "", 0, randomBoolean()));
|
||||
expectThrows(NullPointerException.class, () -> SearchRequest.withLocalReduction(request,
|
||||
expectThrows(NullPointerException.class, () -> SearchRequest.crossClusterSearch(request, null, "", 0, randomBoolean()));
|
||||
expectThrows(NullPointerException.class, () -> SearchRequest.crossClusterSearch(request,
|
||||
new String[]{null}, "", 0, randomBoolean()));
|
||||
expectThrows(NullPointerException.class, () -> SearchRequest.withLocalReduction(request,
|
||||
expectThrows(NullPointerException.class, () -> SearchRequest.crossClusterSearch(request,
|
||||
Strings.EMPTY_ARRAY, null, 0, randomBoolean()));
|
||||
expectThrows(IllegalArgumentException.class, () -> SearchRequest.withLocalReduction(request,
|
||||
expectThrows(IllegalArgumentException.class, () -> SearchRequest.crossClusterSearch(request,
|
||||
Strings.EMPTY_ARRAY, "", -1, randomBoolean()));
|
||||
SearchRequest searchRequest = SearchRequest.withLocalReduction(request, Strings.EMPTY_ARRAY, "", 0, randomBoolean());
|
||||
SearchRequest searchRequest = SearchRequest.crossClusterSearch(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.withLocalReduction(new SearchRequest(), Strings.EMPTY_ARRAY,
|
||||
SearchRequest searchRequest = SearchRequest.crossClusterSearch(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.withLocalReduction(new SearchRequest(), Strings.EMPTY_ARRAY,
|
||||
SearchRequest searchRequest = SearchRequest.crossClusterSearch(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.withLocalReduction(new SearchRequest(),
|
||||
SearchRequest searchRequest = SearchRequest.crossClusterSearch(new SearchRequest(),
|
||||
Strings.EMPTY_ARRAY, "", 0, randomBoolean());
|
||||
SearchResponse searchResponse = client().search(searchRequest).actionGet();
|
||||
assertEquals(2, searchResponse.getHits().getTotalHits().value);
|
||||
}
|
||||
{
|
||||
SearchRequest searchRequest = SearchRequest.withLocalReduction(new SearchRequest(),
|
||||
SearchRequest searchRequest = SearchRequest.crossClusterSearch(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.withLocalReduction(new SearchRequest(),
|
||||
SearchRequest searchRequest = SearchRequest.crossClusterSearch(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.withLocalReduction(originalRequest,
|
||||
SearchRequest searchRequest = randomBoolean() ? originalRequest : SearchRequest.crossClusterSearch(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.withLocalReduction(originalRequest,
|
||||
SearchRequest searchRequest = SearchRequest.crossClusterSearch(originalRequest,
|
||||
Strings.EMPTY_ARRAY, "remote", nowInMillis, false);
|
||||
SearchResponse searchResponse = client().search(searchRequest).actionGet();
|
||||
assertEquals(2, searchResponse.getHits().getTotalHits().value);
|
||||
|
|
Loading…
Reference in New Issue