Skip to content

Commit b71490b

Browse files
authored
Deprecate indices without soft-deletes (#50502) (#50634)
Soft-deletes will be enabled for all indices in 8.0. Hence, we should deprecate new indices without soft-deletes in 7.x. Backport of #50502
1 parent ec0ec61 commit b71490b

File tree

7 files changed

+113
-17
lines changed

7 files changed

+113
-17
lines changed

docs/reference/index-modules/history-retention.asciidoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ there>>. {ccr-cap} will not function if soft deletes are disabled.
6565
configured at index creation and only on indices created on or after 6.5.0.
6666
The default value is `true`.
6767

68+
deprecated::[7.6, Creating indices with soft-deletes disabled is
69+
deprecated and will be removed in future Elasticsearch versions.]
70+
6871
`index.soft_deletes.retention_lease.period`::
6972

7073
The maximum length of time to retain a shard history retention lease before

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.cluster.metadata.MetaDataIndexStateService;
2929
import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider;
3030
import org.elasticsearch.common.Booleans;
31+
import org.elasticsearch.common.Strings;
3132
import org.elasticsearch.common.settings.Settings;
3233
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
3334
import org.elasticsearch.common.xcontent.support.XContentMapValues;
@@ -306,7 +307,7 @@ public void testRelocationWithConcurrentIndexing() throws Exception {
306307
}
307308
}
308309

309-
public void testRecoveryWithSoftDeletes() throws Exception {
310+
public void testRecovery() throws Exception {
310311
final String index = "recover_with_soft_deletes";
311312
if (CLUSTER_TYPE == ClusterType.OLD) {
312313
Settings.Builder settings = Settings.builder()
@@ -318,8 +319,8 @@ public void testRecoveryWithSoftDeletes() throws Exception {
318319
// before timing out
319320
.put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "100ms")
320321
.put(SETTING_ALLOCATION_MAX_RETRY.getKey(), "0"); // fail faster
321-
if (getNodeId(v -> v.onOrAfter(Version.V_6_5_0)) != null && randomBoolean()) {
322-
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true);
322+
if (randomBoolean()) {
323+
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean());
323324
}
324325
createIndex(index, settings.build());
325326
int numDocs = randomInt(10);
@@ -350,7 +351,7 @@ public void testRetentionLeasesEstablishedWhenPromotingPrimary() throws Exceptio
350351
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), between(1, 2)) // triggers nontrivial promotion
351352
.put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "100ms")
352353
.put(SETTING_ALLOCATION_MAX_RETRY.getKey(), "0") // fail faster
353-
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true);
354+
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean());
354355
createIndex(index, settings.build());
355356
int numDocs = randomInt(10);
356357
indexDocs(index, 0, numDocs);
@@ -373,7 +374,7 @@ public void testRetentionLeasesEstablishedWhenRelocatingPrimary() throws Excepti
373374
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), between(0, 1))
374375
.put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "100ms")
375376
.put(SETTING_ALLOCATION_MAX_RETRY.getKey(), "0") // fail faster
376-
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true);
377+
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean());
377378
createIndex(index, settings.build());
378379
int numDocs = randomInt(10);
379380
indexDocs(index, 0, numDocs);
@@ -784,6 +785,26 @@ public void testAutoExpandIndicesDuringRollingUpgrade() throws Exception {
784785
}
785786
}
786787

788+
public void testSoftDeletesDisabledWarning() throws Exception {
789+
final String indexName = "test_soft_deletes_disabled_warning";
790+
if (CLUSTER_TYPE == ClusterType.OLD) {
791+
boolean softDeletesEnabled = true;
792+
Settings.Builder settings = Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1);
793+
if (randomBoolean()) {
794+
softDeletesEnabled = randomBoolean();
795+
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), softDeletesEnabled);
796+
}
797+
Request request = new Request("PUT", "/" + indexName);
798+
request.setJsonEntity("{\"settings\": " + Strings.toString(settings.build()) + "}");
799+
if (softDeletesEnabled == false) {
800+
expectSoftDeletesWarning(request, indexName);
801+
}
802+
client().performRequest(request);
803+
}
804+
ensureGreen(indexName);
805+
indexDocs(indexName, randomInt(100), randomInt(100));
806+
}
807+
787808
@SuppressWarnings("unchecked")
788809
private Map<String, Object> getIndexSettingsAsMap(String index) throws IOException {
789810
Map<String, Object> indexSettings = getIndexSettings(index);

rest-api-spec/src/main/resources/rest-api-spec/test/indices.create/10_basic.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,20 @@
154154

155155
- match: { error.type: "illegal_argument_exception" }
156156
- match: { error.reason: "The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true." }
157+
158+
---
159+
"Create index without soft deletes":
160+
- skip:
161+
version: " - 7.5.99"
162+
reason: "indices without soft deletes are deprecated in 7.6"
163+
features: "warnings"
164+
165+
- do:
166+
warnings:
167+
- Creating indices with soft-deletes disabled is deprecated and will be removed in future Elasticsearch versions.
168+
Please do not specify value for setting [index.soft_deletes.enabled] of index [test_index].
169+
indices.create:
170+
index: test_index
171+
body:
172+
settings:
173+
soft_deletes.enabled: false

rest-api-spec/src/main/resources/rest-api-spec/test/indices.stats/20_translog.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
---
22
"Translog retention without soft_deletes":
3+
- skip:
4+
version: " - 7.5.99"
5+
reason: "indices without soft deletes are deprecated in 7.6"
6+
features: "warnings"
7+
38
- do:
49
indices.create:
510
index: test
611
body:
712
settings:
813
soft_deletes.enabled: false
14+
warnings:
15+
- Creating indices with soft-deletes disabled is deprecated and will be removed in future Elasticsearch versions.
16+
Please do not specify value for setting [index.soft_deletes.enabled] of index [test].
917
- do:
1018
cluster.health:
1119
wait_for_no_initializing_shards: true
@@ -132,15 +140,20 @@
132140
---
133141
"Translog stats on closed indices without soft-deletes":
134142
- skip:
135-
version: " - 7.2.99"
136-
reason: "closed indices have translog stats starting version 7.3.0"
143+
version: " - 7.5.99"
144+
reason: "indices without soft deletes are deprecated in 7.6"
145+
features: "warnings"
137146

138147
- do:
139148
indices.create:
140149
index: test
141150
body:
142151
settings:
143152
soft_deletes.enabled: false
153+
warnings:
154+
- Creating indices with soft-deletes disabled is deprecated and will be removed in future Elasticsearch versions.
155+
Please do not specify value for setting [index.soft_deletes.enabled] of index [test].
156+
144157
- do:
145158
cluster.health:
146159
wait_for_no_initializing_shards: true

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.elasticsearch.common.ValidationException;
5454
import org.elasticsearch.common.compress.CompressedXContent;
5555
import org.elasticsearch.common.io.PathUtils;
56+
import org.elasticsearch.common.logging.DeprecationLogger;
5657
import org.elasticsearch.common.settings.IndexScopedSettings;
5758
import org.elasticsearch.common.settings.Setting;
5859
import org.elasticsearch.common.settings.Settings;
@@ -63,6 +64,7 @@
6364
import org.elasticsearch.index.Index;
6465
import org.elasticsearch.index.IndexNotFoundException;
6566
import org.elasticsearch.index.IndexService;
67+
import org.elasticsearch.index.IndexSettings;
6668
import org.elasticsearch.index.mapper.DocumentMapper;
6769
import org.elasticsearch.index.mapper.MapperService;
6870
import org.elasticsearch.index.mapper.MapperService.MergeReason;
@@ -104,6 +106,7 @@
104106
*/
105107
public class MetaDataCreateIndexService {
106108
private static final Logger logger = LogManager.getLogger(MetaDataCreateIndexService.class);
109+
private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(logger);
107110

108111
public static final int MAX_INDEX_NAME_BYTES = 255;
109112

@@ -455,6 +458,11 @@ static Settings aggregateIndexSettings(ClusterState currentState, CreateIndexClu
455458
* that will be used to create this index.
456459
*/
457460
MetaDataCreateIndexService.checkShardLimit(indexSettings, currentState);
461+
if (indexSettings.getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true) == false) {
462+
DEPRECATION_LOGGER.deprecatedAndMaybeLog("soft_deletes_disabled",
463+
"Creating indices with soft-deletes disabled is deprecated and will be removed in future Elasticsearch versions. " +
464+
"Please do not specify value for setting [index.soft_deletes.enabled] of index [" + request.index() + "].");
465+
}
458466
return indexSettings;
459467
}
460468

server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,21 @@ public void testGetIndexNumberOfRoutingShardsYieldsSourceNumberOfShards() {
858858
assertThat(targetRoutingNumberOfShards, is(6));
859859
}
860860

861+
public void testSoftDeletesDisabledDeprecation() {
862+
request = new CreateIndexClusterStateUpdateRequest("create index", "test", "test");
863+
request.settings(Settings.builder().put(INDEX_SOFT_DELETES_SETTING.getKey(), false).build());
864+
aggregateIndexSettings(ClusterState.EMPTY_STATE, request, Collections.emptyList(), Collections.emptyMap(),
865+
null, Settings.EMPTY, IndexScopedSettings.DEFAULT_SCOPED_SETTINGS);
866+
assertWarnings("Creating indices with soft-deletes disabled is deprecated and will be removed in future Elasticsearch versions. "
867+
+ "Please do not specify value for setting [index.soft_deletes.enabled] of index [test].");
868+
request = new CreateIndexClusterStateUpdateRequest("create index", "test", "test");
869+
if (randomBoolean()) {
870+
request.settings(Settings.builder().put(INDEX_SOFT_DELETES_SETTING.getKey(), true).build());
871+
}
872+
aggregateIndexSettings(ClusterState.EMPTY_STATE, request, Collections.emptyList(), Collections.emptyMap(),
873+
null, Settings.EMPTY, IndexScopedSettings.DEFAULT_SCOPED_SETTINGS);
874+
}
875+
861876
private IndexTemplateMetaData addMatchingTemplate(Consumer<IndexTemplateMetaData.Builder> configurator) {
862877
IndexTemplateMetaData.Builder builder = templateMetaDataBuilder("template1", "te*");
863878
configurator.accept(builder);

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.elasticsearch.common.xcontent.json.JsonXContent;
5353
import org.elasticsearch.common.xcontent.support.XContentMapValues;
5454
import org.elasticsearch.core.internal.io.IOUtils;
55+
import org.elasticsearch.index.IndexSettings;
5556
import org.elasticsearch.index.seqno.ReplicationTracker;
5657
import org.elasticsearch.rest.RestStatus;
5758
import org.elasticsearch.snapshots.SnapshotState;
@@ -969,23 +970,27 @@ protected static void ensureNoInitializingShards() throws IOException {
969970
}
970971

971972
protected static void createIndex(String name, Settings settings) throws IOException {
972-
Request request = new Request("PUT", "/" + name);
973-
request.setJsonEntity("{\n \"settings\": " + Strings.toString(settings) + "}");
974-
client().performRequest(request);
973+
createIndex(name, settings, null);
975974
}
976975

977976
protected static void createIndex(String name, Settings settings, String mapping) throws IOException {
978-
Request request = new Request("PUT", "/" + name);
979-
request.setJsonEntity("{\n \"settings\": " + Strings.toString(settings)
980-
+ ", \"mappings\" : {" + mapping + "} }");
981-
client().performRequest(request);
977+
createIndex(name, settings, mapping, null);
982978
}
983979

984980
protected static void createIndex(String name, Settings settings, String mapping, String aliases) throws IOException {
985981
Request request = new Request("PUT", "/" + name);
986-
request.setJsonEntity("{\n \"settings\": " + Strings.toString(settings)
987-
+ ", \"mappings\" : {" + mapping + "}"
988-
+ ", \"aliases\": {" + aliases + "} }");
982+
String entity = "{\"settings\": " + Strings.toString(settings);
983+
if (mapping != null) {
984+
entity += ",\"mappings\" : {" + mapping + "}";
985+
}
986+
if (aliases != null) {
987+
entity += ",\"aliases\": {" + aliases + "}";
988+
}
989+
entity += "}";
990+
if (settings.getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true) == false) {
991+
expectSoftDeletesWarning(request, name);
992+
}
993+
request.setJsonEntity(entity);
989994
client().performRequest(request);
990995
}
991996

@@ -1004,6 +1009,20 @@ private static void updateIndexSettings(String index, Settings settings) throws
10041009
client().performRequest(request);
10051010
}
10061011

1012+
protected static void expectSoftDeletesWarning(Request request, String indexName) {
1013+
final List<String> expectedWarnings = Collections.singletonList(
1014+
"Creating indices with soft-deletes disabled is deprecated and will be removed in future Elasticsearch versions. " +
1015+
"Please do not specify value for setting [index.soft_deletes.enabled] of index [" + indexName + "].");
1016+
final Builder requestOptions = RequestOptions.DEFAULT.toBuilder();
1017+
if (nodeVersions.stream().allMatch(version -> version.onOrAfter(Version.V_7_6_0))) {
1018+
requestOptions.setWarningsHandler(warnings -> warnings.equals(expectedWarnings) == false);
1019+
request.setOptions(requestOptions);
1020+
} else if (nodeVersions.stream().anyMatch(version -> version.onOrAfter(Version.V_7_6_0))) {
1021+
requestOptions.setWarningsHandler(warnings -> warnings.isEmpty() == false && warnings.equals(expectedWarnings) == false);
1022+
request.setOptions(requestOptions);
1023+
}
1024+
}
1025+
10071026
protected static Map<String, Object> getIndexSettings(String index) throws IOException {
10081027
Request request = new Request("GET", "/" + index + "/_settings");
10091028
request.addParameter("flat_settings", "true");

0 commit comments

Comments
 (0)