From b330f0f733fd24ed7a08b502097b7cb9be55a989 Mon Sep 17 00:00:00 2001 From: liketic Date: Thu, 1 Mar 2018 17:09:06 +0800 Subject: [PATCH 1/3] Deprecate setting index.optimize_auto_generated_id (#27583) --- .../index/engine/EngineConfig.java | 11 +++ .../index/engine/EngineConfigTests.java | 69 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 server/src/test/java/org/elasticsearch/index/engine/EngineConfigTests.java diff --git a/server/src/main/java/org/elasticsearch/index/engine/EngineConfig.java b/server/src/main/java/org/elasticsearch/index/engine/EngineConfig.java index 30743c18cfe10..1488a6624190c 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/EngineConfig.java +++ b/server/src/main/java/org/elasticsearch/index/engine/EngineConfig.java @@ -26,7 +26,10 @@ import org.apache.lucene.search.ReferenceManager; import org.apache.lucene.search.Sort; import org.apache.lucene.search.similarities.Similarity; +import org.elasticsearch.Version; import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.logging.DeprecationLogger; +import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.unit.ByteSizeUnit; @@ -52,6 +55,8 @@ * object will affect the {@link Engine} instance. */ public final class EngineConfig { + private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(EngineConfig.class)); + private final ShardId shardId; private final String allocationId; private final IndexSettings indexSettings; @@ -109,6 +114,7 @@ public final class EngineConfig { * this setting won't be reflected re-enabled optimization until the engine is restarted or the index is closed and reopened. * The default is true */ + @Deprecated public static final Setting INDEX_OPTIMIZE_AUTO_GENERATED_IDS = Setting.boolSetting("index.optimize_auto_generated_id", true, Property.IndexScope, Property.Dynamic); @@ -131,6 +137,11 @@ public EngineConfig(OpenMode openMode, ShardId shardId, String allocationId, Thr if (openMode == null) { throw new IllegalArgumentException("openMode must not be null"); } + if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_6_0_0_rc1) + && INDEX_OPTIMIZE_AUTO_GENERATED_IDS.exists(indexSettings.getSettings())) { + DEPRECATION_LOGGER.deprecated( + "Setting [" + INDEX_OPTIMIZE_AUTO_GENERATED_IDS.getKey() + "] has been deprecated in favor of the auto-ID optimization"); + } this.shardId = shardId; this.allocationId = allocationId; this.indexSettings = indexSettings; diff --git a/server/src/test/java/org/elasticsearch/index/engine/EngineConfigTests.java b/server/src/test/java/org/elasticsearch/index/engine/EngineConfigTests.java new file mode 100644 index 0000000000000..457b17db7119d --- /dev/null +++ b/server/src/test/java/org/elasticsearch/index/engine/EngineConfigTests.java @@ -0,0 +1,69 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.index.engine; + +import org.elasticsearch.Version; +import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.IndexSettingsModule; + + +public class EngineConfigTests extends ESTestCase { + + + private EngineConfig createEngineConfigWithSettings(IndexSettings indexSettings) { + return new EngineConfig(EngineConfig.OpenMode.OPEN_INDEX_AND_TRANSLOG, null, null, null, + indexSettings, null, null, null, null, + null, null, null, null, null, + true, null, null, null, null, null, + null, null, null); + } + + public void testOptimizeAutoGeneratedIdsSettingDeprecation() throws Exception { + Version version = randomFrom(Version.V_6_0_0_rc1, Version.V_6_0_0, Version.V_6_2_0, Version.V_6_3_0); + boolean optimizeAutoGeneratedIds = randomBoolean(); + Settings.Builder builder = Settings.builder() + .put(IndexMetaData.SETTING_VERSION_CREATED, version) + .put(EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS.getKey(), optimizeAutoGeneratedIds); + IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("index1", builder.build()); + + EngineConfig config = createEngineConfigWithSettings(indexSettings); + assertWarnings("Setting [" + EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS.getKey() + + "] has been deprecated in favor of the auto-ID optimization"); + assertEquals(optimizeAutoGeneratedIds, config.isAutoGeneratedIDsOptimizationEnabled()); + + version = randomFrom(Version.V_5_0_0, Version.V_5_0_0_alpha1, Version.V_5_6_9); + optimizeAutoGeneratedIds = randomBoolean(); + builder = Settings.builder() + .put(IndexMetaData.SETTING_VERSION_CREATED, version) + .put(EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS.getKey(), optimizeAutoGeneratedIds); + indexSettings = IndexSettingsModule.newIndexSettings("index2", builder.build()); + config = createEngineConfigWithSettings(indexSettings); + assertEquals(optimizeAutoGeneratedIds, config.isAutoGeneratedIDsOptimizationEnabled()); + + version = randomFrom(Version.V_6_0_0_rc1, Version.V_6_0_0, Version.V_6_2_0, Version.V_6_3_0); + builder = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version); + indexSettings = IndexSettingsModule.newIndexSettings("index3", builder.build()); + config = createEngineConfigWithSettings(indexSettings); + assertTrue(config.isAutoGeneratedIDsOptimizationEnabled()); + } + +} From d155b59687495ed98d158a560a0df0299cd627b4 Mon Sep 17 00:00:00 2001 From: liketic Date: Fri, 25 May 2018 20:57:28 +0800 Subject: [PATCH 2/3] Resolve comments --- .../index/engine/EngineConfig.java | 13 +------ .../index/engine/EngineConfigTests.java | 38 +++++-------------- 2 files changed, 10 insertions(+), 41 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/engine/EngineConfig.java b/server/src/main/java/org/elasticsearch/index/engine/EngineConfig.java index 1488a6624190c..5b3ba9ee623fc 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/EngineConfig.java +++ b/server/src/main/java/org/elasticsearch/index/engine/EngineConfig.java @@ -26,10 +26,7 @@ import org.apache.lucene.search.ReferenceManager; import org.apache.lucene.search.Sort; import org.apache.lucene.search.similarities.Similarity; -import org.elasticsearch.Version; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.logging.DeprecationLogger; -import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.unit.ByteSizeUnit; @@ -55,8 +52,6 @@ * object will affect the {@link Engine} instance. */ public final class EngineConfig { - private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(EngineConfig.class)); - private final ShardId shardId; private final String allocationId; private final IndexSettings indexSettings; @@ -114,9 +109,8 @@ public final class EngineConfig { * this setting won't be reflected re-enabled optimization until the engine is restarted or the index is closed and reopened. * The default is true */ - @Deprecated public static final Setting INDEX_OPTIMIZE_AUTO_GENERATED_IDS = Setting.boolSetting("index.optimize_auto_generated_id", true, - Property.IndexScope, Property.Dynamic); + Property.IndexScope, Property.Dynamic, Property.Deprecated); private final TranslogConfig translogConfig; private final OpenMode openMode; @@ -137,11 +131,6 @@ public EngineConfig(OpenMode openMode, ShardId shardId, String allocationId, Thr if (openMode == null) { throw new IllegalArgumentException("openMode must not be null"); } - if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_6_0_0_rc1) - && INDEX_OPTIMIZE_AUTO_GENERATED_IDS.exists(indexSettings.getSettings())) { - DEPRECATION_LOGGER.deprecated( - "Setting [" + INDEX_OPTIMIZE_AUTO_GENERATED_IDS.getKey() + "] has been deprecated in favor of the auto-ID optimization"); - } this.shardId = shardId; this.allocationId = allocationId; this.indexSettings = indexSettings; diff --git a/server/src/test/java/org/elasticsearch/index/engine/EngineConfigTests.java b/server/src/test/java/org/elasticsearch/index/engine/EngineConfigTests.java index 457b17db7119d..a8d9e1e266ecf 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/EngineConfigTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/EngineConfigTests.java @@ -20,6 +20,7 @@ import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.test.ESTestCase; @@ -28,42 +29,21 @@ public class EngineConfigTests extends ESTestCase { - - private EngineConfig createEngineConfigWithSettings(IndexSettings indexSettings) { - return new EngineConfig(EngineConfig.OpenMode.OPEN_INDEX_AND_TRANSLOG, null, null, null, - indexSettings, null, null, null, null, - null, null, null, null, null, - true, null, null, null, null, null, - null, null, null); - } - - public void testOptimizeAutoGeneratedIdsSettingDeprecation() throws Exception { - Version version = randomFrom(Version.V_6_0_0_rc1, Version.V_6_0_0, Version.V_6_2_0, Version.V_6_3_0); + public void testOptimizeAutoGeneratedIdsSettingDeprecation() { boolean optimizeAutoGeneratedIds = randomBoolean(); Settings.Builder builder = Settings.builder() - .put(IndexMetaData.SETTING_VERSION_CREATED, version) + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put(EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS.getKey(), optimizeAutoGeneratedIds); IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("index1", builder.build()); - EngineConfig config = createEngineConfigWithSettings(indexSettings); - assertWarnings("Setting [" + EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS.getKey() - + "] has been deprecated in favor of the auto-ID optimization"); - assertEquals(optimizeAutoGeneratedIds, config.isAutoGeneratedIDsOptimizationEnabled()); + EngineConfig config = new EngineConfig(EngineConfig.OpenMode.OPEN_INDEX_AND_TRANSLOG, null, null, null, + indexSettings, null, null, null, null, + null, null, null, null, null, + true, null, null, null, null, null, + null, null, null); - version = randomFrom(Version.V_5_0_0, Version.V_5_0_0_alpha1, Version.V_5_6_9); - optimizeAutoGeneratedIds = randomBoolean(); - builder = Settings.builder() - .put(IndexMetaData.SETTING_VERSION_CREATED, version) - .put(EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS.getKey(), optimizeAutoGeneratedIds); - indexSettings = IndexSettingsModule.newIndexSettings("index2", builder.build()); - config = createEngineConfigWithSettings(indexSettings); assertEquals(optimizeAutoGeneratedIds, config.isAutoGeneratedIDsOptimizationEnabled()); - - version = randomFrom(Version.V_6_0_0_rc1, Version.V_6_0_0, Version.V_6_2_0, Version.V_6_3_0); - builder = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version); - indexSettings = IndexSettingsModule.newIndexSettings("index3", builder.build()); - config = createEngineConfigWithSettings(indexSettings); - assertTrue(config.isAutoGeneratedIDsOptimizationEnabled()); + assertSettingDeprecationsAndWarnings(new Setting[]{EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS}); } } From ca9bb8b7d246f5fbe10b315a4e2ef5ee46741606 Mon Sep 17 00:00:00 2001 From: liketic Date: Sun, 9 Dec 2018 21:52:48 +0800 Subject: [PATCH 3/3] Update test --- .../org/elasticsearch/index/engine/EngineConfigTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/index/engine/EngineConfigTests.java b/server/src/test/java/org/elasticsearch/index/engine/EngineConfigTests.java index a8d9e1e266ecf..39741d22f7918 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/EngineConfigTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/EngineConfigTests.java @@ -36,10 +36,10 @@ public void testOptimizeAutoGeneratedIdsSettingDeprecation() { .put(EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS.getKey(), optimizeAutoGeneratedIds); IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("index1", builder.build()); - EngineConfig config = new EngineConfig(EngineConfig.OpenMode.OPEN_INDEX_AND_TRANSLOG, null, null, null, + EngineConfig config = new EngineConfig(null, null, null, indexSettings, null, null, null, null, null, null, null, null, null, - true, null, null, null, null, null, + null, null, null, null, null, null, null, null, null); assertEquals(optimizeAutoGeneratedIds, config.isAutoGeneratedIDsOptimizationEnabled());