From 3e879b404944e12b34a03bf696eefaa167c44643 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Tue, 28 Aug 2018 08:48:42 -0400 Subject: [PATCH] Make soft-deletes settings final (#33172) For now, we do not support changing the soft-deletes setting even with closed indices. Therefore we should make it a final setting. Relates #29530 --- .../main/java/org/elasticsearch/index/IndexSettings.java | 2 +- .../java/org/elasticsearch/index/IndexSettingsTests.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/index/IndexSettings.java b/server/src/main/java/org/elasticsearch/index/IndexSettings.java index 0706cd30e888..7c8b4a72965c 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexSettings.java +++ b/server/src/main/java/org/elasticsearch/index/IndexSettings.java @@ -248,7 +248,7 @@ public final class IndexSettings { * Specifies if the index should use soft-delete instead of hard-delete for update/delete operations. */ public static final Setting INDEX_SOFT_DELETES_SETTING = - Setting.boolSetting("index.soft_deletes.enabled", true, Property.IndexScope); + Setting.boolSetting("index.soft_deletes.enabled", true, Property.IndexScope, Property.Final); /** * Controls how many soft-deleted documents will be kept around before being merged away. Keeping more deleted diff --git a/server/src/test/java/org/elasticsearch/index/IndexSettingsTests.java b/server/src/test/java/org/elasticsearch/index/IndexSettingsTests.java index 08f517552b09..43944759f00d 100644 --- a/server/src/test/java/org/elasticsearch/index/IndexSettingsTests.java +++ b/server/src/test/java/org/elasticsearch/index/IndexSettingsTests.java @@ -607,4 +607,12 @@ public void testQueryDefaultField() { ); assertThat(index.getDefaultFields(), equalTo(Arrays.asList("body", "title"))); } + + public void testUpdateSoftDeletesFails() { + IndexScopedSettings settings = new IndexScopedSettings(Settings.EMPTY, IndexScopedSettings.BUILT_IN_INDEX_SETTINGS); + IllegalArgumentException error = expectThrows(IllegalArgumentException.class, () -> + settings.updateSettings(Settings.builder().put("index.soft_deletes.enabled", randomBoolean()).build(), + Settings.builder(), Settings.builder(), "index")); + assertThat(error.getMessage(), equalTo("final index setting [index.soft_deletes.enabled], not updateable")); + } }