From 8b076b81eed926f6b6a6167a1fc9399e091eb7c4 Mon Sep 17 00:00:00 2001 From: Rabi Panda Date: Thu, 23 Dec 2021 16:54:37 -0800 Subject: [PATCH] Remove LegacyVersion.v6.4.x constants (#1787) This commit removes the `LegacyVersion.v6.4.x` constants and their usages, since we no longer need to support those in OpenSearch 2.0 onwards. Signed-off-by: Rabi Panda --- .../action/PainlessExecuteAction.java | 20 ++---- .../upgrades/FullClusterRestartIT.java | 2 +- .../java/org/opensearch/LegacyESVersion.java | 4 -- .../reroute/ClusterRerouteResponse.java | 25 ++----- .../ClusterUpdateSettingsResponse.java | 25 ++----- .../snapshots/status/SnapshotStats.java | 16 ++--- .../GetStoredScriptResponse.java | 9 +-- .../action/admin/indices/alias/Alias.java | 10 +-- .../indices/alias/IndicesAliasesRequest.java | 8 +-- .../indices/alias/get/GetAliasesRequest.java | 9 +-- .../indices/close/CloseIndexResponse.java | 2 +- .../indices/create/CreateIndexResponse.java | 2 +- .../admin/indices/get/GetIndexRequest.java | 9 +-- .../admin/indices/open/OpenIndexResponse.java | 2 +- .../readonly/AddIndexBlockResponse.java | 2 +- .../indices/rollover/RolloverResponse.java | 69 ++++++------------- .../settings/get/GetSettingsRequest.java | 9 +-- .../admin/indices/shrink/ResizeRequest.java | 13 +--- .../validate/query/QueryExplanation.java | 13 +--- .../resync/ResyncReplicationRequest.java | 11 +-- .../master/ShardsAcknowledgedResponse.java | 4 +- .../cluster/metadata/AliasMetadata.java | 10 +-- .../cluster/metadata/IndexMetadata.java | 20 ++---- .../query/AbstractGeometryQueryBuilder.java | 13 +--- .../index/query/InnerHitBuilder.java | 32 ++------- .../opensearch/index/reindex/RemoteInfo.java | 11 +-- .../bucket/range/InternalBinaryRange.java | 9 +-- .../bucket/range/InternalRange.java | 9 +-- .../search/builder/SearchSourceBuilder.java | 26 ++----- .../search/fetch/subphase/FieldAndFormat.java | 11 +-- .../search/internal/ShardSearchRequest.java | 15 ++-- .../opensearch/search/slice/SliceBuilder.java | 7 +- .../search/sort/GeoDistanceSortBuilder.java | 8 +-- .../action/search/SearchRequestTests.java | 21 ------ .../ShardsAcknowledgedResponseTests.java | 15 +--- .../coordination/JoinTaskExecutorTests.java | 2 +- .../opensearch/ingest/IngestStatsTests.java | 21 ------ 37 files changed, 109 insertions(+), 385 deletions(-) diff --git a/modules/lang-painless/src/main/java/org/opensearch/painless/action/PainlessExecuteAction.java b/modules/lang-painless/src/main/java/org/opensearch/painless/action/PainlessExecuteAction.java index 2c8796d49f3..4999d5d4446 100644 --- a/modules/lang-painless/src/main/java/org/opensearch/painless/action/PainlessExecuteAction.java +++ b/modules/lang-painless/src/main/java/org/opensearch/painless/action/PainlessExecuteAction.java @@ -42,7 +42,6 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.Weight; -import org.opensearch.LegacyESVersion; import org.apache.lucene.store.ByteBuffersDirectory; import org.apache.lucene.store.Directory; import org.opensearch.action.ActionRequestValidationException; @@ -314,15 +313,8 @@ public class PainlessExecuteAction extends ActionType indices = in.readStringArray(); aliases = in.readStringArray(); indicesOptions = IndicesOptions.readIndicesOptions(in); - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - originalAliases = in.readStringArray(); - } + originalAliases = in.readStringArray(); } @Override @@ -72,9 +69,7 @@ public class GetAliasesRequest extends MasterNodeReadRequest out.writeStringArray(indices); out.writeStringArray(aliases); indicesOptions.writeIndicesOptions(out); - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - out.writeStringArray(originalAliases); - } + out.writeStringArray(originalAliases); } @Override diff --git a/server/src/main/java/org/opensearch/action/admin/indices/close/CloseIndexResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/close/CloseIndexResponse.java index 6b89a335fc3..998ffc4af70 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/close/CloseIndexResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/close/CloseIndexResponse.java @@ -57,7 +57,7 @@ public class CloseIndexResponse extends ShardsAcknowledgedResponse { private final List indices; CloseIndexResponse(StreamInput in) throws IOException { - super(in, in.getVersion().onOrAfter(LegacyESVersion.V_7_2_0), true); + super(in, in.getVersion().onOrAfter(LegacyESVersion.V_7_2_0)); if (in.getVersion().onOrAfter(LegacyESVersion.V_7_3_0)) { indices = unmodifiableList(in.readList(IndexResult::new)); } else { diff --git a/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexResponse.java index f72a71a8d68..dedc022180c 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexResponse.java @@ -71,7 +71,7 @@ public class CreateIndexResponse extends ShardsAcknowledgedResponse { private final String index; protected CreateIndexResponse(StreamInput in) throws IOException { - super(in, true, true); + super(in, true); index = in.readString(); } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/get/GetIndexRequest.java b/server/src/main/java/org/opensearch/action/admin/indices/get/GetIndexRequest.java index 84f282c6a28..e1e0b2c54c9 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/get/GetIndexRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/get/GetIndexRequest.java @@ -32,7 +32,6 @@ package org.opensearch.action.admin.indices.get; -import org.opensearch.LegacyESVersion; import org.opensearch.action.ActionRequestValidationException; import org.opensearch.action.support.master.info.ClusterInfoRequest; import org.opensearch.common.io.stream.StreamInput; @@ -90,9 +89,7 @@ public class GetIndexRequest extends ClusterInfoRequest { super(in); features = in.readArray(i -> Feature.fromId(i.readByte()), Feature[]::new); humanReadable = in.readBoolean(); - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - includeDefaults = in.readBoolean(); - } + includeDefaults = in.readBoolean(); } public GetIndexRequest features(Feature... features) { @@ -156,9 +153,7 @@ public class GetIndexRequest extends ClusterInfoRequest { super.writeTo(out); out.writeArray((o, f) -> o.writeByte(f.id), features); out.writeBoolean(humanReadable); - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - out.writeBoolean(includeDefaults); - } + out.writeBoolean(includeDefaults); } } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/open/OpenIndexResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/open/OpenIndexResponse.java index af2754bf210..4b811b215d7 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/open/OpenIndexResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/open/OpenIndexResponse.java @@ -56,7 +56,7 @@ public class OpenIndexResponse extends ShardsAcknowledgedResponse { } public OpenIndexResponse(StreamInput in) throws IOException { - super(in, true, true); + super(in, true); } public OpenIndexResponse(boolean acknowledged, boolean shardsAcknowledged) { diff --git a/server/src/main/java/org/opensearch/action/admin/indices/readonly/AddIndexBlockResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/readonly/AddIndexBlockResponse.java index 15db40b2485..036a8ec635e 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/readonly/AddIndexBlockResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/readonly/AddIndexBlockResponse.java @@ -55,7 +55,7 @@ public class AddIndexBlockResponse extends ShardsAcknowledgedResponse { private final List indices; AddIndexBlockResponse(StreamInput in) throws IOException { - super(in, true, true); + super(in, true); indices = unmodifiableList(in.readList(AddBlockResult::new)); } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/rollover/RolloverResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/rollover/RolloverResponse.java index 7f03867762d..5600d05120a 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/rollover/RolloverResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/rollover/RolloverResponse.java @@ -32,7 +32,6 @@ package org.opensearch.action.admin.indices.rollover; -import org.opensearch.LegacyESVersion; import org.opensearch.action.support.master.ShardsAcknowledgedResponse; import org.opensearch.common.ParseField; import org.opensearch.common.io.stream.StreamInput; @@ -98,31 +97,17 @@ public final class RolloverResponse extends ShardsAcknowledgedResponse implement private final boolean shardsAcknowledged; RolloverResponse(StreamInput in) throws IOException { - super(in, false, in.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)); - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - oldIndex = in.readString(); - newIndex = in.readString(); - int conditionSize = in.readVInt(); - conditionStatus = new HashMap<>(conditionSize); - for (int i = 0; i < conditionSize; i++) { - conditionStatus.put(in.readString(), in.readBoolean()); - } - dryRun = in.readBoolean(); - rolledOver = in.readBoolean(); - shardsAcknowledged = in.readBoolean(); - } else { - oldIndex = in.readString(); - newIndex = in.readString(); - int conditionSize = in.readVInt(); - conditionStatus = new HashMap<>(conditionSize); - for (int i = 0; i < conditionSize; i++) { - conditionStatus.put(in.readString(), in.readBoolean()); - } - dryRun = in.readBoolean(); - rolledOver = in.readBoolean(); - acknowledged = in.readBoolean(); - shardsAcknowledged = in.readBoolean(); + super(in, false); + oldIndex = in.readString(); + newIndex = in.readString(); + int conditionSize = in.readVInt(); + conditionStatus = new HashMap<>(conditionSize); + for (int i = 0; i < conditionSize; i++) { + conditionStatus.put(in.readString(), in.readBoolean()); } + dryRun = in.readBoolean(); + rolledOver = in.readBoolean(); + shardsAcknowledged = in.readBoolean(); } public RolloverResponse( @@ -185,31 +170,17 @@ public final class RolloverResponse extends ShardsAcknowledgedResponse implement @Override public void writeTo(StreamOutput out) throws IOException { - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - super.writeTo(out); - out.writeString(oldIndex); - out.writeString(newIndex); - out.writeVInt(conditionStatus.size()); - for (Map.Entry entry : conditionStatus.entrySet()) { - out.writeString(entry.getKey()); - out.writeBoolean(entry.getValue()); - } - out.writeBoolean(dryRun); - out.writeBoolean(rolledOver); - out.writeBoolean(shardsAcknowledged); - } else { - out.writeString(oldIndex); - out.writeString(newIndex); - out.writeVInt(conditionStatus.size()); - for (Map.Entry entry : conditionStatus.entrySet()) { - out.writeString(entry.getKey()); - out.writeBoolean(entry.getValue()); - } - out.writeBoolean(dryRun); - out.writeBoolean(rolledOver); - out.writeBoolean(acknowledged); - writeShardsAcknowledged(out); + super.writeTo(out); + out.writeString(oldIndex); + out.writeString(newIndex); + out.writeVInt(conditionStatus.size()); + for (Map.Entry entry : conditionStatus.entrySet()) { + out.writeString(entry.getKey()); + out.writeBoolean(entry.getValue()); } + out.writeBoolean(dryRun); + out.writeBoolean(rolledOver); + out.writeBoolean(shardsAcknowledged); } @Override diff --git a/server/src/main/java/org/opensearch/action/admin/indices/settings/get/GetSettingsRequest.java b/server/src/main/java/org/opensearch/action/admin/indices/settings/get/GetSettingsRequest.java index 1cfea627b05..739dfcae628 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/settings/get/GetSettingsRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/settings/get/GetSettingsRequest.java @@ -32,7 +32,6 @@ package org.opensearch.action.admin.indices.settings.get; -import org.opensearch.LegacyESVersion; import org.opensearch.action.ActionRequestValidationException; import org.opensearch.action.IndicesRequest; import org.opensearch.action.ValidateActions; @@ -82,9 +81,7 @@ public class GetSettingsRequest extends MasterNodeReadRequest implements targetIndexRequest = new CreateIndexRequest(in); sourceIndex = in.readString(); type = in.readEnum(ResizeType.class); - if (in.getVersion().before(LegacyESVersion.V_6_4_0)) { - copySettings = null; - } else { - copySettings = in.readOptionalBoolean(); - } + copySettings = in.readOptionalBoolean(); } ResizeRequest() {} @@ -128,12 +124,7 @@ public class ResizeRequest extends AcknowledgedRequest implements throw new IllegalArgumentException("can't send clone request to a node that's older than " + LegacyESVersion.V_7_4_0); } out.writeEnum(type); - // noinspection StatementWithEmptyBody - if (out.getVersion().before(LegacyESVersion.V_6_4_0)) { - - } else { - out.writeOptionalBoolean(copySettings); - } + out.writeOptionalBoolean(copySettings); } @Override diff --git a/server/src/main/java/org/opensearch/action/admin/indices/validate/query/QueryExplanation.java b/server/src/main/java/org/opensearch/action/admin/indices/validate/query/QueryExplanation.java index 74346f04b52..3764cfd1e60 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/validate/query/QueryExplanation.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/validate/query/QueryExplanation.java @@ -32,7 +32,6 @@ package org.opensearch.action.admin.indices.validate.query; -import org.opensearch.LegacyESVersion; import org.opensearch.common.ParseField; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; @@ -84,11 +83,7 @@ public class QueryExplanation implements Writeable, ToXContentFragment { private String error; public QueryExplanation(StreamInput in) throws IOException { - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - index = in.readOptionalString(); - } else { - index = in.readString(); - } + index = in.readOptionalString(); shard = in.readInt(); valid = in.readBoolean(); explanation = in.readOptionalString(); @@ -125,11 +120,7 @@ public class QueryExplanation implements Writeable, ToXContentFragment { @Override public void writeTo(StreamOutput out) throws IOException { - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - out.writeOptionalString(index); - } else { - out.writeString(index); - } + out.writeOptionalString(index); out.writeInt(shard); out.writeBoolean(valid); out.writeOptionalString(explanation); diff --git a/server/src/main/java/org/opensearch/action/resync/ResyncReplicationRequest.java b/server/src/main/java/org/opensearch/action/resync/ResyncReplicationRequest.java index 8f3d9176dca..2b7ff6ba3f1 100644 --- a/server/src/main/java/org/opensearch/action/resync/ResyncReplicationRequest.java +++ b/server/src/main/java/org/opensearch/action/resync/ResyncReplicationRequest.java @@ -36,7 +36,6 @@ import org.opensearch.action.index.IndexRequest; import org.opensearch.action.support.replication.ReplicatedWriteRequest; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.index.seqno.SequenceNumbers; import org.opensearch.index.shard.ShardId; import org.opensearch.index.translog.Translog; @@ -55,11 +54,7 @@ public final class ResyncReplicationRequest extends ReplicatedWriteRequest implements To out.writeBoolean(false); } - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - out.writeOptionalBoolean(writeIndex()); - } + out.writeOptionalBoolean(writeIndex()); if (out.getVersion().onOrAfter(LegacyESVersion.V_7_7_0)) { out.writeOptionalBoolean(isHidden()); @@ -249,11 +247,7 @@ public class AliasMetadata extends AbstractDiffable implements To searchRouting = null; searchRoutingValues = emptySet(); } - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - writeIndex = in.readOptionalBoolean(); - } else { - writeIndex = null; - } + writeIndex = in.readOptionalBoolean(); if (in.getVersion().onOrAfter(LegacyESVersion.V_7_7_0)) { isHidden = in.readOptionalBoolean(); diff --git a/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java index 3be7a6912aa..ce824767348 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java @@ -968,9 +968,7 @@ public class IndexMetadata implements Diffable, ToXContentFragmen aliases.writeTo(out); customData.writeTo(out); inSyncAllocationIds.writeTo(out); - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - rolloverInfos.writeTo(out); - } + rolloverInfos.writeTo(out); if (out.getVersion().onOrAfter(SYSTEM_INDEX_FLAG_ADDED)) { out.writeBoolean(isSystem); } @@ -1041,11 +1039,9 @@ public class IndexMetadata implements Diffable, ToXContentFragmen Set allocationIds = DiffableUtils.StringSetValueSerializer.getInstance().read(in, key); builder.putInSyncAllocationIds(key, allocationIds); } - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - int rolloverAliasesSize = in.readVInt(); - for (int i = 0; i < rolloverAliasesSize; i++) { - builder.putRolloverInfo(new RolloverInfo(in)); - } + int rolloverAliasesSize = in.readVInt(); + for (int i = 0; i < rolloverAliasesSize; i++) { + builder.putRolloverInfo(new RolloverInfo(in)); } if (in.getVersion().onOrAfter(SYSTEM_INDEX_FLAG_ADDED)) { builder.system(in.readBoolean()); @@ -1092,11 +1088,9 @@ public class IndexMetadata implements Diffable, ToXContentFragmen out.writeVInt(cursor.key); DiffableUtils.StringSetValueSerializer.getInstance().write(cursor.value, out); } - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - out.writeVInt(rolloverInfos.size()); - for (ObjectCursor cursor : rolloverInfos.values()) { - cursor.value.writeTo(out); - } + out.writeVInt(rolloverInfos.size()); + for (ObjectCursor cursor : rolloverInfos.values()) { + cursor.value.writeTo(out); } if (out.getVersion().onOrAfter(SYSTEM_INDEX_FLAG_ADDED)) { out.writeBoolean(isSystem); diff --git a/server/src/main/java/org/opensearch/index/query/AbstractGeometryQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/AbstractGeometryQueryBuilder.java index 0847d25563b..ca7e97cfb8b 100644 --- a/server/src/main/java/org/opensearch/index/query/AbstractGeometryQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/AbstractGeometryQueryBuilder.java @@ -35,7 +35,6 @@ package org.opensearch.index.query; import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.util.SetOnce; -import org.opensearch.LegacyESVersion; import org.opensearch.action.ActionListener; import org.opensearch.action.get.GetRequest; import org.opensearch.action.get.GetResponse; @@ -204,11 +203,7 @@ public abstract class AbstractGeometryQueryBuilder fieldList = (List) in.readGenericValue(); - if (fieldList == null) { - docValueFields = null; - } else { - docValueFields = fieldList.stream().map(field -> new FieldAndFormat(field, null)).collect(Collectors.toList()); - } - } else { - docValueFields = in.readBoolean() ? in.readList(FieldAndFormat::new) : null; - } + docValueFields = in.readBoolean() ? in.readList(FieldAndFormat::new) : null; if (in.readBoolean()) { int size = in.readVInt(); scriptFields = new HashSet<>(size); @@ -218,9 +207,7 @@ public final class InnerHitBuilder implements Writeable, ToXContentObject { } } highlightBuilder = in.readOptionalWriteable(HighlightBuilder::new); - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - this.innerCollapseBuilder = in.readOptionalWriteable(CollapseBuilder::new); - } + this.innerCollapseBuilder = in.readOptionalWriteable(CollapseBuilder::new); if (in.getVersion().onOrAfter(LegacyESVersion.V_7_10_0)) { if (in.readBoolean()) { @@ -242,13 +229,10 @@ public final class InnerHitBuilder implements Writeable, ToXContentObject { } out.writeBoolean(trackScores); out.writeOptionalWriteable(storedFieldsContext); - if (out.getVersion().before(LegacyESVersion.V_6_4_0)) { - out.writeGenericValue(docValueFields == null ? null : docValueFields.stream().map(ff -> ff.field).collect(Collectors.toList())); - } else { - out.writeBoolean(docValueFields != null); - if (docValueFields != null) { - out.writeList(docValueFields); - } + + out.writeBoolean(docValueFields != null); + if (docValueFields != null) { + out.writeList(docValueFields); } boolean hasScriptFields = scriptFields != null; out.writeBoolean(hasScriptFields); @@ -269,9 +253,7 @@ public final class InnerHitBuilder implements Writeable, ToXContentObject { } } out.writeOptionalWriteable(highlightBuilder); - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - out.writeOptionalWriteable(innerCollapseBuilder); - } + out.writeOptionalWriteable(innerCollapseBuilder); if (out.getVersion().onOrAfter(LegacyESVersion.V_7_10_0)) { out.writeBoolean(fetchFields != null); diff --git a/server/src/main/java/org/opensearch/index/reindex/RemoteInfo.java b/server/src/main/java/org/opensearch/index/reindex/RemoteInfo.java index 9e2809b0601..03d0ab072a5 100644 --- a/server/src/main/java/org/opensearch/index/reindex/RemoteInfo.java +++ b/server/src/main/java/org/opensearch/index/reindex/RemoteInfo.java @@ -32,7 +32,6 @@ package org.opensearch.index.reindex; -import org.opensearch.LegacyESVersion; import org.opensearch.common.Nullable; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; @@ -130,11 +129,7 @@ public class RemoteInfo implements Writeable, ToXContentObject { this.headers = unmodifiableMap(headers); socketTimeout = in.readTimeValue(); connectTimeout = in.readTimeValue(); - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - pathPrefix = in.readOptionalString(); - } else { - pathPrefix = null; - } + pathPrefix = in.readOptionalString(); } @Override @@ -152,9 +147,7 @@ public class RemoteInfo implements Writeable, ToXContentObject { } out.writeTimeValue(socketTimeout); out.writeTimeValue(connectTimeout); - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - out.writeOptionalString(pathPrefix); - } + out.writeOptionalString(pathPrefix); } public String getScheme() { diff --git a/server/src/main/java/org/opensearch/search/aggregations/bucket/range/InternalBinaryRange.java b/server/src/main/java/org/opensearch/search/aggregations/bucket/range/InternalBinaryRange.java index a20cc06ce02..506593113a0 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/bucket/range/InternalBinaryRange.java +++ b/server/src/main/java/org/opensearch/search/aggregations/bucket/range/InternalBinaryRange.java @@ -33,7 +33,6 @@ package org.opensearch.search.aggregations.bucket.range; import org.apache.lucene.util.BytesRef; -import org.opensearch.LegacyESVersion; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.xcontent.XContentBuilder; @@ -93,7 +92,7 @@ public final class InternalBinaryRange extends InternalMultiBucketAggregation ranges = new ArrayList<>(size); for (int i = 0; i < size; i++) { - String key = in.getVersion().onOrAfter(LegacyESVersion.V_6_4_0) ? in.readString() : in.readOptionalString(); + String key = in.readString(); ranges.add( getFactory().createBucket( key, diff --git a/server/src/main/java/org/opensearch/search/builder/SearchSourceBuilder.java b/server/src/main/java/org/opensearch/search/builder/SearchSourceBuilder.java index cdb2cc542fa..034cf1e9cc7 100644 --- a/server/src/main/java/org/opensearch/search/builder/SearchSourceBuilder.java +++ b/server/src/main/java/org/opensearch/search/builder/SearchSourceBuilder.java @@ -78,7 +78,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; import static org.opensearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder; import static org.opensearch.search.internal.SearchContext.TRACK_TOTAL_HITS_ACCURATE; @@ -219,19 +218,10 @@ public final class SearchSourceBuilder implements Writeable, ToXContentObject, R aggregations = in.readOptionalWriteable(AggregatorFactories.Builder::new); explain = in.readOptionalBoolean(); fetchSourceContext = in.readOptionalWriteable(FetchSourceContext::new); - if (in.getVersion().before(LegacyESVersion.V_6_4_0)) { - List dvFields = (List) in.readGenericValue(); - if (dvFields == null) { - docValueFields = null; - } else { - docValueFields = dvFields.stream().map(field -> new FieldAndFormat(field, null)).collect(Collectors.toList()); - } + if (in.readBoolean()) { + docValueFields = in.readList(FieldAndFormat::new); } else { - if (in.readBoolean()) { - docValueFields = in.readList(FieldAndFormat::new); - } else { - docValueFields = null; - } + docValueFields = null; } storedFieldsContext = in.readOptionalWriteable(StoredFieldsContext::new); from = in.readVInt(); @@ -292,13 +282,9 @@ public final class SearchSourceBuilder implements Writeable, ToXContentObject, R out.writeOptionalWriteable(aggregations); out.writeOptionalBoolean(explain); out.writeOptionalWriteable(fetchSourceContext); - if (out.getVersion().before(LegacyESVersion.V_6_4_0)) { - out.writeGenericValue(docValueFields == null ? null : docValueFields.stream().map(ff -> ff.field).collect(Collectors.toList())); - } else { - out.writeBoolean(docValueFields != null); - if (docValueFields != null) { - out.writeList(docValueFields); - } + out.writeBoolean(docValueFields != null); + if (docValueFields != null) { + out.writeList(docValueFields); } out.writeOptionalWriteable(storedFieldsContext); out.writeVInt(from); diff --git a/server/src/main/java/org/opensearch/search/fetch/subphase/FieldAndFormat.java b/server/src/main/java/org/opensearch/search/fetch/subphase/FieldAndFormat.java index 4478195f01e..c87151170e1 100644 --- a/server/src/main/java/org/opensearch/search/fetch/subphase/FieldAndFormat.java +++ b/server/src/main/java/org/opensearch/search/fetch/subphase/FieldAndFormat.java @@ -32,7 +32,6 @@ package org.opensearch.search.fetch.subphase; -import org.opensearch.LegacyESVersion; import org.opensearch.common.Nullable; import org.opensearch.common.ParseField; import org.opensearch.common.io.stream.StreamInput; @@ -91,19 +90,13 @@ public final class FieldAndFormat implements Writeable, ToXContentObject { /** Serialization constructor. */ public FieldAndFormat(StreamInput in) throws IOException { this.field = in.readString(); - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - format = in.readOptionalString(); - } else { - format = null; - } + format = in.readOptionalString(); } @Override public void writeTo(StreamOutput out) throws IOException { out.writeString(field); - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - out.writeOptionalString(format); - } + out.writeOptionalString(format); } @Override diff --git a/server/src/main/java/org/opensearch/search/internal/ShardSearchRequest.java b/server/src/main/java/org/opensearch/search/internal/ShardSearchRequest.java index 562275b2512..42690bc88c9 100644 --- a/server/src/main/java/org/opensearch/search/internal/ShardSearchRequest.java +++ b/server/src/main/java/org/opensearch/search/internal/ShardSearchRequest.java @@ -255,13 +255,8 @@ public class ShardSearchRequest extends TransportRequest implements IndicesReque } else { allowPartialSearchResults = false; } - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - indexRoutings = in.readStringArray(); - preference = in.readOptionalString(); - } else { - indexRoutings = Strings.EMPTY_ARRAY; - preference = null; - } + indexRoutings = in.readStringArray(); + preference = in.readOptionalString(); if (in.getVersion().onOrAfter(LegacyESVersion.V_7_7_0)) { canReturnNullResponseIfMatchNoDocs = in.readBoolean(); bottomSortValues = in.readOptionalWriteable(SearchSortValuesAndFormats::new); @@ -335,10 +330,8 @@ public class ShardSearchRequest extends TransportRequest implements IndicesReque out.writeBoolean(allowPartialSearchResults); } if (asKey == false) { - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - out.writeStringArray(indexRoutings); - out.writeOptionalString(preference); - } + out.writeStringArray(indexRoutings); + out.writeOptionalString(preference); } if (out.getVersion().onOrAfter(LegacyESVersion.V_7_7_0) && asKey == false) { out.writeBoolean(canReturnNullResponseIfMatchNoDocs); diff --git a/server/src/main/java/org/opensearch/search/slice/SliceBuilder.java b/server/src/main/java/org/opensearch/search/slice/SliceBuilder.java index 4550e94d8c2..9a9444927ae 100644 --- a/server/src/main/java/org/opensearch/search/slice/SliceBuilder.java +++ b/server/src/main/java/org/opensearch/search/slice/SliceBuilder.java @@ -227,20 +227,17 @@ public class SliceBuilder implements Writeable, ToXContentObject { int shardId = request.shardId().id(); int numShards = context.getIndexSettings().getNumberOfShards(); - if (minNodeVersion.onOrAfter(LegacyESVersion.V_6_4_0) && (request.preference() != null || request.indexRoutings().length > 0)) { + if ((request.preference() != null || request.indexRoutings().length > 0)) { GroupShardsIterator group = buildShardIterator(clusterService, request); assert group.size() <= numShards : "index routing shards: " + group.size() + " cannot be greater than total number of shards: " + numShards; if (group.size() < numShards) { - /** + /* * The routing of this request targets a subset of the shards of this index so we need to we retrieve * the original {@link GroupShardsIterator} and compute the request shard id and number of * shards from it. - * This behavior has been added in {@link LegacyESVersion#V_6_4_0} so if there is another node in the cluster - * with an older version we use the original shard id and number of shards in order to ensure that all - * slices use the same numbers. */ numShards = group.size(); int ord = 0; diff --git a/server/src/main/java/org/opensearch/search/sort/GeoDistanceSortBuilder.java b/server/src/main/java/org/opensearch/search/sort/GeoDistanceSortBuilder.java index 9fb90ee1ebc..1a53f288b7a 100644 --- a/server/src/main/java/org/opensearch/search/sort/GeoDistanceSortBuilder.java +++ b/server/src/main/java/org/opensearch/search/sort/GeoDistanceSortBuilder.java @@ -189,9 +189,7 @@ public class GeoDistanceSortBuilder extends SortBuilder nestedPath = in.readOptionalString(); nestedSort = in.readOptionalWriteable(NestedSortBuilder::new); validation = GeoValidationMethod.readFromStream(in); - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - ignoreUnmapped = in.readBoolean(); - } + ignoreUnmapped = in.readBoolean(); } @Override @@ -206,9 +204,7 @@ public class GeoDistanceSortBuilder extends SortBuilder out.writeOptionalString(nestedPath); out.writeOptionalWriteable(nestedSort); validation.writeTo(out); - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) { - out.writeBoolean(ignoreUnmapped); - } + out.writeBoolean(ignoreUnmapped); } /** diff --git a/server/src/test/java/org/opensearch/action/search/SearchRequestTests.java b/server/src/test/java/org/opensearch/action/search/SearchRequestTests.java index 3107c1cb88c..1cad4e2aa34 100644 --- a/server/src/test/java/org/opensearch/action/search/SearchRequestTests.java +++ b/server/src/test/java/org/opensearch/action/search/SearchRequestTests.java @@ -37,7 +37,6 @@ import org.opensearch.Version; import org.opensearch.action.ActionRequestValidationException; import org.opensearch.action.support.IndicesOptions; import org.opensearch.common.Strings; -import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.unit.TimeValue; import org.opensearch.common.util.ArrayUtils; import org.opensearch.index.query.QueryBuilders; @@ -52,7 +51,6 @@ import org.opensearch.test.VersionUtils; import java.io.IOException; import java.util.ArrayList; -import java.util.Base64; import java.util.List; import static java.util.Collections.emptyMap; @@ -134,25 +132,6 @@ public class SearchRequestTests extends AbstractSearchTestCase { } } - public void testReadFromPre6_7_0() throws IOException { - String msg = "AAEBBWluZGV4AAAAAQACAAAA/////w8AAAAAAAAA/////w8AAAAAAAACAAAAAAABAAMCBAUBAAKABACAAQIAAA=="; - try (StreamInput in = StreamInput.wrap(Base64.getDecoder().decode(msg))) { - in.setVersion( - VersionUtils.randomVersionBetween( - random(), - LegacyESVersion.V_6_4_0, - VersionUtils.getPreviousVersion(LegacyESVersion.V_6_7_0) - ) - ); - SearchRequest searchRequest = new SearchRequest(in); - assertArrayEquals(new String[] { "index" }, searchRequest.indices()); - assertNull(searchRequest.getLocalClusterAlias()); - assertAbsoluteStartMillisIsCurrentTime(searchRequest); - assertTrue(searchRequest.isCcsMinimizeRoundtrips()); - assertTrue(searchRequest.isFinalReduce()); - } - } - private static void assertAbsoluteStartMillisIsCurrentTime(SearchRequest searchRequest) { long before = System.currentTimeMillis(); long absoluteStartMillis = searchRequest.getOrCreateAbsoluteStartMillis(); diff --git a/server/src/test/java/org/opensearch/action/support/master/ShardsAcknowledgedResponseTests.java b/server/src/test/java/org/opensearch/action/support/master/ShardsAcknowledgedResponseTests.java index 47a964fb834..90a428a7650 100644 --- a/server/src/test/java/org/opensearch/action/support/master/ShardsAcknowledgedResponseTests.java +++ b/server/src/test/java/org/opensearch/action/support/master/ShardsAcknowledgedResponseTests.java @@ -50,26 +50,17 @@ public class ShardsAcknowledgedResponseTests extends OpenSearchTestCase { ShardsAcknowledgedResponse result = copyWriteable( testInstance, new NamedWriteableRegistry(Collections.emptyList()), - in -> new TestImpl(in, true, true), + in -> new TestImpl(in, true), Version.CURRENT ); assertThat(result.isAcknowledged(), is(true)); assertThat(result.isShardsAcknowledged(), is(true)); - - result = copyWriteable( - testInstance, - new NamedWriteableRegistry(Collections.emptyList()), - in -> new TestImpl(in, false, false), - Version.CURRENT - ); - assertThat(result.isAcknowledged(), is(false)); - assertThat(result.isShardsAcknowledged(), is(false)); } private static class TestImpl extends ShardsAcknowledgedResponse { - private TestImpl(StreamInput in, boolean readShardsAcknowledged, boolean readAcknowledged) throws IOException { - super(in, readShardsAcknowledged, readAcknowledged); + private TestImpl(StreamInput in, boolean readShardsAcknowledged) throws IOException { + super(in, readShardsAcknowledged); } private TestImpl(boolean acknowledged, boolean shardsAcknowledged) { diff --git a/server/src/test/java/org/opensearch/cluster/coordination/JoinTaskExecutorTests.java b/server/src/test/java/org/opensearch/cluster/coordination/JoinTaskExecutorTests.java index b0bc147cdc0..3e4cfd7f100 100644 --- a/server/src/test/java/org/opensearch/cluster/coordination/JoinTaskExecutorTests.java +++ b/server/src/test/java/org/opensearch/cluster/coordination/JoinTaskExecutorTests.java @@ -119,7 +119,7 @@ public class JoinTaskExecutorTests extends OpenSearchTestCase { } if (minNodeVersion.onOrAfter(LegacyESVersion.V_7_0_0)) { - Version oldMajor = LegacyESVersion.V_6_4_0.minimumCompatibilityVersion(); + Version oldMajor = minNodeVersion.minimumCompatibilityVersion(); expectThrows(IllegalStateException.class, () -> JoinTaskExecutor.ensureMajorVersionBarrier(oldMajor, minNodeVersion)); } diff --git a/server/src/test/java/org/opensearch/ingest/IngestStatsTests.java b/server/src/test/java/org/opensearch/ingest/IngestStatsTests.java index b49be2a2f79..0486c9f29f8 100644 --- a/server/src/test/java/org/opensearch/ingest/IngestStatsTests.java +++ b/server/src/test/java/org/opensearch/ingest/IngestStatsTests.java @@ -58,27 +58,6 @@ public class IngestStatsTests extends OpenSearchTestCase { assertIngestStats(ingestStats, serializedStats, true, true); } - public void testReadLegacyStream() throws IOException { - IngestStats.Stats totalStats = new IngestStats.Stats(50, 100, 200, 300); - List pipelineStats = createPipelineStats(); - - // legacy output logic - BytesStreamOutput out = new BytesStreamOutput(); - out.setVersion(VersionUtils.getPreviousVersion(LegacyESVersion.V_6_5_0)); - totalStats.writeTo(out); - out.writeVInt(pipelineStats.size()); - for (IngestStats.PipelineStat pipelineStat : pipelineStats) { - out.writeString(pipelineStat.getPipelineId()); - pipelineStat.getStats().writeTo(out); - } - - StreamInput in = out.bytes().streamInput(); - in.setVersion(VersionUtils.getPreviousVersion(LegacyESVersion.V_6_5_0)); - IngestStats serializedStats = new IngestStats(in); - IngestStats expectedStats = new IngestStats(totalStats, pipelineStats, Collections.emptyMap()); - assertIngestStats(expectedStats, serializedStats, false, true); - } - public void testBWCIngestProcessorTypeStats() throws IOException { IngestStats.Stats totalStats = new IngestStats.Stats(50, 100, 200, 300); List pipelineStats = createPipelineStats();