Skip to content

Commit

Permalink
Reject index.optimize_auto_generated_id setting (#28895)
Browse files Browse the repository at this point in the history
This commit rejects the index.optmize_auto_generated_id setting for
indices created on or after 7.0.0. This setting was deprecated in 6.7.0.
  • Loading branch information
Like authored and jasontedor committed Feb 10, 2019
1 parent 5766b81 commit 97b64ee
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -493,6 +494,11 @@ private synchronized IndexService createIndexService(final String reason,
List<IndexEventListener> 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 [{}]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 97b64ee

Please sign in to comment.