Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;

Expand All @@ -39,12 +38,10 @@ public class RestSearchTemplateAction extends BaseRestHandler {

private final Predicate<NodeFeature> clusterSupportsFeature;
private final Settings settings;
private final boolean inCpsContext;

public RestSearchTemplateAction(Predicate<NodeFeature> clusterSupportsFeature, Settings settings) {
this.clusterSupportsFeature = clusterSupportsFeature;
this.settings = settings;
this.inCpsContext = settings != null && settings.getAsBoolean("serverless.cross_project.enabled", false);
}

@Override
Expand All @@ -64,7 +61,7 @@ public String getName() {

@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
if (inCpsContext) {
if (settings != null && settings.getAsBoolean("serverless.cross_project.enabled", false)) {
// accept but drop project_routing param until fully supported
request.param("project_routing");
}
Expand All @@ -76,9 +73,7 @@ public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client
request,
null,
clusterSupportsFeature,
size -> searchRequest.source().size(size),
// This endpoint is CPS-enabled so propagate the right value.
Optional.of(inCpsContext)
size -> searchRequest.source().size(size)
);

// Creates the search template request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import java.io.IOException;
import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Predicate;

Expand All @@ -53,14 +52,7 @@ protected void parseInternalRequest(
SearchRequest searchRequest = internal.getSearchRequest();

try (XContentParser parser = extractRequestSpecificFields(restRequest, bodyConsumers)) {
RestSearchAction.parseSearchRequest(
searchRequest,
restRequest,
parser,
clusterSupportsFeature,
size -> failOnSizeSpecified(),
Optional.empty()
);
RestSearchAction.parseSearchRequest(searchRequest, restRequest, parser, clusterSupportsFeature, size -> failOnSizeSpecified());
}

searchRequest.source().size(restRequest.paramAsInt("scroll_size", searchRequest.source().size()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.function.IntConsumer;
import java.util.function.Predicate;
Expand All @@ -69,7 +68,6 @@ public class RestSearchAction extends BaseRestHandler {
private final SearchUsageHolder searchUsageHolder;
private final Predicate<NodeFeature> clusterSupportsFeature;
private final Settings settings;
private final boolean inCpsContext;

public RestSearchAction(SearchUsageHolder searchUsageHolder, Predicate<NodeFeature> clusterSupportsFeature) {
this(searchUsageHolder, clusterSupportsFeature, null);
Expand All @@ -79,7 +77,6 @@ public RestSearchAction(SearchUsageHolder searchUsageHolder, Predicate<NodeFeatu
this.searchUsageHolder = searchUsageHolder;
this.clusterSupportsFeature = clusterSupportsFeature;
this.settings = settings;
this.inCpsContext = settings != null && settings.getAsBoolean("serverless.cross_project.enabled", false);
}

@Override
Expand Down Expand Up @@ -112,7 +109,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
// this might be set by old clients
request.param("min_compatible_shard_node");

if (inCpsContext) {
if (settings != null && settings.getAsBoolean("serverless.cross_project.enabled", false)) {
// accept but drop project_routing param until fully supported
request.param("project_routing");
}
Expand All @@ -131,16 +128,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
*/
IntConsumer setSize = size -> searchRequest.source().size(size);
request.withContentOrSourceParamParserOrNull(
parser -> parseSearchRequest(
searchRequest,
request,
parser,
clusterSupportsFeature,
setSize,
searchUsageHolder,
// This endpoint is CPS-enabled so propagate the right value.
Optional.of(inCpsContext)
)
parser -> parseSearchRequest(searchRequest, request, parser, clusterSupportsFeature, setSize, searchUsageHolder)
);

return channel -> {
Expand All @@ -158,23 +146,15 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
* parameter
* @param clusterSupportsFeature used to check if certain features are available in this cluster
* @param setSize how the size url parameter is handled. {@code udpate_by_query} and regular search differ here.
* @param inCpsContext specifies if we're in CPS context.
* <br>
* true - the endpoint that's invoking this method is CPS-enabled and in a CPS/Serverless context.
* <br>
* false - the endpoint that's invoking this method is CPS-enabled but not in a CPS/Serverless context.
* <br>
* Optional.empty - the endpoint is not CPS-enabled irrespective of the environment.
*/
public static void parseSearchRequest(
SearchRequest searchRequest,
RestRequest request,
XContentParser requestContentParser,
Predicate<NodeFeature> clusterSupportsFeature,
IntConsumer setSize,
Optional<Boolean> inCpsContext
IntConsumer setSize
) throws IOException {
parseSearchRequest(searchRequest, request, requestContentParser, clusterSupportsFeature, setSize, null, inCpsContext);
parseSearchRequest(searchRequest, request, requestContentParser, clusterSupportsFeature, setSize, null);
}

/**
Expand All @@ -187,22 +167,14 @@ public static void parseSearchRequest(
* @param clusterSupportsFeature used to check if certain features are available in this cluster
* @param setSize how the size url parameter is handled. {@code udpate_by_query} and regular search differ here.
* @param searchUsageHolder the holder of search usage stats
* @param inCpsContext specifies if we're in CPS context.
* <br>
* true - the endpoint that's invoking this method is CPS-enabled and in a CPS/Serverless context.
* <br>
* false - the endpoint that's invoking this method is CPS-enabled but not in a CPS/Serverless context.
* <br>
* Optional.empty - the endpoint is not CPS-enabled irrespective of the environment.
*/
public static void parseSearchRequest(
SearchRequest searchRequest,
RestRequest request,
@Nullable XContentParser requestContentParser,
Predicate<NodeFeature> clusterSupportsFeature,
IntConsumer setSize,
@Nullable SearchUsageHolder searchUsageHolder,
Optional<Boolean> inCpsContext
@Nullable SearchUsageHolder searchUsageHolder
) throws IOException {
if (searchRequest.source() == null) {
searchRequest.source(new SearchSourceBuilder());
Expand Down Expand Up @@ -257,17 +229,9 @@ public static void parseSearchRequest(
if (searchRequest.pointInTimeBuilder() != null) {
preparePointInTime(searchRequest, request);
} else {
if (inCpsContext.orElse(false)) {
// We're in CPS environment. MRT should not be settable by the user.
if (request.hasParam("ccs_minimize_roundtrips")) {
throw new IllegalArgumentException("Setting ccs_minimize_roundtrips is not supported in cross-project search context");
}
} else {
// Either we're in non-CPS environment or the endpoint isn't CPS enabled, so parse what's in the request.
searchRequest.setCcsMinimizeRoundtrips(
request.paramAsBoolean("ccs_minimize_roundtrips", searchRequest.isCcsMinimizeRoundtrips())
);
}
searchRequest.setCcsMinimizeRoundtrips(
request.paramAsBoolean("ccs_minimize_roundtrips", searchRequest.isCcsMinimizeRoundtrips())
);
}
if (request.paramAsBoolean("force_synthetic_source", false)) {
searchRequest.setForceSyntheticSource(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.IntConsumer;
import java.util.function.Predicate;
Expand All @@ -40,7 +39,6 @@ public final class RestSubmitAsyncSearchAction extends BaseRestHandler {
private final SearchUsageHolder searchUsageHolder;
private final Predicate<NodeFeature> clusterSupportsFeature;
private final Settings settings;
private final boolean inCpsContext;

public RestSubmitAsyncSearchAction(SearchUsageHolder searchUsageHolder, Predicate<NodeFeature> clusterSupportsFeature) {
this(searchUsageHolder, clusterSupportsFeature, null);
Expand All @@ -54,7 +52,6 @@ public RestSubmitAsyncSearchAction(
this.searchUsageHolder = searchUsageHolder;
this.clusterSupportsFeature = clusterSupportsFeature;
this.settings = settings;
this.inCpsContext = settings != null && settings.getAsBoolean("serverless.cross_project.enabled", false);
}

@Override
Expand All @@ -74,10 +71,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
}
SubmitAsyncSearchRequest submit = new SubmitAsyncSearchRequest();

if (inCpsContext) {
if (settings != null && settings.getAsBoolean("serverless.cross_project.enabled", false)) {
// accept but drop project_routing param until fully supported
request.param("project_routing");
submit.getSearchRequest().setCcsMinimizeRoundtrips(true);
}

IntConsumer setSize = size -> submit.getSearchRequest().source().size(size);
Expand All @@ -86,16 +82,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
// them as supported. We rely on SubmitAsyncSearchRequest#validate to fail in case they are set.
// Note that ccs_minimize_roundtrips is also set this way, which is a supported option.
request.withContentOrSourceParamParserOrNull(
parser -> parseSearchRequest(
submit.getSearchRequest(),
request,
parser,
clusterSupportsFeature,
setSize,
searchUsageHolder,
// This endpoint is CPS-enabled so propagate the right value.
Optional.of(inCpsContext)
)
parser -> parseSearchRequest(submit.getSearchRequest(), request, parser, clusterSupportsFeature, setSize, searchUsageHolder)
);

if (request.hasParam("wait_for_completion_timeout")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.IntConsumer;
import java.util.function.Predicate;
Expand Down Expand Up @@ -71,16 +70,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli

IntConsumer setSize = size -> searchRequest.source().size(size);
request.withContentOrSourceParamParserOrNull(parser -> {
RestSearchAction.parseSearchRequest(
searchRequest,
request,
parser,
clusterSupportsFeature,
setSize,
searchUsageHolder,
// This endpoint is not CPS-enabled.
Optional.empty()
);
RestSearchAction.parseSearchRequest(searchRequest, request, parser, clusterSupportsFeature, setSize, searchUsageHolder);
String[] stringWaitForCheckpoints = request.paramAsStringArray("wait_for_checkpoints", Strings.EMPTY_ARRAY);
final long[] waitForCheckpoints = new long[stringWaitForCheckpoints.length];
for (int i = 0; i < stringWaitForCheckpoints.length; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;

Expand Down Expand Up @@ -53,9 +52,7 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
restRequest,
parser,
clusterSupportsFeature,
size -> searchRequest.source().size(size),
// This endpoint is not CPS-enabled.
Optional.empty()
size -> searchRequest.source().size(size)
)
);
RestSearchAction.validateSearchRequest(restRequest, searchRequest);
Expand Down