Skip to content

Commit 49b1e44

Browse files
committed
Compatibility issue with /_mget: RHLC 2.x connected to OpenSearch Cluster 1.x (opensearch-project#4812)
Signed-off-by: Andriy Redko <andriy.redko@aiven.io> Signed-off-by: Andriy Redko <andriy.redko@aiven.io> (cherry picked from commit d85f8cd) Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
1 parent fe122d6 commit 49b1e44

5 files changed

Lines changed: 71 additions & 0 deletions

File tree

.ci/bwcVersions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ BWC_VERSION:
4343
- "1.3.4"
4444
- "1.3.5"
4545
- "1.3.6"
46+
- "1.3.7"
4647
- "2.0.0"
4748
- "2.0.1"
4849
- "2.0.2"

qa/mixed-cluster/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ apply plugin: 'opensearch.standalone-test'
3838
apply from : "$rootDir/gradle/bwc-test.gradle"
3939
apply plugin: 'opensearch.rest-resources'
4040

41+
dependencies {
42+
testImplementation project(":client:rest-high-level")
43+
}
44+
4145
restResources {
4246
restTests {
4347
includeCore '*'
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.backwards;
10+
11+
import org.apache.http.HttpHost;
12+
import org.opensearch.action.get.MultiGetRequest;
13+
import org.opensearch.action.get.MultiGetResponse;
14+
import org.opensearch.client.Request;
15+
import org.opensearch.client.RequestOptions;
16+
import org.opensearch.client.Response;
17+
import org.opensearch.client.RestClient;
18+
import org.opensearch.client.RestHighLevelClient;
19+
import org.opensearch.test.rest.OpenSearchRestTestCase;
20+
import org.opensearch.test.rest.yaml.ObjectPath;
21+
22+
import java.io.IOException;
23+
import java.net.URISyntaxException;
24+
import java.util.HashSet;
25+
import java.util.Map;
26+
import java.util.Set;
27+
28+
import static org.hamcrest.Matchers.containsString;
29+
30+
public class SearchingIT extends OpenSearchRestTestCase {
31+
public void testMultiGet() throws Exception {
32+
final Set<HttpHost> nodes = buildNodes();
33+
34+
final MultiGetRequest multiGetRequest = new MultiGetRequest();
35+
multiGetRequest.add("index", "id1");
36+
37+
try (RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(nodes.toArray(HttpHost[]::new)))) {
38+
MultiGetResponse response = client.mget(multiGetRequest, RequestOptions.DEFAULT);
39+
assertEquals(1, response.getResponses().length);
40+
41+
assertTrue(response.getResponses()[0].isFailed());
42+
assertNotNull(response.getResponses()[0].getFailure());
43+
assertEquals(response.getResponses()[0].getFailure().getId(), "id1");
44+
assertEquals(response.getResponses()[0].getFailure().getIndex(), "index");
45+
assertThat(response.getResponses()[0].getFailure().getMessage(), containsString("no such index [index]"));
46+
}
47+
}
48+
49+
private Set<HttpHost> buildNodes() throws IOException, URISyntaxException {
50+
Response response = client().performRequest(new Request("GET", "_nodes"));
51+
ObjectPath objectPath = ObjectPath.createFromResponse(response);
52+
Map<String, Object> nodesAsMap = objectPath.evaluate("nodes");
53+
final Set<HttpHost> nodes = new HashSet<>();
54+
for (String id : nodesAsMap.keySet()) {
55+
nodes.add(HttpHost.create((String) objectPath.evaluate("nodes." + id + ".http.publish_address")));
56+
}
57+
58+
return nodes;
59+
}
60+
}

server/src/main/java/org/opensearch/Version.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public class Version implements Comparable<Version>, ToXContentFragment {
9090
public static final Version V_1_3_4 = new Version(1030499, org.apache.lucene.util.Version.LUCENE_8_10_1);
9191
public static final Version V_1_3_5 = new Version(1030599, org.apache.lucene.util.Version.LUCENE_8_10_1);
9292
public static final Version V_1_3_6 = new Version(1030699, org.apache.lucene.util.Version.LUCENE_8_10_1);
93+
public static final Version V_1_3_7 = new Version(1030799, org.apache.lucene.util.Version.LUCENE_8_10_1);
9394
public static final Version V_2_0_0 = new Version(2000099, org.apache.lucene.util.Version.LUCENE_9_1_0);
9495
public static final Version V_2_0_1 = new Version(2000199, org.apache.lucene.util.Version.LUCENE_9_1_0);
9596
public static final Version V_2_0_2 = new Version(2000299, org.apache.lucene.util.Version.LUCENE_9_1_0);

server/src/main/java/org/opensearch/action/get/MultiGetResponse.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public class MultiGetResponse extends ActionResponse implements Iterable<MultiGe
6363
private static final ParseField ID = new ParseField("_id");
6464
private static final ParseField ERROR = new ParseField("error");
6565
private static final ParseField DOCS = new ParseField("docs");
66+
// In mixed clusters, the 1.x cluster could still return the '_type' in the response payload, it has to
67+
// be handled gracefully
68+
@Deprecated(forRemoval = true)
69+
private static final ParseField TYPE = new ParseField("_type");
6670

6771
/**
6872
* Represents a failure.
@@ -212,6 +216,7 @@ private static MultiGetItemResponse parseItem(XContentParser parser) throws IOEx
212216
currentFieldName = parser.currentName();
213217
if (INDEX.match(currentFieldName, parser.getDeprecationHandler()) == false
214218
&& ID.match(currentFieldName, parser.getDeprecationHandler()) == false
219+
&& TYPE.match(currentFieldName, parser.getDeprecationHandler()) == false
215220
&& ERROR.match(currentFieldName, parser.getDeprecationHandler()) == false) {
216221
getResult = GetResult.fromXContentEmbedded(parser, index, id);
217222
}

0 commit comments

Comments
 (0)