Skip to content

Commit e6d9325

Browse files
Do not open indices with broken index settings
- remove the leniency on opening indices with unrecognized settings and instead such an index will be closed with the unrecognized settings archived - do not open any index with archived settings - users can remove archived settings via the wildcard archived - return "index_open_exception" 400 status code when trying to open an index with broken settings Relates to elastic#26995 Closes elastic#26998
1 parent 4e0722f commit e6d9325

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,10 @@ public ClusterState execute(ClusterState currentState) {
193193
// We need to check that this index can be upgraded to the current version
194194
indexMetaData = metaDataIndexUpgradeService.upgradeIndexMetaData(indexMetaData, minIndexCompatibilityVersion);
195195
try {
196-
indicesService.verifyIndexMetadata(indexMetaData, indexMetaData, "metadata verification");
196+
indicesService.verifyIndexMetadata(indexMetaData, indexMetaData, false);
197197
} catch (Exception e) {
198-
throw new IndexOpenException(indexMetaData.getIndex(), "Failed to open index! Failed to verify index " + indexMetaData.getIndex() + e.getMessage());
198+
throw new IndexOpenException(indexMetaData.getIndex(),
199+
"Failed to open index! Failed to verify index " + indexMetaData.getIndex() + e.getMessage());
199200
}
200201

201202
mdBuilder.put(indexMetaData, true);

server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,18 @@ public ClusterState execute(ClusterState currentState) {
276276
for (Index index : openIndices) {
277277
final IndexMetaData currentMetaData = currentState.getMetaData().getIndexSafe(index);
278278
final IndexMetaData updatedMetaData = updatedState.metaData().getIndexSafe(index);
279-
indicesService.verifyIndexMetadata(currentMetaData, updatedMetaData, "metadata verification");
279+
indicesService.verifyIndexMetadata(currentMetaData, updatedMetaData, false);
280280
}
281281
for (Index index : closeIndices) {
282282
final IndexMetaData currentMetaData = currentState.getMetaData().getIndexSafe(index);
283283
final IndexMetaData updatedMetaData = updatedState.metaData().getIndexSafe(index);
284284
// Verifies that the current index settings can be updated with the updated dynamic settings.
285285
// Ignore archived settings during verification, as closed indexes can have archived settings
286-
indicesService.verifyIndexMetadata(currentMetaData, updatedMetaData, "closed index metadata verification");
286+
indicesService.verifyIndexMetadata(currentMetaData, updatedMetaData, true);
287287
// Now check that we can create the index with the updated settings (dynamic and non-dynamic).
288288
// This step is mandatory since we allow to update non-dynamic settings on closed indices.
289289
// Ignore archived settings during verification, , as closed indexes can have archived settings
290-
indicesService.verifyIndexMetadata(updatedMetaData, updatedMetaData, "closed index metadata verification");
290+
indicesService.verifyIndexMetadata(updatedMetaData, updatedMetaData, true);
291291
}
292292
} catch (IOException ex) {
293293
throw ExceptionsHelper.convertToElastic(ex);

server/src/main/java/org/elasticsearch/gateway/Gateway.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void performStateRecovery(final GatewayStateRecoveredListener listener) t
124124
try {
125125
if (electedIndexMetaData.getState() == IndexMetaData.State.OPEN) {
126126
// verify that we can actually create this index - if not we recover it as closed with lots of warn logs
127-
indicesService.verifyIndexMetadata(electedIndexMetaData, electedIndexMetaData, "metadata verification");
127+
indicesService.verifyIndexMetadata(electedIndexMetaData, electedIndexMetaData, false);
128128
}
129129
} catch (Exception e) {
130130
final Index electedIndex = electedIndexMetaData.getIndex();

server/src/main/java/org/elasticsearch/indices/IndicesService.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ public void onStoreClosed(ShardId shardId) {
405405
final IndexService indexService =
406406
createIndexService(
407407
"create index",
408+
true,
408409
indexMetaData,
409410
indicesQueryCache,
410411
indicesFieldDataCache,
@@ -427,19 +428,15 @@ public void onStoreClosed(ShardId shardId) {
427428
* This creates a new IndexService without registering it
428429
*/
429430
private synchronized IndexService createIndexService(final String reason,
431+
final boolean ignoreArchivedSettings,
430432
IndexMetaData indexMetaData,
431433
IndicesQueryCache indicesQueryCache,
432434
IndicesFieldDataCache indicesFieldDataCache,
433435
List<IndexEventListener> builtInListeners,
434436
IndexingOperationListener... indexingOperationListeners) throws IOException {
435437
final IndexSettings idxSettings = new IndexSettings(indexMetaData, this.settings, indexScopedSettings);
436438
// we ignore private settings since they are not registered settings
437-
if (reason.equals("metadata verification")) {
438-
// don't allow archived settings during metadata verification
439-
indexScopedSettings.validate(indexMetaData.getSettings(), true, true, false);
440-
} else {
441-
indexScopedSettings.validate(indexMetaData.getSettings(), true, true, true);
442-
}
439+
indexScopedSettings.validate(indexMetaData.getSettings(), true, true, ignoreArchivedSettings);
443440
logger.debug("creating Index [{}], shards [{}]/[{}] - reason [{}]",
444441
indexMetaData.getIndex(),
445442
idxSettings.getNumberOfShards(),
@@ -483,24 +480,24 @@ public synchronized MapperService createIndexMapperService(IndexMetaData indexMe
483480
return indexModule.newIndexMapperService(xContentRegistry, mapperRegistry, scriptService);
484481
}
485482

486-
487483
/**
488484
* This method verifies that the given {@code metaData} holds sane values to create an {@link IndexService}.
489485
* This method tries to update the meta data of the created {@link IndexService} if the given {@code metaDataUpdate} is different from the given {@code metaData}.
490486
* This method will throw an exception if the creation or the update fails.
491487
* The created {@link IndexService} will not be registered and will be closed immediately.
492488
*/
493-
public synchronized void verifyIndexMetadata(IndexMetaData metaData, IndexMetaData metaDataUpdate, String reason) throws IOException {
489+
public synchronized void verifyIndexMetadata(IndexMetaData metaData, IndexMetaData metaDataUpdate, boolean ignoreArchivedSettings)
490+
throws IOException {
494491
final List<Closeable> closeables = new ArrayList<>();
495492
try {
496493
IndicesFieldDataCache indicesFieldDataCache = new IndicesFieldDataCache(settings, new IndexFieldDataCache.Listener() {});
497494
closeables.add(indicesFieldDataCache);
498495
IndicesQueryCache indicesQueryCache = new IndicesQueryCache(settings);
499496
closeables.add(indicesQueryCache);
500497
// this will also fail if some plugin fails etc. which is nice since we can verify that early
501-
final IndexService service =
502-
createIndexService(reason, metaData, indicesQueryCache, indicesFieldDataCache, emptyList());
503-
closeables.add(() -> service.close(reason, false));
498+
final IndexService service = createIndexService("metadata verification", ignoreArchivedSettings, metaData,
499+
indicesQueryCache, indicesFieldDataCache, emptyList());
500+
closeables.add(() -> service.close("metadata verification", false));
504501
service.mapperService().merge(metaData, MapperService.MergeReason.MAPPING_RECOVERY);
505502
if (metaData.equals(metaDataUpdate) == false) {
506503
service.updateMetaData(metaDataUpdate);

0 commit comments

Comments
 (0)