From 01e1b94e47aa8cb04ad2a34e505f31cfdf7b0fed Mon Sep 17 00:00:00 2001 From: Rabi Panda Date: Tue, 28 Dec 2021 09:52:51 -0800 Subject: [PATCH] Remove LegacyESVersion.V_6_5_x constants (#1794) * Remove v6.5.x constants Signed-off-by: Rabi Panda * Address code review comments. Signed-off-by: Rabi Panda * Add back version assumption for testRemoteClusterSettingsUpgraded Signed-off-by: Rabi Panda * Remove unused import after rebase. Signed-off-by: Rabi Panda --- .../upgrades/FullClusterRestartIT.java | 33 ++-------- .../FullClusterRestartSettingsUpgradeIT.java | 2 +- .../opensearch/upgrades/TranslogPolicyIT.java | 8 +-- .../PeerRecoveryRetentionLeaseCreationIT.java | 9 +-- .../java/org/opensearch/LegacyESVersion.java | 5 -- .../indices/create/CreateIndexRequest.java | 12 ---- .../template/put/PutIndexTemplateRequest.java | 12 ---- .../resync/ResyncReplicationRequest.java | 12 +--- .../TransportReplicationAction.java | 13 +--- .../cluster/metadata/IndexMetadata.java | 60 +++++-------------- .../metadata/IndexTemplateMetadata.java | 12 ---- .../org/opensearch/index/IndexService.java | 5 +- .../org/opensearch/index/IndexSettings.java | 2 +- .../index/mapper/MapperService.java | 4 +- .../opensearch/index/mapper/ParseContext.java | 17 ++---- .../index/similarity/SimilarityService.java | 2 +- .../RecoveryTranslogOperationsRequest.java | 23 ++----- .../org/opensearch/ingest/IngestStats.java | 44 +++++++------- .../opensearch/search/fetch/FetchPhase.java | 39 ++++-------- .../search/sort/FieldSortBuilder.java | 3 - .../search/sort/GeoDistanceSortBuilder.java | 5 -- .../search/sort/NestedSortBuilder.java | 11 +--- .../search/sort/ScriptSortBuilder.java | 4 -- .../org/opensearch/LegacyESVersionTests.java | 2 +- .../opensearch/index/IndexSettingsTests.java | 10 ---- .../RetentionLeasesReplicationTests.java | 7 +-- 26 files changed, 79 insertions(+), 277 deletions(-) diff --git a/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/FullClusterRestartIT.java b/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/FullClusterRestartIT.java index 37c7554bb66..4412b9d67dd 100644 --- a/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/FullClusterRestartIT.java +++ b/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/FullClusterRestartIT.java @@ -90,7 +90,6 @@ import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.Matchers.startsWith; /** * Tests to run before and after a full cluster restart. This is run twice, @@ -705,9 +704,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { // before timing out .put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "100ms") .put(SETTING_ALLOCATION_MAX_RETRY.getKey(), "0"); // fail faster - if (getOldClusterVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean()); - } + settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean()); if (randomBoolean()) { settings.put(IndexSettings.INDEX_TRANSLOG_RETENTION_SIZE_SETTING.getKey(), "-1"); } @@ -977,7 +974,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { mappingsAndSettings.startObject("settings"); mappingsAndSettings.field("number_of_shards", 1); mappingsAndSettings.field("number_of_replicas", 1); - if (getOldClusterVersion().onOrAfter(LegacyESVersion.V_6_5_0) && randomBoolean()) { + if (randomBoolean()) { mappingsAndSettings.field("soft_deletes.enabled", true); } mappingsAndSettings.endObject(); @@ -1125,21 +1122,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { clearRoutingFromSettings.setJsonEntity("{\"persistent\":{\"cluster.routing.allocation.exclude.test_attr\": null}}"); client().performRequest(clearRoutingFromSettings); } catch (WarningFailureException e) { - /* - * If this test is executed on the upgraded mode before testRemoteClusterSettingsUpgraded, - * we will hit a warning exception because we put some deprecated settings in that test. - */ - if (isRunningAgainstOldCluster() == false - && getOldClusterVersion().before(LegacyESVersion.V_6_5_0)) { - for (String warning : e.getResponse().getWarnings()) { - assertThat(warning, containsString( - "setting was deprecated and will be removed in a future release! " - + "See the breaking changes documentation for the next major version.")); - assertThat(warning, startsWith("[search.remote.")); - } - } else { - throw e; - } + throw e; } client().performRequest(new Request("DELETE", "/_template/test_template")); @@ -1335,7 +1318,6 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { } public void testPeerRecoveryRetentionLeases() throws Exception { - assumeTrue(getOldClusterVersion() + " does not support soft deletes", getOldClusterVersion().onOrAfter(LegacyESVersion.V_6_5_0)); if (isRunningAgainstOldCluster()) { XContentBuilder settings = jsonBuilder(); settings.startObject(); @@ -1428,9 +1410,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { final Settings.Builder settings = Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1); - if (getOldClusterVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean()); - } + settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean()); if (randomBoolean()) { settings.put(IndexSettings.INDEX_TRANSLOG_RETENTION_SIZE_SETTING.getKey(), "-1"); } @@ -1572,9 +1552,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { final Settings.Builder settings = Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1); - if (getOldClusterVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean()); - } + settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean()); createIndex(index, settings.build()); ensureGreen(index); int numDocs = randomIntBetween(0, 100); @@ -1623,7 +1601,6 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { } public void testForbidDisableSoftDeletesOnRestore() throws Exception { - assumeTrue("soft deletes is introduced in 6.5", getOldClusterVersion().onOrAfter(LegacyESVersion.V_6_5_0)); final String snapshot = "snapshot-" + index; if (isRunningAgainstOldCluster()) { final Settings.Builder settings = Settings.builder() diff --git a/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/FullClusterRestartSettingsUpgradeIT.java b/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/FullClusterRestartSettingsUpgradeIT.java index 2d28a712ee0..f82380fa672 100644 --- a/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/FullClusterRestartSettingsUpgradeIT.java +++ b/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/FullClusterRestartSettingsUpgradeIT.java @@ -58,7 +58,7 @@ import static org.hamcrest.Matchers.equalTo; public class FullClusterRestartSettingsUpgradeIT extends AbstractFullClusterRestartTestCase { public void testRemoteClusterSettingsUpgraded() throws IOException { - assumeTrue("settings automatically upgraded since 6.5.0", getOldClusterVersion().before(LegacyESVersion.V_6_5_0)); + assumeTrue("settings automatically upgraded since 6.5.0", getOldClusterVersion().before(LegacyESVersion.fromString("6.5.0"))); if (isRunningAgainstOldCluster()) { final Request putSettingsRequest = new Request("PUT", "/_cluster/settings"); try (XContentBuilder builder = jsonBuilder()) { diff --git a/qa/translog-policy/src/test/java/org/opensearch/upgrades/TranslogPolicyIT.java b/qa/translog-policy/src/test/java/org/opensearch/upgrades/TranslogPolicyIT.java index 30ac77cf2d4..9ab58d1e758 100644 --- a/qa/translog-policy/src/test/java/org/opensearch/upgrades/TranslogPolicyIT.java +++ b/qa/translog-policy/src/test/java/org/opensearch/upgrades/TranslogPolicyIT.java @@ -103,9 +103,7 @@ public class TranslogPolicyIT extends AbstractFullClusterRestartTestCase { final Settings.Builder settings = Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, between(0, 1)); - if (getOldClusterVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean()); - } + settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean()); if (randomBoolean()) { settings.put(IndexSettings.INDEX_TRANSLOG_RETENTION_SIZE_SETTING.getKey(), "-1"); } @@ -121,9 +119,7 @@ public class TranslogPolicyIT extends AbstractFullClusterRestartTestCase { final Settings.Builder settings = Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1); - if (getOldClusterVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean()); - } + settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean()); if (randomBoolean()) { settings.put(IndexSettings.INDEX_TRANSLOG_RETENTION_SIZE_SETTING.getKey(), "-1"); } diff --git a/server/src/internalClusterTest/java/org/opensearch/index/seqno/PeerRecoveryRetentionLeaseCreationIT.java b/server/src/internalClusterTest/java/org/opensearch/index/seqno/PeerRecoveryRetentionLeaseCreationIT.java index b7975744a61..e1e969345d5 100644 --- a/server/src/internalClusterTest/java/org/opensearch/index/seqno/PeerRecoveryRetentionLeaseCreationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/index/seqno/PeerRecoveryRetentionLeaseCreationIT.java @@ -31,7 +31,6 @@ package org.opensearch.index.seqno; -import org.opensearch.LegacyESVersion; import org.opensearch.Version; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.UUIDs; @@ -75,12 +74,8 @@ public class PeerRecoveryRetentionLeaseCreationIT extends OpenSearchIntegTestCas .put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true) .put( IndexMetadata.SETTING_VERSION_CREATED, - // simulate a version which supports soft deletes (v6.5.0-and-later) with which this node is compatible - VersionUtils.randomVersionBetween( - random(), - Version.max(Version.CURRENT.minimumIndexCompatibilityVersion(), LegacyESVersion.V_6_5_0), - Version.CURRENT - ) + // simulate a version which supports soft deletes with which this node is compatible + VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumIndexCompatibilityVersion(), Version.CURRENT) ) ) ); diff --git a/server/src/main/java/org/opensearch/LegacyESVersion.java b/server/src/main/java/org/opensearch/LegacyESVersion.java index d8c419889d5..9fd782d3fe1 100644 --- a/server/src/main/java/org/opensearch/LegacyESVersion.java +++ b/server/src/main/java/org/opensearch/LegacyESVersion.java @@ -46,11 +46,6 @@ import java.lang.reflect.Field; */ public class LegacyESVersion extends Version { - public static final LegacyESVersion V_6_5_0 = new LegacyESVersion(6050099, org.apache.lucene.util.Version.LUCENE_7_5_0); - public static final LegacyESVersion V_6_5_1 = new LegacyESVersion(6050199, org.apache.lucene.util.Version.LUCENE_7_5_0); - public static final LegacyESVersion V_6_5_2 = new LegacyESVersion(6050299, org.apache.lucene.util.Version.LUCENE_7_5_0); - public static final LegacyESVersion V_6_5_3 = new LegacyESVersion(6050399, org.apache.lucene.util.Version.LUCENE_7_5_0); - public static final LegacyESVersion V_6_5_4 = new LegacyESVersion(6050499, org.apache.lucene.util.Version.LUCENE_7_5_0); public static final LegacyESVersion V_6_6_0 = new LegacyESVersion(6060099, org.apache.lucene.util.Version.LUCENE_7_6_0); public static final LegacyESVersion V_6_6_1 = new LegacyESVersion(6060199, org.apache.lucene.util.Version.LUCENE_7_6_0); public static final LegacyESVersion V_6_6_2 = new LegacyESVersion(6060299, org.apache.lucene.util.Version.LUCENE_7_6_0); diff --git a/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java b/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java index 6ddddd288f8..1d6c093f97b 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java @@ -111,14 +111,6 @@ public class CreateIndexRequest extends AcknowledgedRequest String source = in.readString(); mappings.put(type, source); } - if (in.getVersion().before(LegacyESVersion.V_6_5_0)) { - // This used to be the size of custom metadata classes - int customSize = in.readVInt(); - assert customSize == 0 : "unexpected custom metadata when none is supported"; - if (customSize > 0) { - throw new IllegalStateException("unexpected custom metadata when none is supported"); - } - } int aliasesSize = in.readVInt(); for (int i = 0; i < aliasesSize; i++) { aliases.add(new Alias(in)); @@ -472,10 +464,6 @@ public class CreateIndexRequest extends AcknowledgedRequest out.writeString(entry.getKey()); out.writeString(entry.getValue()); } - if (out.getVersion().before(LegacyESVersion.V_6_5_0)) { - // Size of custom index metadata, which is removed - out.writeVInt(0); - } out.writeVInt(aliases.size()); for (Alias alias : aliases) { alias.writeTo(out); diff --git a/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequest.java b/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequest.java index 83f4e69a122..d331a1f9a55 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequest.java @@ -31,7 +31,6 @@ package org.opensearch.action.admin.indices.template.put; -import org.opensearch.LegacyESVersion; import org.opensearch.OpenSearchGenerationException; import org.opensearch.OpenSearchParseException; import org.opensearch.action.ActionRequestValidationException; @@ -114,14 +113,6 @@ public class PutIndexTemplateRequest extends MasterNodeRequest 0) { - throw new IllegalStateException("unexpected custom metadata when none is supported"); - } - } int aliasesSize = in.readVInt(); for (int i = 0; i < aliasesSize; i++) { aliases.add(new Alias(in)); @@ -502,9 +493,6 @@ public class PutIndexTemplateRequest extends MasterNodeRequest requestReader, StreamInput in) throws IOException { super(requestReader, in); globalCheckpoint = in.readZLong(); - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - maxSeqNoOfUpdatesOrDeletes = in.readZLong(); - } else { - // UNASSIGNED_SEQ_NO (-2) means uninitialized, and replicas will disable - // optimization using seq_no if its max_seq_no_of_updates is still uninitialized - maxSeqNoOfUpdatesOrDeletes = SequenceNumbers.UNASSIGNED_SEQ_NO; - } + maxSeqNoOfUpdatesOrDeletes = in.readZLong(); } public ConcreteReplicaRequest( @@ -1474,9 +1467,7 @@ public abstract class TransportReplicationAction< public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeZLong(globalCheckpoint); - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - out.writeZLong(maxSeqNoOfUpdatesOrDeletes); - } + out.writeZLong(maxSeqNoOfUpdatesOrDeletes); } public long getGlobalCheckpoint() { 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 ce824767348..147c8987169 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java @@ -909,16 +909,8 @@ public class IndexMetadata implements Diffable, ToXContentFragmen index = in.readString(); routingNumShards = in.readInt(); version = in.readLong(); - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - mappingVersion = in.readVLong(); - } else { - mappingVersion = 1; - } - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - settingsVersion = in.readVLong(); - } else { - settingsVersion = 1; - } + mappingVersion = in.readVLong(); + settingsVersion = in.readVLong(); if (in.getVersion().onOrAfter(LegacyESVersion.V_7_2_0)) { aliasesVersion = in.readVLong(); } else { @@ -952,12 +944,8 @@ public class IndexMetadata implements Diffable, ToXContentFragmen out.writeString(index); out.writeInt(routingNumShards); out.writeLong(version); - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - out.writeVLong(mappingVersion); - } - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - out.writeVLong(settingsVersion); - } + out.writeVLong(mappingVersion); + out.writeVLong(settingsVersion); if (out.getVersion().onOrAfter(LegacyESVersion.V_7_2_0)) { out.writeVLong(aliasesVersion); } @@ -998,16 +986,8 @@ public class IndexMetadata implements Diffable, ToXContentFragmen public static IndexMetadata readFrom(StreamInput in) throws IOException { Builder builder = new Builder(in.readString()); builder.version(in.readLong()); - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - builder.mappingVersion(in.readVLong()); - } else { - builder.mappingVersion(1); - } - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - builder.settingsVersion(in.readVLong()); - } else { - builder.settingsVersion(1); - } + builder.mappingVersion(in.readVLong()); + builder.settingsVersion(in.readVLong()); if (in.getVersion().onOrAfter(LegacyESVersion.V_7_2_0)) { builder.aliasesVersion(in.readVLong()); } else { @@ -1053,12 +1033,8 @@ public class IndexMetadata implements Diffable, ToXContentFragmen public void writeTo(StreamOutput out) throws IOException { out.writeString(index.getName()); // uuid will come as part of settings out.writeLong(version); - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - out.writeVLong(mappingVersion); - } - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - out.writeVLong(settingsVersion); - } + out.writeVLong(mappingVersion); + out.writeVLong(settingsVersion); if (out.getVersion().onOrAfter(LegacyESVersion.V_7_2_0)) { out.writeVLong(aliasesVersion); } @@ -1074,14 +1050,10 @@ public class IndexMetadata implements Diffable, ToXContentFragmen for (ObjectCursor cursor : aliases.values()) { cursor.value.writeTo(out); } - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - out.writeVInt(customData.size()); - for (final ObjectObjectCursor cursor : customData) { - out.writeString(cursor.key); - cursor.value.writeTo(out); - } - } else { - out.writeVInt(0); + out.writeVInt(customData.size()); + for (final ObjectObjectCursor cursor : customData) { + out.writeString(cursor.key); + cursor.value.writeTo(out); } out.writeVInt(inSyncAllocationIds.size()); for (IntObjectCursor> cursor : inSyncAllocationIds) { @@ -1731,11 +1703,11 @@ public class IndexMetadata implements Diffable, ToXContentFragmen throw new IllegalArgumentException("Unexpected token " + token); } } - if (Assertions.ENABLED && Version.indexCreated(builder.settings).onOrAfter(LegacyESVersion.V_6_5_0)) { - assert mappingVersion : "mapping version should be present for indices created on or after 6.5.0"; + if (Assertions.ENABLED) { + assert mappingVersion : "mapping version should be present for indices"; } - if (Assertions.ENABLED && Version.indexCreated(builder.settings).onOrAfter(LegacyESVersion.V_6_5_0)) { - assert settingsVersion : "settings version should be present for indices created on or after 6.5.0"; + if (Assertions.ENABLED) { + assert settingsVersion : "settings version should be present for indices"; } if (Assertions.ENABLED && Version.indexCreated(builder.settings).onOrAfter(LegacyESVersion.V_7_2_0)) { assert aliasesVersion : "aliases version should be present for indices created on or after 7.2.0"; diff --git a/server/src/main/java/org/opensearch/cluster/metadata/IndexTemplateMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/IndexTemplateMetadata.java index d5c737c47f4..7cf3c3da24c 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/IndexTemplateMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/IndexTemplateMetadata.java @@ -33,7 +33,6 @@ package org.opensearch.cluster.metadata; import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; -import org.opensearch.LegacyESVersion; import org.opensearch.OpenSearchParseException; import org.opensearch.cluster.AbstractDiffable; import org.opensearch.cluster.Diff; @@ -224,14 +223,6 @@ public class IndexTemplateMetadata extends AbstractDiffable 0) { - throw new IllegalStateException("unexpected custom metadata when none is supported"); - } - } builder.version(in.readOptionalVInt()); return builder.build(); } @@ -255,9 +246,6 @@ public class IndexTemplateMetadata extends AbstractDiffable cursor : aliases.values()) { cursor.value.writeTo(out); } - if (out.getVersion().before(LegacyESVersion.V_6_5_0)) { - out.writeVInt(0); - } out.writeOptionalVInt(version); } diff --git a/server/src/main/java/org/opensearch/index/IndexService.java b/server/src/main/java/org/opensearch/index/IndexService.java index f6b31b01bc6..a14afde7eba 100644 --- a/server/src/main/java/org/opensearch/index/IndexService.java +++ b/server/src/main/java/org/opensearch/index/IndexService.java @@ -41,7 +41,6 @@ import org.apache.lucene.store.AlreadyClosedException; import org.apache.lucene.store.Directory; import org.apache.lucene.util.Accountable; import org.opensearch.Assertions; -import org.opensearch.LegacyESVersion; import org.opensearch.client.Client; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; @@ -793,9 +792,7 @@ public class IndexService extends AbstractIndexComponent implements IndicesClust public synchronized void updateMetadata(final IndexMetadata currentIndexMetadata, final IndexMetadata newIndexMetadata) { final boolean updateIndexSettings = indexSettings.updateIndexMetadata(newIndexMetadata); - if (Assertions.ENABLED - && currentIndexMetadata != null - && currentIndexMetadata.getCreationVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { + if (Assertions.ENABLED && currentIndexMetadata != null) { final long currentSettingsVersion = currentIndexMetadata.getSettingsVersion(); final long newSettingsVersion = newIndexMetadata.getSettingsVersion(); if (currentSettingsVersion == newSettingsVersion) { diff --git a/server/src/main/java/org/opensearch/index/IndexSettings.java b/server/src/main/java/org/opensearch/index/IndexSettings.java index 6006002b38f..8da77ab1d00 100644 --- a/server/src/main/java/org/opensearch/index/IndexSettings.java +++ b/server/src/main/java/org/opensearch/index/IndexSettings.java @@ -666,7 +666,7 @@ public final class IndexSettings { flushAfterMergeThresholdSize = scopedSettings.get(INDEX_FLUSH_AFTER_MERGE_THRESHOLD_SIZE_SETTING); mergeSchedulerConfig = new MergeSchedulerConfig(this); gcDeletesInMillis = scopedSettings.get(INDEX_GC_DELETES_SETTING).getMillis(); - softDeleteEnabled = version.onOrAfter(LegacyESVersion.V_6_5_0) && scopedSettings.get(INDEX_SOFT_DELETES_SETTING); + softDeleteEnabled = scopedSettings.get(INDEX_SOFT_DELETES_SETTING); softDeleteRetentionOperations = scopedSettings.get(INDEX_SOFT_DELETES_RETENTION_OPERATIONS_SETTING); retentionLeaseMillis = scopedSettings.get(INDEX_SOFT_DELETES_RETENTION_LEASE_PERIOD_SETTING).millis(); warmerEnabled = scopedSettings.get(INDEX_WARMER_ENABLED_SETTING); diff --git a/server/src/main/java/org/opensearch/index/mapper/MapperService.java b/server/src/main/java/org/opensearch/index/mapper/MapperService.java index 139f33a1c86..765f5dc2d2f 100644 --- a/server/src/main/java/org/opensearch/index/mapper/MapperService.java +++ b/server/src/main/java/org/opensearch/index/mapper/MapperService.java @@ -346,9 +346,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable { final IndexMetadata newIndexMetadata, final Map updatedEntries ) throws IOException { - if (Assertions.ENABLED - && currentIndexMetadata != null - && currentIndexMetadata.getCreationVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { + if (Assertions.ENABLED && currentIndexMetadata != null) { if (currentIndexMetadata.getMappingVersion() == newIndexMetadata.getMappingVersion()) { // if the mapping version is unchanged, then there should not be any updates and all mappings should be the same assert updatedEntries.isEmpty() : updatedEntries; diff --git a/server/src/main/java/org/opensearch/index/mapper/ParseContext.java b/server/src/main/java/org/opensearch/index/mapper/ParseContext.java index b512c0fd0c2..50295626393 100644 --- a/server/src/main/java/org/opensearch/index/mapper/ParseContext.java +++ b/server/src/main/java/org/opensearch/index/mapper/ParseContext.java @@ -37,7 +37,6 @@ import com.carrotsearch.hppc.ObjectObjectMap; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexableField; import org.apache.lucene.util.BytesRef; -import org.opensearch.LegacyESVersion; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.index.IndexSettings; @@ -466,18 +465,10 @@ public abstract class ParseContext implements Iterable { void postParse() { if (documents.size() > 1) { docsReversed = true; - if (indexSettings.getIndexVersionCreated().onOrAfter(LegacyESVersion.V_6_5_0)) { - /** - * For indices created on or after {@link LegacyESVersion#V_6_5_0} we preserve the order - * of the children while ensuring that parents appear after them. - */ - List newDocs = reorderParent(documents); - documents.clear(); - documents.addAll(newDocs); - } else { - // reverse the order of docs for nested docs support, parent should be last - Collections.reverse(documents); - } + // Preserve the order of the children while ensuring that parents appear after them. + List newDocs = reorderParent(documents); + documents.clear(); + documents.addAll(newDocs); } } diff --git a/server/src/main/java/org/opensearch/index/similarity/SimilarityService.java b/server/src/main/java/org/opensearch/index/similarity/SimilarityService.java index 14c815e81cd..a183457ffbc 100644 --- a/server/src/main/java/org/opensearch/index/similarity/SimilarityService.java +++ b/server/src/main/java/org/opensearch/index/similarity/SimilarityService.java @@ -333,7 +333,7 @@ public final class SimilarityService extends AbstractIndexComponent { private static void fail(Version indexCreatedVersion, String message) { if (indexCreatedVersion.onOrAfter(LegacyESVersion.V_7_0_0)) { throw new IllegalArgumentException(message); - } else if (indexCreatedVersion.onOrAfter(LegacyESVersion.V_6_5_0)) { + } else { deprecationLogger.deprecate("similarity_failure", message); } } diff --git a/server/src/main/java/org/opensearch/indices/recovery/RecoveryTranslogOperationsRequest.java b/server/src/main/java/org/opensearch/indices/recovery/RecoveryTranslogOperationsRequest.java index 622d698e7bd..7e365e1bdf2 100644 --- a/server/src/main/java/org/opensearch/indices/recovery/RecoveryTranslogOperationsRequest.java +++ b/server/src/main/java/org/opensearch/indices/recovery/RecoveryTranslogOperationsRequest.java @@ -33,11 +33,9 @@ package org.opensearch.indices.recovery; import org.opensearch.LegacyESVersion; -import org.opensearch.action.index.IndexRequest; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.index.seqno.RetentionLeases; -import org.opensearch.index.seqno.SequenceNumbers; import org.opensearch.index.shard.ShardId; import org.opensearch.index.translog.Translog; @@ -120,17 +118,8 @@ public class RecoveryTranslogOperationsRequest extends RecoveryTransportRequest shardId = new ShardId(in); operations = Translog.readOperations(in, "recovery"); totalTranslogOps = in.readVInt(); - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - maxSeenAutoIdTimestampOnPrimary = in.readZLong(); - } else { - maxSeenAutoIdTimestampOnPrimary = IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP; - } - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - maxSeqNoOfUpdatesOrDeletesOnPrimary = in.readZLong(); - } else { - // UNASSIGNED_SEQ_NO means uninitialized and replica won't enable optimization using seq_no - maxSeqNoOfUpdatesOrDeletesOnPrimary = SequenceNumbers.UNASSIGNED_SEQ_NO; - } + maxSeenAutoIdTimestampOnPrimary = in.readZLong(); + maxSeqNoOfUpdatesOrDeletesOnPrimary = in.readZLong(); if (in.getVersion().onOrAfter(LegacyESVersion.V_6_7_0)) { retentionLeases = new RetentionLeases(in); } else { @@ -150,12 +139,8 @@ public class RecoveryTranslogOperationsRequest extends RecoveryTransportRequest shardId.writeTo(out); Translog.writeOperations(out, operations); out.writeVInt(totalTranslogOps); - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - out.writeZLong(maxSeenAutoIdTimestampOnPrimary); - } - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - out.writeZLong(maxSeqNoOfUpdatesOrDeletesOnPrimary); - } + out.writeZLong(maxSeenAutoIdTimestampOnPrimary); + out.writeZLong(maxSeqNoOfUpdatesOrDeletesOnPrimary); if (out.getVersion().onOrAfter(LegacyESVersion.V_6_7_0)) { retentionLeases.writeTo(out); } diff --git a/server/src/main/java/org/opensearch/ingest/IngestStats.java b/server/src/main/java/org/opensearch/ingest/IngestStats.java index df8740b0df4..c1b08cb7e62 100644 --- a/server/src/main/java/org/opensearch/ingest/IngestStats.java +++ b/server/src/main/java/org/opensearch/ingest/IngestStats.java @@ -78,20 +78,18 @@ public class IngestStats implements Writeable, ToXContentFragment { String pipelineId = in.readString(); Stats pipelineStat = new Stats(in); this.pipelineStats.add(new PipelineStat(pipelineId, pipelineStat)); - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - int processorsSize = in.readVInt(); - List processorStatsPerPipeline = new ArrayList<>(processorsSize); - for (int j = 0; j < processorsSize; j++) { - String processorName = in.readString(); - String processorType = "_NOT_AVAILABLE"; - if (in.getVersion().onOrAfter(LegacyESVersion.V_7_6_0)) { - processorType = in.readString(); - } - Stats processorStat = new Stats(in); - processorStatsPerPipeline.add(new ProcessorStat(processorName, processorType, processorStat)); + int processorsSize = in.readVInt(); + List processorStatsPerPipeline = new ArrayList<>(processorsSize); + for (int j = 0; j < processorsSize; j++) { + String processorName = in.readString(); + String processorType = "_NOT_AVAILABLE"; + if (in.getVersion().onOrAfter(LegacyESVersion.V_7_6_0)) { + processorType = in.readString(); } - this.processorStats.put(pipelineId, processorStatsPerPipeline); + Stats processorStat = new Stats(in); + processorStatsPerPipeline.add(new ProcessorStat(processorName, processorType, processorStat)); } + this.processorStats.put(pipelineId, processorStatsPerPipeline); } } @@ -102,19 +100,17 @@ public class IngestStats implements Writeable, ToXContentFragment { for (PipelineStat pipelineStat : pipelineStats) { out.writeString(pipelineStat.getPipelineId()); pipelineStat.getStats().writeTo(out); - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - List processorStatsForPipeline = processorStats.get(pipelineStat.getPipelineId()); - if (processorStatsForPipeline == null) { - out.writeVInt(0); - } else { - out.writeVInt(processorStatsForPipeline.size()); - for (ProcessorStat processorStat : processorStatsForPipeline) { - out.writeString(processorStat.getName()); - if (out.getVersion().onOrAfter(LegacyESVersion.V_7_6_0)) { - out.writeString(processorStat.getType()); - } - processorStat.getStats().writeTo(out); + List processorStatsForPipeline = processorStats.get(pipelineStat.getPipelineId()); + if (processorStatsForPipeline == null) { + out.writeVInt(0); + } else { + out.writeVInt(processorStatsForPipeline.size()); + for (ProcessorStat processorStat : processorStatsForPipeline) { + out.writeString(processorStat.getName()); + if (out.getVersion().onOrAfter(LegacyESVersion.V_7_6_0)) { + out.writeString(processorStat.getType()); } + processorStat.getStats().writeTo(out); } } } diff --git a/server/src/main/java/org/opensearch/search/fetch/FetchPhase.java b/server/src/main/java/org/opensearch/search/fetch/FetchPhase.java index 22aa8677aab..e1537b6aa19 100644 --- a/server/src/main/java/org/opensearch/search/fetch/FetchPhase.java +++ b/server/src/main/java/org/opensearch/search/fetch/FetchPhase.java @@ -43,7 +43,6 @@ import org.apache.lucene.search.Scorer; import org.apache.lucene.search.TotalHits; import org.apache.lucene.search.Weight; import org.apache.lucene.util.BitSet; -import org.opensearch.LegacyESVersion; import org.opensearch.common.CheckedBiConsumer; import org.opensearch.common.collect.Tuple; import org.opensearch.common.document.DocumentField; @@ -531,32 +530,20 @@ public class FetchPhase { BitSet parentBits = context.bitsetFilterCache().getBitSetProducer(parentFilter).getBitSet(subReaderContext); int offset = 0; - if (indexSettings.getIndexVersionCreated().onOrAfter(LegacyESVersion.V_6_5_0)) { - /** - * Starts from the previous parent and finds the offset of the - * nestedSubDocID within the nested children. Nested documents - * are indexed in the same order than in the source array so the offset - * of the nested child is the number of nested document with the same parent - * that appear before him. - */ - int previousParent = parentBits.prevSetBit(currentParent); - for (int docId = childIter.advance(previousParent + 1); docId < nestedSubDocId - && docId != DocIdSetIterator.NO_MORE_DOCS; docId = childIter.nextDoc()) { - offset++; - } - currentParent = nestedSubDocId; - } else { - /** - * Nested documents are in reverse order in this version so we start from the current nested document - * and find the number of documents with the same parent that appear after it. - */ - int nextParent = parentBits.nextSetBit(currentParent); - for (int docId = childIter.advance(currentParent + 1); docId < nextParent && docId != DocIdSetIterator.NO_MORE_DOCS; docId = - childIter.nextDoc()) { - offset++; - } - currentParent = nextParent; + + /* + * Starts from the previous parent and finds the offset of the + * nestedSubDocID within the nested children. Nested documents + * are indexed in the same order than in the source array so the offset + * of the nested child is the number of nested document with the same parent + * that appear before him. + */ + int previousParent = parentBits.prevSetBit(currentParent); + for (int docId = childIter.advance(previousParent + 1); docId < nestedSubDocId + && docId != DocIdSetIterator.NO_MORE_DOCS; docId = childIter.nextDoc()) { + offset++; } + currentParent = nestedSubDocId; current = nestedObjectMapper = nestedParentObjectMapper; int currentPrefix = current == null ? 0 : current.name().length() + 1; nestedIdentity = new SearchHit.NestedIdentity(originalName.substring(currentPrefix), offset, nestedIdentity); diff --git a/server/src/main/java/org/opensearch/search/sort/FieldSortBuilder.java b/server/src/main/java/org/opensearch/search/sort/FieldSortBuilder.java index ab0848e8324..17d778eb358 100644 --- a/server/src/main/java/org/opensearch/search/sort/FieldSortBuilder.java +++ b/server/src/main/java/org/opensearch/search/sort/FieldSortBuilder.java @@ -579,9 +579,6 @@ public class FieldSortBuilder extends SortBuilder { if (nestedSort == null) { return resolveNested(context, nestedPath, nestedFilter); } - if (context.indexVersionCreated().before(LegacyESVersion.V_6_5_0) && nestedSort.getMaxChildren() != Integer.MAX_VALUE) { - throw new QueryShardException(context, "max_children is only supported on v6.5.0 or higher"); - } validateMaxChildrenExistOnlyInTopLevelNestedSort(context, nestedSort); return resolveNested(context, nestedSort); } 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 1a53f288b7a..2dd3481cc80 100644 --- a/server/src/main/java/org/opensearch/search/sort/GeoDistanceSortBuilder.java +++ b/server/src/main/java/org/opensearch/search/sort/GeoDistanceSortBuilder.java @@ -41,7 +41,6 @@ import org.apache.lucene.search.LeafFieldComparator; import org.apache.lucene.search.SortField; import org.apache.lucene.search.comparators.DoubleComparator; import org.apache.lucene.util.BitSet; -import org.opensearch.LegacyESVersion; import org.opensearch.OpenSearchParseException; import org.opensearch.common.ParseField; import org.opensearch.common.ParsingException; @@ -69,7 +68,6 @@ import org.opensearch.index.query.GeoValidationMethod; import org.opensearch.index.query.QueryBuilder; import org.opensearch.index.query.QueryRewriteContext; import org.opensearch.index.query.QueryShardContext; -import org.opensearch.index.query.QueryShardException; import org.opensearch.search.DocValueFormat; import org.opensearch.search.MultiValueMode; @@ -696,9 +694,6 @@ public class GeoDistanceSortBuilder extends SortBuilder if (nestedSort == null) { return resolveNested(context, nestedPath, nestedFilter); } - if (context.indexVersionCreated().before(LegacyESVersion.V_6_5_0) && nestedSort.getMaxChildren() != Integer.MAX_VALUE) { - throw new QueryShardException(context, "max_children is only supported on v6.5.0 or higher"); - } validateMaxChildrenExistOnlyInTopLevelNestedSort(context, nestedSort); return resolveNested(context, nestedSort); } diff --git a/server/src/main/java/org/opensearch/search/sort/NestedSortBuilder.java b/server/src/main/java/org/opensearch/search/sort/NestedSortBuilder.java index 4bf0d90cd88..2463cb92949 100644 --- a/server/src/main/java/org/opensearch/search/sort/NestedSortBuilder.java +++ b/server/src/main/java/org/opensearch/search/sort/NestedSortBuilder.java @@ -32,7 +32,6 @@ package org.opensearch.search.sort; -import org.opensearch.LegacyESVersion; import org.opensearch.common.ParseField; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; @@ -67,11 +66,7 @@ public class NestedSortBuilder implements Writeable, ToXContentObject { path = in.readOptionalString(); filter = in.readOptionalNamedWriteable(QueryBuilder.class); nestedSort = in.readOptionalWriteable(NestedSortBuilder::new); - if (in.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - maxChildren = in.readVInt(); - } else { - maxChildren = Integer.MAX_VALUE; - } + maxChildren = in.readVInt(); } public String getPath() { @@ -113,9 +108,7 @@ public class NestedSortBuilder implements Writeable, ToXContentObject { out.writeOptionalString(path); out.writeOptionalNamedWriteable(filter); out.writeOptionalWriteable(nestedSort); - if (out.getVersion().onOrAfter(LegacyESVersion.V_6_5_0)) { - out.writeVInt(maxChildren); - } + out.writeVInt(maxChildren); } @Override diff --git a/server/src/main/java/org/opensearch/search/sort/ScriptSortBuilder.java b/server/src/main/java/org/opensearch/search/sort/ScriptSortBuilder.java index 136d60598e7..55a3f380b0e 100644 --- a/server/src/main/java/org/opensearch/search/sort/ScriptSortBuilder.java +++ b/server/src/main/java/org/opensearch/search/sort/ScriptSortBuilder.java @@ -38,7 +38,6 @@ import org.apache.lucene.search.Scorable; import org.apache.lucene.search.SortField; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; -import org.opensearch.LegacyESVersion; import org.opensearch.common.ParseField; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; @@ -341,9 +340,6 @@ public class ScriptSortBuilder extends SortBuilder { final Nested nested; if (nestedSort != null) { - if (context.indexVersionCreated().before(LegacyESVersion.V_6_5_0) && nestedSort.getMaxChildren() != Integer.MAX_VALUE) { - throw new QueryShardException(context, "max_children is only supported on v6.5.0 or higher"); - } // new nested sorts takes priority validateMaxChildrenExistOnlyInTopLevelNestedSort(context, nestedSort); nested = resolveNested(context, nestedSort); diff --git a/server/src/test/java/org/opensearch/LegacyESVersionTests.java b/server/src/test/java/org/opensearch/LegacyESVersionTests.java index 673b1c9ffa9..d98ce0a9e85 100644 --- a/server/src/test/java/org/opensearch/LegacyESVersionTests.java +++ b/server/src/test/java/org/opensearch/LegacyESVersionTests.java @@ -142,7 +142,7 @@ public class LegacyESVersionTests extends OpenSearchTestCase { assertThat(LegacyESVersion.fromString("5.3.0").minimumCompatibilityVersion(), equalTo(major5x)); Version major56x = LegacyESVersion.fromString("5.6.0"); - assertThat(LegacyESVersion.V_6_5_0.minimumCompatibilityVersion(), equalTo(major56x)); + assertThat(LegacyESVersion.fromString("6.5.0").minimumCompatibilityVersion(), equalTo(major56x)); assertThat(LegacyESVersion.fromString("6.3.1").minimumCompatibilityVersion(), equalTo(major56x)); // from 7.0 on we are supporting the latest minor of the previous major... this might fail once we add a new version ie. 5.x is diff --git a/server/src/test/java/org/opensearch/index/IndexSettingsTests.java b/server/src/test/java/org/opensearch/index/IndexSettingsTests.java index f3278a9e3d5..48c3094ee4b 100644 --- a/server/src/test/java/org/opensearch/index/IndexSettingsTests.java +++ b/server/src/test/java/org/opensearch/index/IndexSettingsTests.java @@ -728,16 +728,6 @@ public class IndexSettingsTests extends OpenSearchTestCase { Settings settings = Settings.builder().put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), createdVersion).build(); assertTrue(IndexSettings.INDEX_SOFT_DELETES_SETTING.get(settings)); } - // disabled by default on the previous versions - { - Version prevVersion = VersionUtils.randomVersionBetween( - random(), - LegacyESVersion.V_6_5_0, - VersionUtils.getPreviousVersion(LegacyESVersion.V_7_0_0) - ); - Settings settings = Settings.builder().put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), prevVersion).build(); - assertFalse(IndexSettings.INDEX_SOFT_DELETES_SETTING.get(settings)); - } } public void testIgnoreTranslogRetentionSettingsIfSoftDeletesEnabled() { diff --git a/server/src/test/java/org/opensearch/index/replication/RetentionLeasesReplicationTests.java b/server/src/test/java/org/opensearch/index/replication/RetentionLeasesReplicationTests.java index c780ffa8504..abb2a7632e2 100644 --- a/server/src/test/java/org/opensearch/index/replication/RetentionLeasesReplicationTests.java +++ b/server/src/test/java/org/opensearch/index/replication/RetentionLeasesReplicationTests.java @@ -32,8 +32,6 @@ package org.opensearch.index.replication; -import org.opensearch.LegacyESVersion; -import org.opensearch.Version; import org.opensearch.action.ActionListener; import org.opensearch.action.support.PlainActionFuture; import org.opensearch.action.support.replication.ReplicationResponse; @@ -172,10 +170,7 @@ public class RetentionLeasesReplicationTests extends OpenSearchIndexLevelReplica public void testTurnOffTranslogRetentionAfterAllShardStarted() throws Exception { final Settings.Builder settings = Settings.builder().put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true); if (randomBoolean()) { - settings.put( - IndexMetadata.SETTING_VERSION_CREATED, - VersionUtils.randomVersionBetween(random(), LegacyESVersion.V_6_5_0, Version.CURRENT) - ); + settings.put(IndexMetadata.SETTING_VERSION_CREATED, VersionUtils.randomIndexCompatibleVersion(random())); } try (ReplicationGroup group = createGroup(between(1, 2), settings.build())) { group.startAll();