diff --git a/server/src/main/java/org/elasticsearch/indices/IndicesService.java b/server/src/main/java/org/elasticsearch/indices/IndicesService.java index 4682cd4dff421..32cbc4f70212b 100644 --- a/server/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/server/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -83,6 +83,7 @@ import org.elasticsearch.index.analysis.AnalysisRegistry; import org.elasticsearch.index.cache.request.ShardRequestCache; import org.elasticsearch.index.engine.CommitStats; +import org.elasticsearch.index.engine.EngineConfig; import org.elasticsearch.index.engine.EngineFactory; import org.elasticsearch.index.engine.InternalEngineFactory; import org.elasticsearch.index.fielddata.IndexFieldDataCache; @@ -493,6 +494,11 @@ private synchronized IndexService createIndexService(final String reason, List builtInListeners, IndexingOperationListener... indexingOperationListeners) throws IOException { final IndexSettings idxSettings = new IndexSettings(indexMetaData, settings, indexScopedSettings); + if (idxSettings.getIndexVersionCreated().onOrAfter(Version.V_7_0_0) + && EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS.exists(idxSettings.getSettings())) { + throw new IllegalArgumentException( + "Setting [" + EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS.getKey() + "] was removed in version 7.0.0"); + } // we ignore private settings since they are not registered settings indexScopedSettings.validate(indexMetaData.getSettings(), true, true, true); logger.debug("creating Index [{}], shards [{}]/[{}] - reason [{}]", diff --git a/server/src/test/java/org/elasticsearch/indices/IndicesServiceTests.java b/server/src/test/java/org/elasticsearch/indices/IndicesServiceTests.java index 60dbad99795f3..aa38f9782f006 100644 --- a/server/src/test/java/org/elasticsearch/indices/IndicesServiceTests.java +++ b/server/src/test/java/org/elasticsearch/indices/IndicesServiceTests.java @@ -642,5 +642,48 @@ public static ClusterState createClusterForShardLimitTest(int nodesInCluster, in .build(); } + public void testOptimizeAutoGeneratedIdsSettingRemoval() throws Exception { + final IndicesService indicesService = getIndicesService(); + + final Index index = new Index("foo-index", UUIDs.randomBase64UUID()); + Settings.Builder builder = Settings.builder() + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_7_0_0) + .put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID()); + IndexMetaData indexMetaData = new IndexMetaData.Builder(index.getName()) + .settings(builder.build()) + .numberOfShards(1) + .numberOfReplicas(0) + .build(); + IndexService indexService = indicesService.createIndex(indexMetaData, Collections.emptyList()); + assertNotNull(indexService); + + final Index index2 = new Index("bar-index", UUIDs.randomBase64UUID()); + Settings.Builder builder2 = Settings.builder() + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_7_0_0) + .put(IndexMetaData.SETTING_INDEX_UUID, index2.getUUID()) + .put(EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS.getKey(), randomBoolean()); + IndexMetaData indexMetaData2 = new IndexMetaData.Builder(index2.getName()) + .settings(builder2.build()) + .numberOfShards(1) + .numberOfReplicas(0) + .build(); + IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, + () -> indicesService.createIndex(indexMetaData2, Collections.emptyList())); + assertEquals("Setting [" + EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS.getKey() + "] was removed in version 7.0.0", + ex.getMessage()); + + Version version = randomFrom(Version.V_6_0_0_rc1, Version.V_6_0_0, Version.V_6_2_0, Version.V_6_3_0, Version.V_6_4_0); + builder = Settings.builder() + .put(IndexMetaData.SETTING_VERSION_CREATED, version) + .put(IndexMetaData.SETTING_INDEX_UUID, index2.getUUID()) + .put(EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS.getKey(), randomBoolean()); + IndexMetaData indexMetaData3 = new IndexMetaData.Builder(index2.getName()) + .settings(builder.build()) + .numberOfShards(1) + .numberOfReplicas(0) + .build(); + IndexService indexService2 = indicesService.createIndex(indexMetaData3, Collections.emptyList()); + assertNotNull(indexService2); + } }