Skip to content

Add minimum compatibility version to SearchRequest #65896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 12, 2021

Conversation

astefan
Copy link
Contributor

@astefan astefan commented Dec 4, 2020

Adds a minimum version request parameter to SearchRequest. The minimum version helps failing a request if any shards involved in the search do not meet the compatibility requirements (all shards need to have a version equal or later than the minimum version provided).

Relates to #63304.

to REST. The minimum version helps failing a request if any shards
involved in the search do not meet the compatibility requirements
(all shards need to have a version equal or later than the minimum
version provided).
@astefan astefan added >feature :Search/Search Search-related issues that do not fall into other categories labels Dec 4, 2020
@elasticmachine elasticmachine added the Team:Search Meta label for search team label Dec 4, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

Copy link
Contributor

@jimczi jimczi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments but the logic looks good to me.

@@ -80,7 +84,11 @@ protected void executePhaseOnShard(final SearchShardIterator shardIt,
final SearchShardTarget shard,
final SearchActionListener<SearchPhaseResult> listener) {
ShardSearchRequest request = rewriteShardSearchRequest(super.buildShardSearchRequest(shardIt));
getSearchTransport().sendExecuteQuery(getConnection(shard.getClusterAlias(), shard.getNodeId()), request, getTask(), listener);
Transport.Connection conn = getConnection(shard.getClusterAlias(), shard.getNodeId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to AbstractSearchAsyncAction#getConnection ? There's nothing that prevents to check the version there.

@@ -80,7 +84,11 @@ protected void executePhaseOnShard(final SearchShardIterator shardIt,
final SearchShardTarget shard,
final SearchActionListener<SearchPhaseResult> listener) {
ShardSearchRequest request = rewriteShardSearchRequest(super.buildShardSearchRequest(shardIt));
getSearchTransport().sendExecuteQuery(getConnection(shard.getClusterAlias(), shard.getNodeId()), request, getTask(), listener);
Transport.Connection conn = getConnection(shard.getClusterAlias(), shard.getNodeId());
if (minVersion != null && conn.getVersion().before(minVersion)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conn can be null too so you'll need to handle this case.

@@ -214,6 +226,9 @@ public SearchRequest(StreamInput in) throws IOException {
finalReduce = true;
}
ccsMinimizeRoundtrips = in.readBoolean();
if (in.getVersion().onOrAfter(Version.V_7_11_0)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to start with 8.0.0 and adapt the checks after the backport

@@ -241,7 +256,9 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(finalReduce);
}
out.writeBoolean(ccsMinimizeRoundtrips);

if (out.getVersion().onOrAfter(Version.V_7_11_0)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@@ -210,6 +210,10 @@ public final void run() {
throw new SearchPhaseExecutionException(getName(), msg, null, ShardSearchFailure.EMPTY_ARRAY);
}
}
if (checkMinimumVersion(shardsIts) == false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to check the minimum version if it's equal to the minimum compatible version (default value).

org.elasticsearch.action.search.VersionMismatchException.class,
org.elasticsearch.action.search.VersionMismatchException::new,
161,
Version.V_7_11_0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now it's just a 8.0.0 exception, you'll need to adapt the version after the backport

@astefan astefan requested a review from jimczi December 8, 2020 08:18
@@ -157,6 +159,16 @@ static SearchRequest subSearchRequest(SearchRequest originalSearchRequest, Strin
return new SearchRequest(originalSearchRequest, indices, clusterAlias, absoluteStartMillis, finalReduce);
}

public static SearchRequest withMinimumVersion(SearchRequest searchRequest, Version minVersion) {
Copy link
Contributor

@jimczi jimczi Dec 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could reuse the subSearchRequest above and just add a nullable minCompatibleShardNode argument ? That makes sense to me because we need to set ccsMinimizeRoundtrips to false there too and these sub search requests are meant for internal use (using the transport client only).
Should we add also a check that the min version is greater or equals than the minimum compatibility version ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also ensure that ccsMinimizeRoundtrips is set to false, otherwise the check will not be applied on the remote cluster. We can force the value here searchRequest.cssMinimizeRountrips(false) but we should also verify the final value in SearchRequest#validate.

@@ -319,6 +336,9 @@ long getAbsoluteStartMillis() {
return absoluteStartMillis;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename to something more explicit: minCompatibleShardNode ?

Copy link
Contributor

@jimczi jimczi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks great. Thanks for adding the mixed cluster tests. I left one comment regarding the ccs_minimize_roundtrips that could be unset automatically.

@@ -97,6 +97,9 @@

private boolean ccsMinimizeRoundtrips = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we switch to a Boolean with a default value of null ? This way we can decide the default value depending on whether the minCompatibleShardNode is set or not ? It feels wrong that you have to explicitly disable this option when using minCompatibleShardNode. It should be done automatically unless the user sets the ccsMinimizeRoundtrips value explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jimczi I've made the change, but slightly different from your suggestion as it wasn't easy to enforce a certain value for ccsMinimizeRoundtrips in all cases. Thus, I've removed the setter and kept as the sole option of setting minCompatibleShardNode for a search request - a constructor (which will also set ccsMinimizeRoundtrips).

Copy link
Contributor

@jimczi jimczi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Thanks @astefan!

@astefan astefan merged commit e3386e1 into elastic:master Jan 12, 2021
astefan added a commit to astefan/elasticsearch that referenced this pull request Jan 13, 2021
* Adds a minimum version request parameter to SearchRequest.
The minimum version helps failing a request if any shards
involved in the search do not meet the compatibility requirements
(all shards need to have a version equal or later than the minimum
version provided).

(cherry picked from commit e3386e1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>feature :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team v7.12.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants