Skip to content

Commit

Permalink
Reject setting index.optimize_auto_generated_id after version 7.0.0 (e…
Browse files Browse the repository at this point in the history
  • Loading branch information
liketic committed Mar 4, 2018
1 parent f53d159 commit 2c7fe6a
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +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.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property;
Expand Down Expand Up @@ -131,6 +132,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_7_0_0_alpha1)
&& INDEX_OPTIMIZE_AUTO_GENERATED_IDS.exists(indexSettings.getSettings())) {
throw new IllegalArgumentException(
"Setting [" + INDEX_OPTIMIZE_AUTO_GENERATED_IDS.getKey() + "] was removed in version 7.0.0");
}
this.shardId = shardId;
this.allocationId = allocationId;
this.indexSettings = indexSettings;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 testOptimizeAutoGeneratedIdsSettingRemoval() throws Exception {
Version version = Version.V_7_0_0_alpha1;
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());

IllegalArgumentException exception = expectThrows(IllegalArgumentException.class,
() -> createEngineConfigWithSettings(indexSettings));
assertEquals("Setting [" + EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS.getKey() + "] was removed in version 7.0.0",
exception.getMessage());

version = randomFrom(Version.V_5_0_0, Version.V_5_0_0_alpha1, Version.V_5_6_9, Version.V_6_0_0_rc1,
Version.V_6_0_0, Version.V_6_2_0, Version.V_6_3_0);
optimizeAutoGeneratedIds = randomBoolean();
builder = Settings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, version)
.put(EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS.getKey(), optimizeAutoGeneratedIds);
IndexSettings indexSettings2 = IndexSettingsModule.newIndexSettings("index2", builder.build());
EngineConfig config = createEngineConfigWithSettings(indexSettings2);
assertEquals(optimizeAutoGeneratedIds, config.isAutoGeneratedIDsOptimizationEnabled());

version = Version.V_7_0_0_alpha1;
builder = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version);
indexSettings2 = IndexSettingsModule.newIndexSettings("index3", builder.build());
config = createEngineConfigWithSettings(indexSettings2);
assertTrue(config.isAutoGeneratedIDsOptimizationEnabled());
}
}

0 comments on commit 2c7fe6a

Please sign in to comment.