From e0d89e0dd365fcb6ce1ea941616fcf27a92a44bb Mon Sep 17 00:00:00 2001 From: Issam El-atif Date: Wed, 22 May 2019 15:10:00 +0200 Subject: [PATCH 1/4] remove v6.8.x version constant and the backcompat code that uses it related to refactoring initiative elastic#41164. --- .../java/org/elasticsearch/ElasticsearchException.java | 2 +- server/src/main/java/org/elasticsearch/Version.java | 8 -------- server/src/test/java/org/elasticsearch/VersionTests.java | 4 ++-- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/ElasticsearchException.java b/server/src/main/java/org/elasticsearch/ElasticsearchException.java index 260b443a6a557..51662414e0d07 100644 --- a/server/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/server/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -1027,7 +1027,7 @@ private enum ElasticsearchExceptionHandle { org.elasticsearch.index.shard.ShardNotInPrimaryModeException.class, org.elasticsearch.index.shard.ShardNotInPrimaryModeException::new, 155, - Version.V_6_8_1); + UNKNOWN_VERSION_ADDED); final Class exceptionClass; final CheckedFunction constructor; diff --git a/server/src/main/java/org/elasticsearch/Version.java b/server/src/main/java/org/elasticsearch/Version.java index 844b963e9aa83..3d077af6e9c6e 100644 --- a/server/src/main/java/org/elasticsearch/Version.java +++ b/server/src/main/java/org/elasticsearch/Version.java @@ -62,10 +62,6 @@ public class Version implements Comparable, ToXContentFragment { public static final Version V_6_6_1 = new Version(V_6_6_1_ID, org.apache.lucene.util.Version.LUCENE_7_6_0); public static final int V_6_6_2_ID = 6060299; public static final Version V_6_6_2 = new Version(V_6_6_2_ID, org.apache.lucene.util.Version.LUCENE_7_6_0); - public static final int V_6_8_0_ID = 6080099; - public static final Version V_6_8_0 = new Version(V_6_8_0_ID, org.apache.lucene.util.Version.LUCENE_7_7_0); - public static final int V_6_8_1_ID = 6080199; - public static final Version V_6_8_1 = new Version(V_6_8_1_ID, org.apache.lucene.util.Version.LUCENE_7_7_0); public static final int V_7_0_0_ID = 7000099; public static final Version V_7_0_0 = new Version(V_7_0_0_ID, org.apache.lucene.util.Version.LUCENE_8_0_0); public static final int V_7_0_1_ID = 7000199; @@ -112,10 +108,6 @@ public static Version fromId(int id) { return V_7_0_1; case V_7_0_0_ID: return V_7_0_0; - case V_6_8_1_ID: - return V_6_8_1; - case V_6_8_0_ID: - return V_6_8_0; case V_6_6_2_ID: return V_6_6_2; case V_6_6_1_ID: diff --git a/server/src/test/java/org/elasticsearch/VersionTests.java b/server/src/test/java/org/elasticsearch/VersionTests.java index e5149b9bce515..9f05c6a4cdece 100644 --- a/server/src/test/java/org/elasticsearch/VersionTests.java +++ b/server/src/test/java/org/elasticsearch/VersionTests.java @@ -186,7 +186,7 @@ public void testMinCompatVersion() { // 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 // released since we need to bump the supported minor in Version#minimumCompatibilityVersion() - Version lastVersion = Version.V_6_8_0; // TODO: remove this once min compat version is a constant instead of method + Version lastVersion = Version.fromString("6.8.0"); // TODO: remove this once min compat version is a constant instead of method assertEquals(lastVersion.major, Version.V_7_0_0.minimumCompatibilityVersion().major); assertEquals("did you miss to bump the minor in Version#minimumCompatibilityVersion()", lastVersion.minor, Version.V_7_0_0.minimumCompatibilityVersion().minor); @@ -346,7 +346,7 @@ public static void assertUnknownVersion(Version version) { public void testIsCompatible() { assertTrue(isCompatible(Version.CURRENT, Version.CURRENT.minimumCompatibilityVersion())); assertFalse(isCompatible(Version.V_6_6_0, Version.V_7_0_0)); - assertTrue(isCompatible(Version.V_6_8_0, Version.V_7_0_0)); + assertTrue(isCompatible(Version.fromId(6080099), Version.V_7_0_0)); assertFalse(isCompatible(Version.fromId(2000099), Version.V_7_0_0)); assertFalse(isCompatible(Version.fromId(2000099), Version.V_6_5_0)); From a06a9229ab4bb41e7460181cd7397395650f7671 Mon Sep 17 00:00:00 2001 From: Issam El-atif Date: Thu, 23 May 2019 00:22:02 +0200 Subject: [PATCH 2/4] Fix tests --- server/src/main/java/org/elasticsearch/Version.java | 7 +++++-- server/src/test/java/org/elasticsearch/VersionTests.java | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/Version.java b/server/src/main/java/org/elasticsearch/Version.java index 3d077af6e9c6e..0905978474184 100644 --- a/server/src/main/java/org/elasticsearch/Version.java +++ b/server/src/main/java/org/elasticsearch/Version.java @@ -307,8 +307,11 @@ public Version minimumCompatibilityVersion() { if (major == 6) { // force the minimum compatibility for version 6 to 5.6 since we don't reference version 5 anymore return Version.fromId(5060099); - } else if (major >= 7) { - // all major versions from 7 onwards are compatible with last minor series of the previous major + } else if (major == 7) { + // force the minimum compatibility for version 7 to 6.8 since we don't reference version 6 anymore + return Version.fromId(6080099); + } else if (major >= 8) { + // all major versions from 8 onwards are compatible with last minor series of the previous major Version bwcVersion = null; for (int i = DeclaredVersionsHolder.DECLARED_VERSIONS.size() - 1; i >= 0; i--) { diff --git a/server/src/test/java/org/elasticsearch/VersionTests.java b/server/src/test/java/org/elasticsearch/VersionTests.java index 9f05c6a4cdece..7b52d6aeb9a2a 100644 --- a/server/src/test/java/org/elasticsearch/VersionTests.java +++ b/server/src/test/java/org/elasticsearch/VersionTests.java @@ -345,7 +345,7 @@ public static void assertUnknownVersion(Version version) { public void testIsCompatible() { assertTrue(isCompatible(Version.CURRENT, Version.CURRENT.minimumCompatibilityVersion())); - assertFalse(isCompatible(Version.V_6_6_0, Version.V_7_0_0)); + assertFalse(isCompatible(Version.V_7_0_0, Version.V_8_0_0)); assertTrue(isCompatible(Version.fromId(6080099), Version.V_7_0_0)); assertFalse(isCompatible(Version.fromId(2000099), Version.V_7_0_0)); assertFalse(isCompatible(Version.fromId(2000099), Version.V_6_5_0)); From f94cef5ff8b02c8710f129a2ae54b5e63c6a2b7d Mon Sep 17 00:00:00 2001 From: Issam El-atif Date: Fri, 31 May 2019 15:32:09 +0200 Subject: [PATCH 3/4] Remove test for lastest V6 since 'calculateNumRoutingShards' no longer needs version logic --- .../cluster/metadata/MetaDataCreateIndexServiceTests.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java index 3de716acfee44..cda92d3953ea3 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java @@ -433,12 +433,6 @@ public void testCalculateNumRoutingShards() { assertEquals(2048, MetaDataCreateIndexService.calculateNumRoutingShards(1024, Version.CURRENT)); assertEquals(4096, MetaDataCreateIndexService.calculateNumRoutingShards(2048, Version.CURRENT)); - Version latestV6 = VersionUtils.getPreviousVersion(Version.V_7_0_0); - int numShards = randomIntBetween(1, 1000); - assertEquals(numShards, MetaDataCreateIndexService.calculateNumRoutingShards(numShards, latestV6)); - assertEquals(numShards, MetaDataCreateIndexService.calculateNumRoutingShards(numShards, - VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), latestV6))); - for (int i = 0; i < 1000; i++) { int randomNumShards = randomIntBetween(1, 10000); int numRoutingShards = MetaDataCreateIndexService.calculateNumRoutingShards(randomNumShards, Version.CURRENT); From 2ebcdad7205ebb15e3ef09fbc5c932e251a59cac Mon Sep 17 00:00:00 2001 From: Issam El-atif Date: Fri, 31 May 2019 20:41:57 +0200 Subject: [PATCH 4/4] Fix tests --- .../coordination/JoinTaskExecutorTests.java | 3 +-- .../xpack/security/SecurityTests.java | 23 ------------------- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/JoinTaskExecutorTests.java b/server/src/test/java/org/elasticsearch/cluster/coordination/JoinTaskExecutorTests.java index b8168ce3de4a7..0225ffe8fe6cd 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/JoinTaskExecutorTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/JoinTaskExecutorTests.java @@ -54,8 +54,7 @@ public void testPreventJoinClusterWithUnsupportedIndices() { Settings.builder().build(); MetaData.Builder metaBuilder = MetaData.builder(); IndexMetaData indexMetaData = IndexMetaData.builder("test") - .settings(settings(VersionUtils.getPreviousVersion(Version.CURRENT - .minimumIndexCompatibilityVersion()))) + .settings(settings(Version.fromString("6.8.0"))) // latest V6 released version .numberOfShards(1) .numberOfReplicas(1).build(); metaBuilder.put(indexMetaData, false); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityTests.java index 768bc38813c0b..47c686e0c87a2 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityTests.java @@ -318,29 +318,6 @@ public void testJoinValidatorForFIPSLicense() throws Exception { } } - public void testIndexJoinValidator_Old_And_Rolling() throws Exception { - createComponents(Settings.EMPTY); - BiConsumer joinValidator = security.getJoinValidator(); - assertNotNull(joinValidator); - Version version = VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), - VersionUtils.getPreviousVersion(Version.V_7_0_0)); - DiscoveryNode node = new DiscoveryNode("foo", buildNewFakeTransportAddress(), Version.CURRENT); - IndexMetaData indexMetaData = IndexMetaData.builder(SECURITY_MAIN_ALIAS) - .settings(settings(version) - .put(INDEX_FORMAT_SETTING.getKey(), INTERNAL_MAIN_INDEX_FORMAT - 1)) - .numberOfShards(1).numberOfReplicas(0) - .build(); - DiscoveryNode existingOtherNode = new DiscoveryNode("bar", buildNewFakeTransportAddress(), version); - DiscoveryNodes discoveryNodes = DiscoveryNodes.builder().add(existingOtherNode).build(); - ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) - .nodes(discoveryNodes) - .metaData(MetaData.builder().put(indexMetaData, true).build()).build(); - IllegalStateException e = expectThrows(IllegalStateException.class, - () -> joinValidator.accept(node, clusterState)); - assertThat(e.getMessage(), equalTo("Security index is not on the current version [6] - " + - "The Upgrade API must be run for 7.x nodes to join the cluster")); - } - public void testIndexJoinValidator_FullyCurrentCluster() throws Exception { createComponents(Settings.EMPTY); BiConsumer joinValidator = security.getJoinValidator();