Skip to content

Commit

Permalink
[Remove] LegacyESVersion.V_7_10_* constants
Browse files Browse the repository at this point in the history
Removes all usages of LegacyESVersion.V_7_10_ version constants along with
ancient API logic.

Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
  • Loading branch information
nknize committed Nov 1, 2022
1 parent fab4336 commit 4b5e1c8
Show file tree
Hide file tree
Showing 41 changed files with 95 additions and 455 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void accept(final Tuple<TaskInput, Terminal> input) {
// check if the elasticsearch version is supported
if (taskInput.getVersion().isPresent()) {
final Version version = taskInput.getVersion().get();
if (version.equals(LegacyESVersion.V_7_10_2) == false) {
if (version.equals(LegacyESVersion.fromId(7100299)) == false) {
throw new RuntimeException(
String.format(Locale.getDefault(), "The installed version %s of elasticsearch is not supported.", version)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void setTask() {

public void testUnsupportedEsVersion() {
TaskInput taskInput = new TaskInput(env);
taskInput.setVersion(LegacyESVersion.V_7_10_1);
taskInput.setVersion(LegacyESVersion.fromId(7100199));

final RuntimeException e = expectThrows(RuntimeException.class, () -> task.accept(new Tuple<>(taskInput, terminal)));

Expand All @@ -51,7 +51,7 @@ public void testGetSummaryFields() {
taskInput.setEsConfig(PathUtils.get("es_home"));
taskInput.setCluster("some-cluster");
taskInput.setNode("some-node");
taskInput.setVersion(LegacyESVersion.V_7_10_2);
taskInput.setVersion(LegacyESVersion.fromId(7100299));
taskInput.setBaseUrl("some-url");
taskInput.setPlugins(Arrays.asList("plugin-1", "plugin-2"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

package org.opensearch.ingest.common;

import org.opensearch.LegacyESVersion;
import org.opensearch.action.ActionListener;
import org.opensearch.action.ActionRequest;
import org.opensearch.action.ActionRequestValidationException;
Expand Down Expand Up @@ -79,7 +78,7 @@ public Request(boolean sorted) {

Request(StreamInput in) throws IOException {
super(in);
this.sorted = in.getVersion().onOrAfter(LegacyESVersion.V_7_10_0) ? in.readBoolean() : false;
this.sorted = in.readBoolean();
}

@Override
Expand All @@ -90,9 +89,7 @@ public ActionRequestValidationException validate() {
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
if (out.getVersion().onOrAfter(LegacyESVersion.V_7_10_0)) {
out.writeBoolean(sorted);
}
out.writeBoolean(sorted);
}

public boolean sorted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

package org.opensearch.upgrades;

import org.opensearch.LegacyESVersion;
import org.opensearch.Version;
import org.opensearch.client.Request;
import org.opensearch.client.Response;
Expand Down Expand Up @@ -72,7 +71,6 @@
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.opensearch.cluster.metadata.IndexNameExpressionResolver.SYSTEM_INDEX_ENFORCEMENT_VERSION;
import static org.opensearch.cluster.routing.UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING;
import static org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider.SETTING_ALLOCATION_MAX_RETRY;
import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder;
Expand Down Expand Up @@ -1441,20 +1439,6 @@ public void testSystemIndexMetadataIsUpgraded() throws Exception {
throw new AssertionError(".tasks index does not exist yet");
}
});

// If we are on 7.x create an alias that includes both a system index and a non-system index so we can be sure it gets
// upgraded properly. If we're already on 8.x, skip this part of the test.
if (minimumNodeVersion().before(SYSTEM_INDEX_ENFORCEMENT_VERSION)) {
// Create an alias to make sure it gets upgraded properly
Request putAliasRequest = new Request("POST", "/_aliases");
putAliasRequest.setJsonEntity("{\n" +
" \"actions\": [\n" +
" {\"add\": {\"index\": \".tasks\", \"alias\": \"test-system-alias\"}},\n" +
" {\"add\": {\"index\": \"test_index_reindex\", \"alias\": \"test-system-alias\"}}\n" +
" ]\n" +
"}");
assertThat(client().performRequest(putAliasRequest).getStatusLine().getStatusCode(), is(200));
}
} else {
assertBusy(() -> {
Request clusterStateRequest = new Request("GET", "/_cluster/state/metadata");
Expand All @@ -1469,21 +1453,8 @@ public void testSystemIndexMetadataIsUpgraded() throws Exception {
XContentTestUtils.JsonMapView tasksIndex = new XContentTestUtils.JsonMapView((Map<String, Object>) indices.get(".tasks"));
assertThat(tasksIndex.get("system"), is(true));

// If .tasks was created in a 7.x version, it should have an alias on it that we need to make sure got upgraded properly.
final String tasksCreatedVersionString = tasksIndex.get("settings.index.version.created");
assertThat(tasksCreatedVersionString, notNullValue());
final Version tasksCreatedVersion = Version.fromId(Integer.parseInt(tasksCreatedVersionString));
if (tasksCreatedVersion.before(SYSTEM_INDEX_ENFORCEMENT_VERSION)) {
// Verify that the alias survived the upgrade
Request getAliasRequest = new Request("GET", "/_alias/test-system-alias");
getAliasRequest.setOptions(expectVersionSpecificWarnings(v -> {
v.current(systemIndexWarning);
v.compatible(systemIndexWarning);
}));
Map<String, Object> aliasResponse = entityAsMap(client().performRequest(getAliasRequest));
assertThat(aliasResponse, hasKey(".tasks"));
assertThat(aliasResponse, hasKey("test_index_reindex"));
}
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

import java.util.Map;

import static org.opensearch.cluster.metadata.IndexNameExpressionResolver.SYSTEM_INDEX_ENFORCEMENT_VERSION;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
Expand Down Expand Up @@ -97,20 +96,6 @@ public void testSystemIndicesUpgrades() throws Exception {
throw new AssertionError(".tasks index does not exist yet");
}
});

// If we are on 7.x create an alias that includes both a system index and a non-system index so we can be sure it gets
// upgraded properly. If we're already on 8.x, skip this part of the test.
if (minimumNodeVersion().before(SYSTEM_INDEX_ENFORCEMENT_VERSION)) {
// Create an alias to make sure it gets upgraded properly
Request putAliasRequest = new Request("POST", "/_aliases");
putAliasRequest.setJsonEntity("{\n" +
" \"actions\": [\n" +
" {\"add\": {\"index\": \".tasks\", \"alias\": \"test-system-alias\"}},\n" +
" {\"add\": {\"index\": \"test_index_reindex\", \"alias\": \"test-system-alias\"}}\n" +
" ]\n" +
"}");
assertThat(client().performRequest(putAliasRequest).getStatusLine().getStatusCode(), is(200));
}
} else if (CLUSTER_TYPE == ClusterType.UPGRADED) {
assertBusy(() -> {
Request clusterStateRequest = new Request("GET", "/_cluster/state/metadata");
Expand All @@ -125,21 +110,8 @@ public void testSystemIndicesUpgrades() throws Exception {
JsonMapView tasksIndex = new JsonMapView((Map<String, Object>) indices.get(".tasks"));
assertThat(tasksIndex.get("system"), is(true));

// If .tasks was created in a 7.x version, it should have an alias on it that we need to make sure got upgraded properly.
final String tasksCreatedVersionString = tasksIndex.get("settings.index.version.created");
assertThat(tasksCreatedVersionString, notNullValue());
final Version tasksCreatedVersion = Version.fromId(Integer.parseInt(tasksCreatedVersionString));
if (tasksCreatedVersion.before(SYSTEM_INDEX_ENFORCEMENT_VERSION)) {
// Verify that the alias survived the upgrade
Request getAliasRequest = new Request("GET", "/_alias/test-system-alias");
getAliasRequest.setOptions(expectVersionSpecificWarnings(v -> {
v.current(systemIndexWarning);
v.compatible(systemIndexWarning);
}));
Map<String, Object> aliasResponse = entityAsMap(client().performRequest(getAliasRequest));
assertThat(aliasResponse, hasKey(".tasks"));
assertThat(aliasResponse, hasKey("test_index_reindex"));
}
});
}
}
Expand Down
4 changes: 0 additions & 4 deletions server/src/main/java/org/opensearch/LegacyESVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
*/
public class LegacyESVersion extends Version {

public static final LegacyESVersion V_7_10_0 = new LegacyESVersion(7100099, org.apache.lucene.util.Version.LUCENE_8_7_0);
public static final LegacyESVersion V_7_10_1 = new LegacyESVersion(7100199, org.apache.lucene.util.Version.LUCENE_8_7_0);
public static final LegacyESVersion V_7_10_2 = new LegacyESVersion(7100299, org.apache.lucene.util.Version.LUCENE_8_7_0);

// todo move back to Version.java if retiring legacy version support
protected static final ImmutableOpenIntMap<Version> idToVersion;
protected static final ImmutableOpenMap<String, Version> stringToVersion;
Expand Down
16 changes: 3 additions & 13 deletions server/src/main/java/org/opensearch/OpenSearchException.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public class OpenSearchException extends RuntimeException implements ToXContentF
private static final Map<Class<? extends OpenSearchException>, OpenSearchExceptionHandle> CLASS_TO_OPENSEARCH_EXCEPTION_HANDLE;

private static final Pattern OS_METADATA = Pattern.compile("^opensearch\\.");
private static final Pattern ES_METADATA = Pattern.compile("^es\\.");

private final Map<String, List<String>> metadata = new HashMap<>();
private final Map<String, List<String>> headers = new HashMap<>();
Expand Down Expand Up @@ -158,16 +157,7 @@ public OpenSearchException(StreamInput in) throws IOException {
super(in.readOptionalString(), in.readException());
readStackTrace(this, in);
headers.putAll(in.readMapOfLists(StreamInput::readString, StreamInput::readString));
metadata.putAll(in.readMapOfLists(OpenSearchException::readAndReplace, StreamInput::readString));
}

private static String readAndReplace(StreamInput in) throws IOException {
String str = in.readString();
return in.getVersion().onOrBefore(LegacyESVersion.V_7_10_2) ? ES_METADATA.matcher(str).replaceFirst("opensearch.") : str;
}

private static void replaceAndWrite(StreamOutput out, String str) throws IOException {
out.writeString(out.getVersion().onOrBefore(LegacyESVersion.V_7_10_2) ? OS_METADATA.matcher(str).replaceFirst("es.") : str);
metadata.putAll(in.readMapOfLists(StreamInput::readString, StreamInput::readString));
}

/**
Expand Down Expand Up @@ -310,7 +300,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeException(this.getCause());
writeStackTraces(this, out, StreamOutput::writeException);
out.writeMapOfLists(headers, StreamOutput::writeString, StreamOutput::writeString);
out.writeMapOfLists(metadata, OpenSearchException::replaceAndWrite, StreamOutput::writeString);
out.writeMapOfLists(metadata, StreamOutput::writeString, StreamOutput::writeString);
}

public static OpenSearchException readException(StreamInput input, int id) throws IOException {
Expand Down Expand Up @@ -1588,7 +1578,7 @@ private enum OpenSearchExceptionHandle {
org.opensearch.transport.NoSeedNodeLeftException.class,
org.opensearch.transport.NoSeedNodeLeftException::new,
160,
LegacyESVersion.V_7_10_0
UNKNOWN_VERSION_ADDED
),
REPLICATION_FAILED_EXCEPTION(
org.opensearch.indices.replication.common.ReplicationFailedException.class,
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/org/opensearch/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ protected Version computeMinCompatVersion() {
// we don't have LegacyESVersion.V_6 constants, so set it to its last minor
return LegacyESVersion.fromId(6080099);
} else if (major == 2) {
return LegacyESVersion.V_7_10_0;
return LegacyESVersion.fromId(7100099);
} else if (major == 6) {
// force the minimum compatibility for version 6 to 5.6 since we don't reference version 5 anymore
return LegacyESVersion.fromId(5060099);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
package org.opensearch.action.admin.cluster.node.info;

import org.opensearch.Build;
import org.opensearch.LegacyESVersion;
import org.opensearch.Version;
import org.opensearch.action.support.nodes.BaseNodeResponse;
import org.opensearch.cluster.node.DiscoveryNode;
Expand Down Expand Up @@ -99,9 +98,7 @@ public NodeInfo(StreamInput in) throws IOException {
addInfoIfNonNull(HttpInfo.class, in.readOptionalWriteable(HttpInfo::new));
addInfoIfNonNull(PluginsAndModules.class, in.readOptionalWriteable(PluginsAndModules::new));
addInfoIfNonNull(IngestInfo.class, in.readOptionalWriteable(IngestInfo::new));
if (in.getVersion().onOrAfter(LegacyESVersion.V_7_10_0)) {
addInfoIfNonNull(AggregationInfo.class, in.readOptionalWriteable(AggregationInfo::new));
}
addInfoIfNonNull(AggregationInfo.class, in.readOptionalWriteable(AggregationInfo::new));
}

public NodeInfo(
Expand Down Expand Up @@ -198,11 +195,7 @@ private <T extends ReportingService.Info> void addInfoIfNonNull(Class<T> clazz,
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
if (out.getVersion().before(Version.V_1_0_0)) {
out.writeVInt(LegacyESVersion.V_7_10_2.id);
} else {
out.writeVInt(version.id);
}
out.writeVInt(version.id);
Build.writeBuild(build, out);
if (totalIndexingBuffer == null) {
out.writeBoolean(false);
Expand All @@ -224,8 +217,6 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalWriteable(getInfo(HttpInfo.class));
out.writeOptionalWriteable(getInfo(PluginsAndModules.class));
out.writeOptionalWriteable(getInfo(IngestInfo.class));
if (out.getVersion().onOrAfter(LegacyESVersion.V_7_10_0)) {
out.writeOptionalWriteable(getInfo(AggregationInfo.class));
}
out.writeOptionalWriteable(getInfo(AggregationInfo.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

package org.opensearch.action.admin.cluster.snapshots.restore;

import org.opensearch.LegacyESVersion;
import org.opensearch.Version;
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.action.support.IndicesOptions;
Expand Down Expand Up @@ -146,9 +145,7 @@ public RestoreSnapshotRequest(StreamInput in) throws IOException {
includeAliases = in.readBoolean();
indexSettings = readSettingsFromStream(in);
ignoreIndexSettings = in.readStringArray();
if (in.getVersion().onOrAfter(LegacyESVersion.V_7_10_0)) {
snapshotUuid = in.readOptionalString();
}
snapshotUuid = in.readOptionalString();
if (FeatureFlags.isEnabled(FeatureFlags.SEARCHABLE_SNAPSHOT) && in.getVersion().onOrAfter(Version.V_2_4_0)) {
storageType = in.readEnum(StorageType.class);
}
Expand All @@ -169,13 +166,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(includeAliases);
writeSettingsToStream(indexSettings, out);
out.writeStringArray(ignoreIndexSettings);
if (out.getVersion().onOrAfter(LegacyESVersion.V_7_10_0)) {
out.writeOptionalString(snapshotUuid);
} else if (snapshotUuid != null) {
throw new IllegalStateException(
"restricting the snapshot UUID is forbidden in a cluster with version [" + out.getVersion() + "] nodes"
);
}
out.writeOptionalString(snapshotUuid);
if (FeatureFlags.isEnabled(FeatureFlags.SEARCHABLE_SNAPSHOT) && out.getVersion().onOrAfter(Version.V_2_4_0)) {
out.writeEnum(storageType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,7 @@ public IndexRequest(@Nullable ShardId shardId, StreamInput in) throws IOExceptio
}
ifSeqNo = in.readZLong();
ifPrimaryTerm = in.readVLong();
if (in.getVersion().onOrAfter(LegacyESVersion.V_7_10_0)) {
requireAlias = in.readBoolean();
} else {
requireAlias = false;
}
requireAlias = in.readBoolean();
}

public IndexRequest() {
Expand Down Expand Up @@ -679,9 +675,7 @@ private void writeBody(StreamOutput out) throws IOException {
}
out.writeZLong(ifSeqNo);
out.writeVLong(ifPrimaryTerm);
if (out.getVersion().onOrAfter(LegacyESVersion.V_7_10_0)) {
out.writeBoolean(requireAlias);
}
out.writeBoolean(requireAlias);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

package org.opensearch.action.ingest;

import org.opensearch.LegacyESVersion;
import org.opensearch.OpenSearchException;
import org.opensearch.common.ParseField;
import org.opensearch.common.collect.Tuple;
Expand Down Expand Up @@ -193,18 +192,12 @@ public SimulateProcessorResult(String type, String processorTag, String descript
this.ingestDocument = in.readOptionalWriteable(WriteableIngestDocument::new);
this.failure = in.readException();
this.description = in.readOptionalString();

if (in.getVersion().onOrAfter(LegacyESVersion.V_7_10_0)) {
this.type = in.readString();
boolean hasConditional = in.readBoolean();
if (hasConditional) {
this.conditionalWithResult = new Tuple<>(in.readString(), in.readBoolean());
} else {
this.conditionalWithResult = null; // no condition exists
}
this.type = in.readString();
boolean hasConditional = in.readBoolean();
if (hasConditional) {
this.conditionalWithResult = new Tuple<>(in.readString(), in.readBoolean());
} else {
this.conditionalWithResult = null;
this.type = null;
this.conditionalWithResult = null; // no condition exists
}
}

Expand All @@ -214,14 +207,11 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalWriteable(ingestDocument);
out.writeException(failure);
out.writeOptionalString(description);

if (out.getVersion().onOrAfter(LegacyESVersion.V_7_10_0)) {
out.writeString(type);
out.writeBoolean(conditionalWithResult != null);
if (conditionalWithResult != null) {
out.writeString(conditionalWithResult.v1());
out.writeBoolean(conditionalWithResult.v2());
}
out.writeString(type);
out.writeBoolean(conditionalWithResult != null);
if (conditionalWithResult != null) {
out.writeString(conditionalWithResult.v1());
out.writeBoolean(conditionalWithResult.v2());
}
}

Expand Down
Loading

0 comments on commit 4b5e1c8

Please sign in to comment.