-
Notifications
You must be signed in to change notification settings - Fork 25.2k
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
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1c41a9c
Adds a minimum version parameter to the SearchRequest, not exposed
astefan 2bcb4aa
Address reviews
astefan df89dcc
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan 5410f26
Adjustment after merge
astefan 137c089
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan c262054
Add min_compatible_shard_node as request parameter
astefan 7c6ab18
Small fixes
astefan e677515
Address reviews
astefan e85c0b5
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan 9a9a919
Differentiate between pre 7.12.0 mixed version cluster tests and post.
astefan b1acef2
Disable bwc tests.
astefan 3ef1cd0
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan d51a352
Re-enable bwc tests
astefan 54365b7
Just to please the bwc checks, since the code is not in 7.x yet,
astefan 6eadbde
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
...luster/src/test/java/org/elasticsearch/backwards/SearchWithMinCompatibleSearchNodeIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.backwards; | ||
|
||
import org.apache.http.HttpHost; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.backwards.IndexingIT.Node; | ||
import org.elasticsearch.backwards.IndexingIT.Nodes; | ||
import org.elasticsearch.client.Request; | ||
import org.elasticsearch.client.Response; | ||
import org.elasticsearch.client.ResponseException; | ||
import org.elasticsearch.client.RestClient; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.common.CheckedRunnable; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.rest.RestStatus; | ||
import org.elasticsearch.test.rest.ESRestTestCase; | ||
import org.elasticsearch.test.rest.yaml.ObjectPath; | ||
import org.junit.Before; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class SearchWithMinCompatibleSearchNodeIT extends ESRestTestCase { | ||
|
||
private static String index = "test_min_version"; | ||
private static int numShards; | ||
private static int numReplicas = 1; | ||
private static int numDocs; | ||
private static Nodes nodes; | ||
private static List<Node> allNodes; | ||
private static Version bwcVersion; | ||
private static Version newVersion; | ||
|
||
@Before | ||
public void prepareTestData() throws IOException { | ||
nodes = IndexingIT.buildNodeAndVersions(client()); | ||
numShards = nodes.size(); | ||
numDocs = randomIntBetween(numShards, 16); | ||
allNodes = new ArrayList<>(); | ||
allNodes.addAll(nodes.getBWCNodes()); | ||
allNodes.addAll(nodes.getNewNodes()); | ||
bwcVersion = nodes.getBWCNodes().get(0).getVersion(); | ||
newVersion = nodes.getNewNodes().get(0).getVersion(); | ||
|
||
if (client().performRequest(new Request("HEAD", "/" + index)).getStatusLine().getStatusCode() == 404) { | ||
createIndex(index, Settings.builder() | ||
.put(IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), numShards) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, numReplicas).build()); | ||
for (int i = 0; i < numDocs; i++) { | ||
Request request = new Request("PUT", index + "/_doc/" + i); | ||
request.setJsonEntity("{\"test\": \"test_" + randomAlphaOfLength(2) + "\"}"); | ||
assertOK(client().performRequest(request)); | ||
} | ||
ensureGreen(index); | ||
} | ||
} | ||
|
||
public void testMinVersionAsNewVersion() throws Exception { | ||
try (RestClient client = buildClient(restClientSettings(), | ||
allNodes.stream().map(Node::getPublishAddress).toArray(HttpHost[]::new))) { | ||
Request newVersionRequest = new Request("POST", | ||
index + "/_search?min_compatible_shard_node=" + newVersion + "&ccs_minimize_roundtrips=false"); | ||
assertBusy(() -> { | ||
ResponseException responseException = expectThrows(ResponseException.class, () -> client.performRequest(newVersionRequest)); | ||
assertThat(responseException.getResponse().getStatusLine().getStatusCode(), | ||
equalTo(RestStatus.INTERNAL_SERVER_ERROR.getStatus())); | ||
assertThat(responseException.getMessage(), | ||
containsString("{\"error\":{\"root_cause\":[],\"type\":\"search_phase_execution_exception\"")); | ||
assertThat(responseException.getMessage(), containsString("caused_by\":{\"type\":\"version_mismatch_exception\"," | ||
+ "\"reason\":\"One of the shards is incompatible with the required minimum version [" + newVersion + "]\"")); | ||
}); | ||
} | ||
} | ||
|
||
public void testMinVersionAsOldVersion() throws Exception { | ||
try (RestClient client = buildClient(restClientSettings(), | ||
allNodes.stream().map(Node::getPublishAddress).toArray(HttpHost[]::new))) { | ||
Request oldVersionRequest = new Request("POST", index + "/_search?min_compatible_shard_node=" + bwcVersion + | ||
"&ccs_minimize_roundtrips=false"); | ||
oldVersionRequest.setJsonEntity("{\"query\":{\"match_all\":{}},\"_source\":false}"); | ||
assertBusy(() -> { | ||
assertWithBwcVersionCheck(() -> { | ||
Response response = client.performRequest(oldVersionRequest); | ||
ObjectPath responseObject = ObjectPath.createFromResponse(response); | ||
Map<String, Object> shardsResult = responseObject.evaluate("_shards"); | ||
assertThat(shardsResult.get("total"), equalTo(numShards)); | ||
assertThat(shardsResult.get("successful"), equalTo(numShards)); | ||
assertThat(shardsResult.get("failed"), equalTo(0)); | ||
Map<String, Object> hitsResult = responseObject.evaluate("hits.total"); | ||
assertThat(hitsResult.get("value"), equalTo(numDocs)); | ||
assertThat(hitsResult.get("relation"), equalTo("eq")); | ||
}, client, oldVersionRequest); | ||
}); | ||
} | ||
} | ||
|
||
public void testCcsMinimizeRoundtripsIsFalse() throws Exception { | ||
try (RestClient client = buildClient(restClientSettings(), | ||
allNodes.stream().map(Node::getPublishAddress).toArray(HttpHost[]::new))) { | ||
Version version = randomBoolean() ? newVersion : bwcVersion; | ||
boolean shouldSetCcsMinimizeRoundtrips = randomBoolean(); | ||
|
||
Request request = new Request("POST", index + "/_search?min_compatible_shard_node=" + version + | ||
(shouldSetCcsMinimizeRoundtrips ? "&ccs_minimize_roundtrips=true" : "")); | ||
assertBusy(() -> { | ||
assertWithBwcVersionCheck(() -> { | ||
ResponseException responseException = expectThrows(ResponseException.class, () -> client.performRequest(request)); | ||
assertThat(responseException.getResponse().getStatusLine().getStatusCode(), | ||
equalTo(RestStatus.BAD_REQUEST.getStatus())); | ||
assertThat(responseException.getMessage(), | ||
containsString("{\"error\":{\"root_cause\":[{\"type\":\"action_request_validation_exception\"")); | ||
assertThat(responseException.getMessage(), containsString("\"reason\":\"Validation Failed: 1: " | ||
+ "[ccs_minimize_roundtrips] cannot be [true] when setting a minimum compatible shard version;\"")); | ||
}, client, request); | ||
}); | ||
} | ||
} | ||
|
||
private void assertWithBwcVersionCheck(CheckedRunnable<Exception> code, RestClient client, Request request) throws Exception { | ||
if (bwcVersion.before(Version.V_8_0_0)) { | ||
// min_compatible_shard_node support doesn't exist in older versions and there will be an "unrecognized parameter" exception | ||
ResponseException exception = expectThrows(ResponseException.class, () -> client.performRequest(request)); | ||
assertThat(exception.getResponse().getStatusLine().getStatusCode(), | ||
equalTo(RestStatus.BAD_REQUEST.getStatus())); | ||
assertThat(exception.getMessage(), containsString("contains unrecognized parameter: [min_compatible_shard_node]")); | ||
} else { | ||
code.run(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
?