Skip to content

Commit

Permalink
[Remove] LegacyESVersion.V_7_4_* and V_7_5_* constants (opensearch-pr…
Browse files Browse the repository at this point in the history
…oject#4704)

Removes all usages of LegacyESVersion.V_7_4_ and LegacyESVersion.V_7_5
version constants along with ancient API logic.

Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
  • Loading branch information
nknize authored and ashking94 committed Nov 7, 2022
1 parent 226c34c commit def7dba
Show file tree
Hide file tree
Showing 38 changed files with 64 additions and 712 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Remove LegacyESVersion.V_7_0_* and V_7_1_* Constants ([#2768](https://https://github.com/opensearch-project/OpenSearch/pull/2768))
- Remove LegacyESVersion.V_7_2_ and V_7_3_ Constants ([#4702](https://github.com/opensearch-project/OpenSearch/pull/4702))
- Always auto release the flood stage block ([#4703](https://github.com/opensearch-project/OpenSearch/pull/4703))
- Remove LegacyESVersion.V_7_4_ and V_7_5_ Constants ([#4704](https://github.com/opensearch-project/OpenSearch/pull/4704))

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,7 @@ public void testAutoIdWithOpTypeCreate() throws IOException {
}
}

if (minNodeVersion.before(LegacyESVersion.V_7_5_0)) {
ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(bulk));
assertEquals(400, e.getResponse().getStatusLine().getStatusCode());
assertThat(e.getMessage(),
// if request goes to 7.5+ node
either(containsString("optype create not supported for indexing requests without explicit id until"))
// if request goes to < 7.5 node
.or(containsString("an id must be provided if version type or value are set")
));
} else {
client().performRequest(bulk);
}
client().performRequest(bulk);
break;
case UPGRADED:
client().performRequest(bulk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

import org.opensearch.Version;
import org.opensearch.action.ActionFuture;
import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest;
import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
import org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse;
import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
Expand All @@ -47,7 +46,6 @@
import org.opensearch.action.admin.indices.stats.ShardStats;
import org.opensearch.action.index.IndexRequestBuilder;
import org.opensearch.action.support.ActiveShardCount;
import org.opensearch.action.support.PlainActionFuture;
import org.opensearch.action.support.master.AcknowledgedResponse;
import org.opensearch.client.Client;
import org.opensearch.client.node.NodeClient;
Expand Down Expand Up @@ -1386,44 +1384,6 @@ public void testPartialSnapshotAllShardsMissing() throws Exception {
assertThat(createSnapshotResponse.getSnapshotInfo().state(), is(SnapshotState.PARTIAL));
}

/**
* Tests for the legacy snapshot path that is normally executed if the cluster contains any nodes older than
* {@link SnapshotsService#NO_REPO_INITIALIZE_VERSION}.
* Makes sure that blocking as well as non-blocking snapshot create paths execute cleanly as well as that error handling works out
* correctly by testing a snapshot name collision.
*/
public void testCreateSnapshotLegacyPath() throws Exception {
final String clusterManagerNode = internalCluster().startClusterManagerOnlyNode();
internalCluster().startDataOnlyNode();
final String repoName = "test-repo";
createRepository(repoName, "fs");
createIndex("some-index");

final SnapshotsService snapshotsService = internalCluster().getClusterManagerNodeInstance(SnapshotsService.class);
final Snapshot snapshot1 = PlainActionFuture.get(
f -> snapshotsService.createSnapshotLegacy(new CreateSnapshotRequest(repoName, "snap-1"), f)
);
awaitNoMoreRunningOperations(clusterManagerNode);

final InvalidSnapshotNameException sne = expectThrows(
InvalidSnapshotNameException.class,
() -> PlainActionFuture.<SnapshotInfo, Exception>get(
f -> snapshotsService.executeSnapshotLegacy(new CreateSnapshotRequest(repoName, snapshot1.getSnapshotId().getName()), f)
)
);

assertThat(sne.getMessage(), containsString("snapshot with the same name already exists"));
final SnapshotInfo snapshot2 = PlainActionFuture.get(
f -> snapshotsService.executeSnapshotLegacy(new CreateSnapshotRequest(repoName, "snap-2"), f)
);
assertThat(snapshot2.state(), is(SnapshotState.SUCCESS));

final SnapshotInfo snapshot3 = PlainActionFuture.get(
f -> snapshotsService.executeSnapshotLegacy(new CreateSnapshotRequest(repoName, "snap-3").indices("does-not-exist-*"), f)
);
assertThat(snapshot3.state(), is(SnapshotState.SUCCESS));
}

public void testSnapshotDeleteRelocatingPrimaryIndex() throws Exception {
internalCluster().startClusterManagerOnlyNode();
final List<String> dataNodes = internalCluster().startDataOnlyNodes(2);
Expand Down
6 changes: 0 additions & 6 deletions server/src/main/java/org/opensearch/LegacyESVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@
*/
public class LegacyESVersion extends Version {

public static final LegacyESVersion V_7_4_0 = new LegacyESVersion(7040099, org.apache.lucene.util.Version.LUCENE_8_2_0);
public static final LegacyESVersion V_7_4_1 = new LegacyESVersion(7040199, org.apache.lucene.util.Version.LUCENE_8_2_0);
public static final LegacyESVersion V_7_4_2 = new LegacyESVersion(7040299, org.apache.lucene.util.Version.LUCENE_8_2_0);
public static final LegacyESVersion V_7_5_0 = new LegacyESVersion(7050099, org.apache.lucene.util.Version.LUCENE_8_3_0);
public static final LegacyESVersion V_7_5_1 = new LegacyESVersion(7050199, org.apache.lucene.util.Version.LUCENE_8_3_0);
public static final LegacyESVersion V_7_5_2 = new LegacyESVersion(7050299, org.apache.lucene.util.Version.LUCENE_8_3_0);
public static final LegacyESVersion V_7_6_0 = new LegacyESVersion(7060099, org.apache.lucene.util.Version.LUCENE_8_4_0);
public static final LegacyESVersion V_7_6_1 = new LegacyESVersion(7060199, org.apache.lucene.util.Version.LUCENE_8_4_0);
public static final LegacyESVersion V_7_6_2 = new LegacyESVersion(7060299, org.apache.lucene.util.Version.LUCENE_8_4_0);
Expand Down
9 changes: 2 additions & 7 deletions server/src/main/java/org/opensearch/OpenSearchException.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.opensearch.index.Index;
import org.opensearch.index.shard.ShardId;
import org.opensearch.rest.RestStatus;
import org.opensearch.search.SearchException;
import org.opensearch.search.aggregations.MultiBucketConsumerService;
import org.opensearch.transport.TcpTransport;

Expand Down Expand Up @@ -317,10 +316,6 @@ public void writeTo(StreamOutput out) throws IOException {
public static OpenSearchException readException(StreamInput input, int id) throws IOException {
CheckedFunction<StreamInput, ? extends OpenSearchException, IOException> opensearchException = ID_TO_SUPPLIER.get(id);
if (opensearchException == null) {
if (id == 127 && input.getVersion().before(LegacyESVersion.V_7_5_0)) {
// was SearchContextException
return new SearchException(input);
}
throw new IllegalStateException("unknown exception for id: " + id);
}
return opensearchException.apply(input);
Expand Down Expand Up @@ -1569,13 +1564,13 @@ private enum OpenSearchExceptionHandle {
org.opensearch.index.seqno.RetentionLeaseInvalidRetainingSeqNoException.class,
org.opensearch.index.seqno.RetentionLeaseInvalidRetainingSeqNoException::new,
156,
LegacyESVersion.V_7_5_0
UNKNOWN_VERSION_ADDED
),
INGEST_PROCESSOR_EXCEPTION(
org.opensearch.ingest.IngestProcessorException.class,
org.opensearch.ingest.IngestProcessorException::new,
157,
LegacyESVersion.V_7_5_0
UNKNOWN_VERSION_ADDED
),
PEER_RECOVERY_NOT_FOUND_EXCEPTION(
org.opensearch.indices.recovery.PeerRecoveryNotFound.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,14 @@ boolean hasPassword() {
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
if (out.getVersion().onOrAfter(LegacyESVersion.V_7_4_0)) {
if (this.secureSettingsPassword == null) {
out.writeOptionalBytesReference(null);
} else {
final byte[] passwordBytes = CharArrays.toUtf8Bytes(this.secureSettingsPassword.getChars());
try {
out.writeOptionalBytesReference(new BytesArray(passwordBytes));
} finally {
Arrays.fill(passwordBytes, (byte) 0);
}
if (this.secureSettingsPassword == null) {
out.writeOptionalBytesReference(null);
} else {
final byte[] passwordBytes = CharArrays.toUtf8Bytes(this.secureSettingsPassword.getChars());
try {
out.writeOptionalBytesReference(new BytesArray(passwordBytes));
} finally {
Arrays.fill(passwordBytes, (byte) 0);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.opensearch.LegacyESVersion;
import org.opensearch.Version;
import org.opensearch.action.ActionListener;
import org.opensearch.action.ActionRunnable;
import org.opensearch.action.StepListener;
Expand Down Expand Up @@ -91,8 +89,6 @@ public final class TransportCleanupRepositoryAction extends TransportClusterMana

private static final Logger logger = LogManager.getLogger(TransportCleanupRepositoryAction.class);

private static final Version MIN_VERSION = LegacyESVersion.V_7_4_0;

private final RepositoriesService repositoriesService;

private final SnapshotsService snapshotsService;
Expand Down Expand Up @@ -179,17 +175,7 @@ protected void clusterManagerOperation(
ClusterState state,
ActionListener<CleanupRepositoryResponse> listener
) {
if (state.nodes().getMinNodeVersion().onOrAfter(MIN_VERSION)) {
cleanupRepo(request.name(), ActionListener.map(listener, CleanupRepositoryResponse::new));
} else {
throw new IllegalArgumentException(
"Repository cleanup is only supported from version ["
+ MIN_VERSION
+ "] but the oldest node version in the cluster is ["
+ state.nodes().getMinNodeVersion()
+ ']'
);
}
cleanupRepo(request.name(), ActionListener.map(listener, CleanupRepositoryResponse::new));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,10 @@ protected void clusterManagerOperation(
ClusterState state,
final ActionListener<CreateSnapshotResponse> listener
) {
if (state.nodes().getMinNodeVersion().before(SnapshotsService.NO_REPO_INITIALIZE_VERSION)) {
if (request.waitForCompletion()) {
snapshotsService.executeSnapshotLegacy(request, ActionListener.map(listener, CreateSnapshotResponse::new));
} else {
snapshotsService.createSnapshotLegacy(request, ActionListener.map(listener, snapshot -> new CreateSnapshotResponse()));
}
if (request.waitForCompletion()) {
snapshotsService.executeSnapshot(request, ActionListener.map(listener, CreateSnapshotResponse::new));
} else {
if (request.waitForCompletion()) {
snapshotsService.executeSnapshot(request, ActionListener.map(listener, CreateSnapshotResponse::new));
} else {
snapshotsService.createSnapshot(request, ActionListener.map(listener, snapshot -> new CreateSnapshotResponse()));
}
snapshotsService.createSnapshot(request, ActionListener.map(listener, snapshot -> new CreateSnapshotResponse()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

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

import org.opensearch.LegacyESVersion;
import org.opensearch.cluster.SnapshotsInProgress;
import org.opensearch.cluster.SnapshotsInProgress.State;
import org.opensearch.common.Nullable;
Expand Down Expand Up @@ -92,15 +91,8 @@ public class SnapshotStatus implements ToXContentObject, Writeable {
state = State.fromValue(in.readByte());
shards = Collections.unmodifiableList(in.readList(SnapshotIndexShardStatus::new));
includeGlobalState = in.readOptionalBoolean();
final long startTime;
final long time;
if (in.getVersion().onOrAfter(LegacyESVersion.V_7_4_0)) {
startTime = in.readLong();
time = in.readLong();
} else {
startTime = 0L;
time = 0L;
}
final long startTime = in.readLong();
final long time = in.readLong();
updateShardStats(startTime, time);
}

Expand Down Expand Up @@ -207,10 +199,8 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeByte(state.value());
out.writeList(shards);
out.writeOptionalBoolean(includeGlobalState);
if (out.getVersion().onOrAfter(LegacyESVersion.V_7_4_0)) {
out.writeLong(stats.getStartTime());
out.writeLong(stats.getTime());
}
out.writeLong(stats.getStartTime());
out.writeLong(stats.getTime());
}

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

import com.carrotsearch.hppc.cursors.IntObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.opensearch.LegacyESVersion;
import org.opensearch.OpenSearchException;
import org.opensearch.action.ActionResponse;
import org.opensearch.action.support.DefaultShardOperationFailedException;
Expand Down Expand Up @@ -247,13 +246,8 @@ public Failure(String nodeId, String index, int shardId, Throwable reason) {
}

private Failure(StreamInput in) throws IOException {
if (in.getVersion().before(LegacyESVersion.V_7_4_0)) {
nodeId = in.readString();
}
readFrom(in, this);
if (in.getVersion().onOrAfter(LegacyESVersion.V_7_4_0)) {
nodeId = in.readString();
}
nodeId = in.readString();
}

public String nodeId() {
Expand All @@ -266,13 +260,8 @@ static Failure readFailure(StreamInput in) throws IOException {

@Override
public void writeTo(StreamOutput out) throws IOException {
if (out.getVersion().before(LegacyESVersion.V_7_4_0)) {
out.writeString(nodeId);
}
super.writeTo(out);
if (out.getVersion().onOrAfter(LegacyESVersion.V_7_4_0)) {
out.writeString(nodeId);
}
out.writeString(nodeId);
}

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

package org.opensearch.action.admin.indices.shrink;

import org.opensearch.LegacyESVersion;
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.action.IndicesRequest;
import org.opensearch.action.admin.indices.alias.Alias;
Expand Down Expand Up @@ -122,9 +121,6 @@ public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
targetIndexRequest.writeTo(out);
out.writeString(sourceIndex);
if (type == ResizeType.CLONE && out.getVersion().before(LegacyESVersion.V_7_4_0)) {
throw new IllegalArgumentException("can't send clone request to a node that's older than " + LegacyESVersion.V_7_4_0);
}
out.writeEnum(type);
out.writeOptionalBoolean(copySettings);
}
Expand Down
18 changes: 5 additions & 13 deletions server/src/main/java/org/opensearch/action/index/IndexRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,8 @@ public IndexRequest(@Nullable ShardId shardId, StreamInput in) throws IOExceptio
version = in.readLong();
versionType = VersionType.fromValue(in.readByte());
pipeline = in.readOptionalString();
if (in.getVersion().onOrAfter(LegacyESVersion.V_7_5_0)) {
finalPipeline = in.readOptionalString();
}
if (in.getVersion().onOrAfter(LegacyESVersion.V_7_5_0)) {
isPipelineResolved = in.readBoolean();
}
finalPipeline = in.readOptionalString();
isPipelineResolved = in.readBoolean();
isRetry = in.readBoolean();
autoGeneratedTimestamp = in.readLong();
if (in.readBoolean()) {
Expand Down Expand Up @@ -639,7 +635,7 @@ public void resolveRouting(Metadata metadata) {
}

public void checkAutoIdWithOpTypeCreateSupportedByVersion(Version version) {
if (id == null && opType == OpType.CREATE && version.before(LegacyESVersion.V_7_5_0)) {
if (id == null && opType == OpType.CREATE && version.before(LegacyESVersion.fromId(7050099))) {
throw new IllegalArgumentException(
"optype create not supported for indexing requests without explicit id until all nodes " + "are on version 7.5.0 or higher"
);
Expand Down Expand Up @@ -671,12 +667,8 @@ private void writeBody(StreamOutput out) throws IOException {
out.writeLong(version);
out.writeByte(versionType.getValue());
out.writeOptionalString(pipeline);
if (out.getVersion().onOrAfter(LegacyESVersion.V_7_5_0)) {
out.writeOptionalString(finalPipeline);
}
if (out.getVersion().onOrAfter(LegacyESVersion.V_7_5_0)) {
out.writeBoolean(isPipelineResolved);
}
out.writeOptionalString(finalPipeline);
out.writeBoolean(isPipelineResolved);
out.writeBoolean(isRetry);
out.writeLong(autoGeneratedTimestamp);
if (contentType != null) {
Expand Down
Loading

0 comments on commit def7dba

Please sign in to comment.