Skip to content

Commit e13db1b

Browse files
authored
Validates updated settings on closed indices (#24487)
We allow non-dynamic settings to be updated on closed indices but we don't check if the updated settings can be used to open/create the index. This can lead to unrecoverable state where the settings are updated but the index cannot be reopened since the settings are not valid. Trying to update the invalid settings is also not possible since the update will fail to validate the current settings. This change adds the validation of the updated settings for closed indices and make sure that the new settings do not prevent the reopen of the index. Fixes #23787
1 parent 77feabb commit e13db1b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,11 @@ public ClusterState execute(ClusterState currentState) {
276276
for (Index index : closeIndices) {
277277
final IndexMetaData currentMetaData = currentState.getMetaData().getIndexSafe(index);
278278
final IndexMetaData updatedMetaData = updatedState.metaData().getIndexSafe(index);
279+
// Verifies that the current index settings can be updated with the updated dynamic settings.
279280
indicesService.verifyIndexMetadata(currentMetaData, updatedMetaData);
281+
// Now check that we can create the index with the updated settings (dynamic and non-dynamic).
282+
// This step is mandatory since we allow to update non-dynamic settings on closed indices.
283+
indicesService.verifyIndexMetadata(updatedMetaData, updatedMetaData);
280284
}
281285
} catch (IOException ex) {
282286
throw ExceptionsHelper.convertToElastic(ex);

core/src/test/java/org/elasticsearch/indices/settings/UpdateSettingsIT.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@
4949
import static org.hamcrest.Matchers.nullValue;
5050

5151
public class UpdateSettingsIT extends ESIntegTestCase {
52+
public void testInvalidUpdateOnClosedIndex() {
53+
createIndex("test");
54+
assertAcked(client().admin().indices().prepareClose("test").get());
55+
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () ->
56+
client()
57+
.admin()
58+
.indices()
59+
.prepareUpdateSettings("test")
60+
.setSettings(Settings.builder().put("index.analysis.char_filter.invalid_char.type", "invalid"))
61+
.get());
62+
assertEquals(exception.getMessage(), "Unknown char_filter type [invalid] for [invalid_char]");
63+
}
5264

5365
public void testInvalidDynamicUpdate() {
5466
createIndex("test");

0 commit comments

Comments
 (0)