Skip to content

Commit

Permalink
Revert "Enable HLRC compatibility mode by default (#86517)" (#86873)
Browse files Browse the repository at this point in the history
This reverts commit 0cb5108.
  • Loading branch information
sethmlarson authored May 17, 2022
1 parent 4276aad commit 7987866
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,7 @@ protected RestHighLevelClient(
.flatMap(Function.identity())
.collect(toList())
);

// Compatibility mode is on by default, then env variable has precedence over builder setting
String apiVersioningEnv = System.getenv(API_VERSIONING_ENV_VARIABLE);
if (useAPICompatibility == null && apiVersioningEnv == null) {
this.useAPICompatibility = true;
} else if (useAPICompatibility == null && "true".equals(System.getenv(API_VERSIONING_ENV_VARIABLE))) {
if (useAPICompatibility == null && "true".equals(System.getenv(API_VERSIONING_ENV_VARIABLE))) {
this.useAPICompatibility = true;
} else {
this.useAPICompatibility = Boolean.TRUE.equals(useAPICompatibility);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ private Void mockPerformRequestAsync(Request request, ResponseListener responseL
* Mocks the synchronous request execution like if it was executed by Elasticsearch.
*/
private Response mockPerformRequest(Request request) throws IOException {
// Headers contain 'node_name' set by optionsForNodeName and 'Accept' from HLRC compatibility mode
assertThat(request.getOptions().getHeaders(), hasSize(2));
assertThat(request.getOptions().getHeaders(), hasSize(1));
Header httpHeader = request.getOptions().getHeaders().get(0);
final Response mockResponse = mock(Response.class);
when(mockResponse.getHost()).thenReturn(new HttpHost("localhost", 9200));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.ClearScrollRequest;
import org.elasticsearch.action.search.ClearScrollResponse;
import org.elasticsearch.action.search.SearchResponse;
Expand Down Expand Up @@ -97,7 +95,6 @@
import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.core.CheckedFunction;
import org.elasticsearch.core.Tuple;
import org.elasticsearch.index.get.GetResult;
import org.elasticsearch.index.rankeval.DiscountedCumulativeGain;
import org.elasticsearch.index.rankeval.EvaluationMetric;
import org.elasticsearch.index.rankeval.ExpectedReciprocalRank;
Expand Down Expand Up @@ -1504,30 +1501,6 @@ public void testModifyForCompatibility() {

}

public void testCompatibilityModeDefault() throws Exception {
mockResponse(new GetResponse(new GetResult("foo", "bar", "1", 1, 1, 1, true, null, null, null)));
restHighLevelClient.get(new GetRequest("foo", "bar"), RequestOptions.DEFAULT);

verify(restClient).performRequest(argThat(req -> {
List<Header> headers = req.getOptions().getHeaders();
Header accept = headers.stream().filter(h -> h.getName().equals("Accept")).findFirst().get();
return accept.getValue().equals("application/vnd.elasticsearch+json; compatible-with=7");
}));
}

public void testDisableCompatibilityMode() throws Exception {
RestHighLevelClient client = new RestHighLevelClientBuilder(restClient).setApiCompatibilityMode(false).build();

mockResponse(new GetResponse(new GetResult("foo", "bar", "1", 1, 1, 1, true, null, null, null)));
client.get(new GetRequest("foo", "bar"), RequestOptions.DEFAULT);

verify(restClient).performRequest(argThat(req -> {
List<Header> headers = req.getOptions().getHeaders();
Optional<Header> accept = headers.stream().filter(h -> h.getName().equals("Accept")).findFirst();
return accept.isPresent() == false;
}));
}

private static void assertSyncMethod(Method method, String apiName, List<String> booleanReturnMethods) {
// A few methods return a boolean rather than a response object
if (apiName.equals("ping") || apiName.contains("exist") || booleanReturnMethods.contains(apiName)) {
Expand Down
18 changes: 0 additions & 18 deletions docs/changelog/86517.yaml

This file was deleted.

49 changes: 16 additions & 33 deletions docs/java-rest/high-level/getting-started.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ doesn't need to be in the same minor version as the Elasticsearch nodes it
communicates with, as it is forward compatible meaning that it supports
communicating with later versions of Elasticsearch than the one it was developed for.

The 7.0 client is able to communicate with any 7.x Elasticsearch node, while the 7.1
client is for sure able to communicate with 7.1, 7.2 and any later 7.x version, but
The 6.0 client is able to communicate with any 6.x Elasticsearch node, while the 6.1
client is for sure able to communicate with 6.1, 6.2 and any later 6.x version, but
there may be incompatibility issues when communicating with a previous Elasticsearch
node version, for instance between 7.1 and 7.0, in case the 7.1 client supports new
request body fields for some APIs that are not known by the 7.0 node(s).
node version, for instance between 6.1 and 6.0, in case the 6.1 client supports new
request body fields for some APIs that are not known by the 6.0 node(s).

It is recommended to upgrade the High Level Client when upgrading the Elasticsearch
cluster to a new major version, as REST API breaking changes may cause unexpected
Expand All @@ -31,23 +31,6 @@ only be supported by the newer version of the client. The client should always b
updated last, once all of the nodes in the cluster have been upgraded to the new
major version.

*Compatibility with Elasticsearch 8.x*

The High Level Client version 7.16 and higher can communicate with Elasticsearch version 8.x after enabling API compatibility mode. When this mode enabled, the client will send HTTP headers that instruct Elasticsearch 8.x to honor 7.x request/responses.

Compatibility mode is enabled as follows:

["source","java",subs="attributes"]
--------------------------------------------------
RestHighLevelClient esClient = new RestHighLevelClientBuilder(restClient)
.setApiCompatibilityMode(true)
.build()
--------------------------------------------------

When compatibility mode is enabled, the client can also communicate with Elasticsearch version 7.11 and higher.

NOTE: Starting with version 7.17.4, compatibility mode is enabled by default.

[[java-rest-high-javadoc]]
=== Javadoc

Expand Down Expand Up @@ -158,7 +141,7 @@ transitive dependencies:
[[java-rest-high-getting-started-initialization]]
=== Initialization

A `RestHighLevelClient` instance needs a
A `RestHighLevelClient` instance needs a
{java-api-client}/java-rest-low-usage-initialization.html[REST low-level client builder]
to be built as follows:

Expand Down Expand Up @@ -189,27 +172,27 @@ All APIs in the `RestHighLevelClient` accept a `RequestOptions` which you can
use to customize the request in ways that won't change how Elasticsearch
executes the request. For example, this is the place where you'd specify a
`NodeSelector` to control which node receives the request. See the
{java-api-client}/java-rest-low-usage-requests.html#java-rest-low-usage-request-options[low level client documentation]
{java-api-client}/java-rest-low-usage-requests.html#java-rest-low-usage-request-options[low level client documentation]
for more examples of customizing the options.

[[java-rest-high-getting-started-asynchronous-usage]]
=== Asynchronous usage

All of the methods across the different clients exist in a traditional synchronous and
asynchronous variant. The difference is that the asynchronous ones use asynchronous requests
All of the methods across the different clients exist in a traditional synchronous and
asynchronous variant. The difference is that the asynchronous ones use asynchronous requests
in the REST Low Level Client. This is useful if you are doing multiple requests or are using e.g.
rx java, Kotlin co-routines, or similar frameworks.

The asynchronous methods are recognizable by the fact that they have the word "Async" in their name
and return a `Cancellable` instance. The asynchronous methods accept the same request object
as the synchronous variant and accept a generic `ActionListener<T>` where `T` is the return
type of the synchronous method.
The asynchronous methods are recognizable by the fact that they have the word "Async" in their name
and return a `Cancellable` instance. The asynchronous methods accept the same request object
as the synchronous variant and accept a generic `ActionListener<T>` where `T` is the return
type of the synchronous method.

All asynchronous methods return a `Cancellable` object with a `cancel` method that you may call
All asynchronous methods return a `Cancellable` object with a `cancel` method that you may call
in case you want to abort the request. Cancelling
no longer needed requests is a good way to avoid putting unnecessary
no longer needed requests is a good way to avoid putting unnecessary
load on Elasticsearch.

Using the `Cancellable` instance is optional and you can safely ignore this if you have
no need for this. A use case for this would be using this with e.g. Kotlin's `suspendCancellableCoRoutine`.
Using the `Cancellable` instance is optional and you can safely ignore this if you have
no need for this. A use case for this would be using this with e.g. Kotlin's `suspendCancellableCoRoutine`.

2 changes: 0 additions & 2 deletions docs/java-rest/high-level/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

deprecated[7.15.0, The High Level REST Client is deprecated in favour of the {java-api-client}/index.html[Java API Client].]

NOTE: The High Level Rest Client version 7.17 can work with {es} `8.x` with <<java-rest-high-compatibility,compatibility mode enabled>>.

The Java High Level REST Client works on top of the Java Low Level REST client.
Its main goal is to expose API specific methods, that accept request objects as
an argument and return response objects, so that request marshalling and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.RestHighLevelClientBuilder;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.document.DocumentField;
Expand Down Expand Up @@ -90,13 +89,11 @@ static RestHighLevelClient newLocalClient(Logger logger) {
final List<HttpHost> hosts = parseHosts("tests.rest.cluster");
final int index = random().nextInt(hosts.size());
logger.info("Using client node {}", index);
return new RestHighLevelClientBuilder(RestClient.builder(hosts.get(index)).build()).setApiCompatibilityMode(false).build();
return new RestHighLevelClient(RestClient.builder(hosts.get(index)));
}

static RestHighLevelClient newRemoteClient() {
return new RestHighLevelClientBuilder(RestClient.builder(randomFrom(parseHosts("tests.rest.remote_cluster"))).build())
.setApiCompatibilityMode(false)
.build();
return new RestHighLevelClient(RestClient.builder(randomFrom(parseHosts("tests.rest.remote_cluster"))));
}

public void testFieldsOptionEmulation() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.RestHighLevelClientBuilder;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.settings.Settings;
Expand Down Expand Up @@ -73,13 +72,11 @@ protected static RestHighLevelClient newLocalClient(Logger logger) {
final List<HttpHost> hosts = parseHosts("tests.rest.cluster");
final int index = random().nextInt(hosts.size());
logger.info("Using client node {}", index);
return new RestHighLevelClientBuilder(RestClient.builder(hosts.get(index)).build()).setApiCompatibilityMode(false).build();
return new RestHighLevelClient(RestClient.builder(hosts.get(index)));
}

protected static RestHighLevelClient newRemoteClient() {
return new RestHighLevelClientBuilder(RestClient.builder(randomFrom(parseHosts("tests.rest.remote_cluster"))).build())
.setApiCompatibilityMode(false)
.build();
return new RestHighLevelClient(RestClient.builder(randomFrom(parseHosts("tests.rest.remote_cluster"))));
}

static int indexDocs(RestHighLevelClient client, String index, int numDocs) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.RestHighLevelClientBuilder;
import org.elasticsearch.client.ml.CloseJobRequest;
import org.elasticsearch.client.ml.CloseJobResponse;
import org.elasticsearch.client.ml.FlushJobRequest;
Expand Down Expand Up @@ -70,8 +69,10 @@ public class MlJobSnapshotUpgradeIT extends AbstractUpgradeTestCase {
// min version in upgraded 7.series is 7.11.0
private static final Version CPP_COMPATIBILTIY_VERSION = Version.V_7_11_0;

private static RestHighLevelClient HLRC(RestClient restClient) {
return new RestHighLevelClientBuilder(restClient).setApiCompatibilityMode(false).build();
private static class HLRC extends RestHighLevelClient {
HLRC(RestClient restClient) {
super(restClient, RestClient::close, new ArrayList<>());
}
}

private MachineLearningClient hlrc;
Expand All @@ -97,7 +98,7 @@ protected static void waitForPendingUpgraderTasks() throws Exception {
* index mappings when it is assigned to an upgraded node even if no other ML endpoint is called after the upgrade
*/
public void testSnapshotUpgrader() throws Exception {
hlrc = HLRC(client()).machineLearning();
hlrc = new HLRC(client()).machineLearning();
Request adjustLoggingLevels = new Request("PUT", "/_cluster/settings");
adjustLoggingLevels.setJsonEntity("{\"persistent\": {" + "\"logger.org.elasticsearch.xpack.ml\": \"trace\"" + "}}");
client().performRequest(adjustLoggingLevels);
Expand Down

0 comments on commit 7987866

Please sign in to comment.