Skip to content

Commit c893a3e

Browse files
authored
Make soft-deletes mandatory in 8.0 (#51122)
Creating indices with soft deletes disabled is no longer supported in 8.0.
1 parent 09ebc11 commit c893a3e

File tree

26 files changed

+150
-390
lines changed

26 files changed

+150
-390
lines changed

docs/reference/migration/migrate_8_0/indices.asciidoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,12 @@ removed in 8.0.
3434

3535
Synced flush was deprecated in 7.6 and is removed in 8.0. Use a regular flush
3636
instead as it has the same effect as a synced flush in 7.6 and later.
37+
38+
39+
[float]
40+
==== Indices with soft deletes disabled
41+
42+
Creating indices with soft deletes disabled was deprecated in 7.6 and
43+
is no longer supported in 8.0. The setting index.soft_deletes.enabled
44+
can no longer be set to false. As the setting defaults to true, simply
45+
leave the setting unset.

qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,11 @@ public void testSnapshotRestore() throws IOException {
776776
if (isRunningAgainstOldCluster()) {
777777
// Create the index
778778
count = between(200, 300);
779+
Settings.Builder settings = Settings.builder();
780+
if (minimumNodeVersion().before(Version.V_8_0_0) && randomBoolean()) {
781+
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean());
782+
}
783+
createIndex(index, settings.build());
779784
indexRandomDocuments(count, true, true, i -> jsonBuilder().startObject().field("field", "value").endObject());
780785
} else {
781786
count = countOfIndexedRandomDocuments();
@@ -1257,11 +1262,12 @@ public void testPeerRecoveryRetentionLeases() throws IOException {
12571262
*/
12581263
public void testOperationBasedRecovery() throws Exception {
12591264
if (isRunningAgainstOldCluster()) {
1260-
createIndex(index, Settings.builder()
1261-
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
1262-
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
1263-
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean())
1264-
.build());
1265+
Settings.Builder settings = Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
1266+
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1);
1267+
if (minimumNodeVersion().before(Version.V_8_0_0) && randomBoolean()) {
1268+
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean());
1269+
}
1270+
createIndex(index, settings.build());
12651271
ensureGreen(index);
12661272
int committedDocs = randomIntBetween(100, 200);
12671273
for (int i = 0; i < committedDocs; i++) {
@@ -1309,4 +1315,77 @@ public void testTurnOffTranslogRetentionAfterUpgraded() throws Exception {
13091315
ensurePeerRecoveryRetentionLeasesRenewedAndSynced(index);
13101316
}
13111317
}
1318+
1319+
public void testResize() throws Exception {
1320+
int numDocs;
1321+
if (isRunningAgainstOldCluster()) {
1322+
final Settings.Builder settings = Settings.builder()
1323+
.put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 3)
1324+
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 1);
1325+
if (minimumNodeVersion().before(Version.V_8_0_0) && randomBoolean()) {
1326+
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), false);
1327+
}
1328+
createIndex(index, settings.build());
1329+
numDocs = randomIntBetween(10, 1000);
1330+
for (int i = 0; i < numDocs; i++) {
1331+
indexDocument(Integer.toString(i));
1332+
if (rarely()) {
1333+
flush(index, randomBoolean());
1334+
}
1335+
}
1336+
saveInfoDocument("num_doc_" + index, Integer.toString(numDocs));
1337+
ensureGreen(index);
1338+
} else {
1339+
ensureGreen(index);
1340+
numDocs = Integer.parseInt(loadInfoDocument("num_doc_" + index));
1341+
int moreDocs = randomIntBetween(0, 100);
1342+
for (int i = 0; i < moreDocs; i++) {
1343+
indexDocument(Integer.toString(numDocs + i));
1344+
if (rarely()) {
1345+
flush(index, randomBoolean());
1346+
}
1347+
}
1348+
Request updateSettingsRequest = new Request("PUT", "/" + index + "/_settings");
1349+
updateSettingsRequest.setJsonEntity("{\"settings\": {\"index.blocks.write\": true}}");
1350+
client().performRequest(updateSettingsRequest);
1351+
{
1352+
final String target = index + "_shrunken";
1353+
Request shrinkRequest = new Request("PUT", "/" + index + "/_shrink/" + target);
1354+
Settings.Builder settings = Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1);
1355+
if (randomBoolean()) {
1356+
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true);
1357+
}
1358+
shrinkRequest.setJsonEntity("{\"settings\":" + Strings.toString(settings.build()) + "}");
1359+
client().performRequest(shrinkRequest);
1360+
ensureGreenLongWait(target);
1361+
assertNumHits(target, numDocs + moreDocs, 1);
1362+
}
1363+
{
1364+
final String target = index + "_split";
1365+
Settings.Builder settings = Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 6);
1366+
if (randomBoolean()) {
1367+
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true);
1368+
}
1369+
Request splitRequest = new Request("PUT", "/" + index + "/_split/" + target);
1370+
splitRequest.setJsonEntity("{\"settings\":" + Strings.toString(settings.build()) + "}");
1371+
client().performRequest(splitRequest);
1372+
ensureGreenLongWait(target);
1373+
assertNumHits(target, numDocs + moreDocs, 6);
1374+
}
1375+
{
1376+
final String target = index + "_cloned";
1377+
client().performRequest(new Request("PUT", "/" + index + "/_clone/" + target));
1378+
ensureGreenLongWait(target);
1379+
assertNumHits(target, numDocs + moreDocs, 3);
1380+
}
1381+
}
1382+
}
1383+
1384+
private void assertNumHits(String index, int numHits, int totalShards) throws IOException {
1385+
Map<String, Object> resp = entityAsMap(client().performRequest(new Request("GET", "/" + index + "/_search")));
1386+
assertNoFailures(resp);
1387+
assertThat(XContentMapValues.extractValue("_shards.total", resp), equalTo(totalShards));
1388+
assertThat(XContentMapValues.extractValue("_shards.successful", resp), equalTo(totalShards));
1389+
assertThat(extractTotalHits(resp), equalTo(numHits));
1390+
}
13121391
}

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public void testRecovery() throws Exception {
293293
// before timing out
294294
.put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "100ms")
295295
.put(SETTING_ALLOCATION_MAX_RETRY.getKey(), "0"); // fail faster
296-
if (randomBoolean()) {
296+
if (minimumNodeVersion().before(Version.V_8_0_0) && randomBoolean()) {
297297
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean());
298298
}
299299
createIndex(index, settings.build());
@@ -327,8 +327,10 @@ public void testRetentionLeasesEstablishedWhenPromotingPrimary() throws Exceptio
327327
.put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), between(1, 5))
328328
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), between(1, 2)) // triggers nontrivial promotion
329329
.put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "100ms")
330-
.put(SETTING_ALLOCATION_MAX_RETRY.getKey(), "0") // fail faster
331-
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean());
330+
.put(SETTING_ALLOCATION_MAX_RETRY.getKey(), "0"); // fail faster
331+
if (minimumNodeVersion().before(Version.V_8_0_0) && randomBoolean()) {
332+
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean());
333+
}
332334
createIndex(index, settings.build());
333335
int numDocs = randomInt(10);
334336
indexDocs(index, 0, numDocs);
@@ -350,8 +352,10 @@ public void testRetentionLeasesEstablishedWhenRelocatingPrimary() throws Excepti
350352
.put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), between(1, 5))
351353
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), between(0, 1))
352354
.put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "100ms")
353-
.put(SETTING_ALLOCATION_MAX_RETRY.getKey(), "0") // fail faster
354-
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean());
355+
.put(SETTING_ALLOCATION_MAX_RETRY.getKey(), "0"); // fail faster
356+
if (minimumNodeVersion().before(Version.V_8_0_0) && randomBoolean()) {
357+
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean());
358+
}
355359
createIndex(index, settings.build());
356360
int numDocs = randomInt(10);
357361
indexDocs(index, 0, numDocs);
@@ -635,10 +639,13 @@ private void assertNoopRecoveries(String indexName, Predicate<String> targetNode
635639
public void testOperationBasedRecovery() throws Exception {
636640
final String index = "test_operation_based_recovery";
637641
if (CLUSTER_TYPE == ClusterType.OLD) {
638-
createIndex(index, Settings.builder()
642+
final Settings.Builder settings = Settings.builder()
639643
.put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1)
640-
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 2)
641-
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean()).build());
644+
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 2);
645+
if (minimumNodeVersion().before(Version.V_8_0_0) && randomBoolean()) {
646+
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean());
647+
}
648+
createIndex(index, settings.build());
642649
ensureGreen(index);
643650
indexDocs(index, 0, randomIntBetween(100, 200));
644651
flush(index, randomBoolean());
@@ -714,7 +721,7 @@ public void testSoftDeletesDisabledWarning() throws Exception {
714721
if (CLUSTER_TYPE == ClusterType.OLD) {
715722
boolean softDeletesEnabled = true;
716723
Settings.Builder settings = Settings.builder();
717-
if (randomBoolean()) {
724+
if (minimumNodeVersion().before(Version.V_8_0_0) && randomBoolean()) {
718725
softDeletesEnabled = randomBoolean();
719726
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), softDeletesEnabled);
720727
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,10 @@
123123
---
124124
"Create index without soft deletes":
125125
- skip:
126-
version: " - 7.5.99"
127-
reason: "indices without soft deletes are deprecated in 7.6"
128-
features: "warnings"
129-
126+
version: " - 7.9.99"
127+
reason: "indices without soft-deletes is no longer supported "
130128
- do:
131-
warnings:
132-
- Creating indices with soft-deletes disabled is deprecated and will be removed in future Elasticsearch versions.
133-
Please do not specify value for setting [index.soft_deletes.enabled] of index [test_index].
129+
catch: /illegal_argument_exception/
134130
indices.create:
135131
index: test_index
136132
body:

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

Lines changed: 2 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,5 @@
11
---
2-
"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-
8-
- do:
9-
indices.create:
10-
index: test
11-
body:
12-
settings:
13-
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].
17-
- do:
18-
cluster.health:
19-
wait_for_no_initializing_shards: true
20-
wait_for_events: languid
21-
- do:
22-
indices.stats:
23-
metric: [ translog ]
24-
- set: { indices.test.primaries.translog.size_in_bytes: creation_size }
25-
26-
- do:
27-
index:
28-
index: test
29-
id: 1
30-
body: { "foo": "bar" }
31-
32-
- do:
33-
indices.stats:
34-
metric: [ translog ]
35-
- gt: { indices.test.primaries.translog.size_in_bytes: $creation_size }
36-
- match: { indices.test.primaries.translog.operations: 1 }
37-
# we can't check this yet as creation size will contain two empty translog generations. A single
38-
# non empty generation with one op may be smaller or larger than that.
39-
# - gt: { indices.test.primaries.translog.uncommitted_size_in_bytes: $creation_size }
40-
- match: { indices.test.primaries.translog.uncommitted_operations: 1 }
41-
42-
- do:
43-
indices.flush:
44-
index: test
45-
46-
- do:
47-
indices.stats:
48-
metric: [ translog ]
49-
- gt: { indices.test.primaries.translog.size_in_bytes: $creation_size }
50-
- match: { indices.test.primaries.translog.operations: 1 }
51-
## creation translog size has some overhead due to an initial empty generation that will be trimmed later
52-
- lt: { indices.test.primaries.translog.uncommitted_size_in_bytes: $creation_size }
53-
- match: { indices.test.primaries.translog.uncommitted_operations: 0 }
54-
55-
- do:
56-
indices.put_settings:
57-
index: test
58-
body:
59-
index.translog.retention.size: -1
60-
index.translog.retention.age: -1
61-
62-
- do:
63-
indices.flush:
64-
index: test
65-
force: true # force flush as we don't have pending ops
66-
67-
- do:
68-
indices.stats:
69-
metric: [ translog ]
70-
## creation translog size has some overhead due to an initial empty generation that will be trimmed later
71-
- lte: { indices.test.primaries.translog.size_in_bytes: $creation_size }
72-
- match: { indices.test.primaries.translog.operations: 0 }
73-
- lte: { indices.test.primaries.translog.uncommitted_size_in_bytes: $creation_size }
74-
- match: { indices.test.primaries.translog.uncommitted_operations: 0 }
75-
76-
---
77-
"Translog retention with soft_deletes":
78-
- skip:
79-
version: " - 7.3.99"
80-
reason: "start ignoring translog retention policy with soft-deletes enabled in 7.4"
2+
"Translog retention":
813
- do:
824
indices.create:
835
index: test
@@ -136,69 +58,7 @@
13658
- gte: { indices.test.primaries.translog.earliest_last_modified_age: 0 }
13759

13860
---
139-
"Translog stats on closed indices without soft-deletes":
140-
- skip:
141-
version: " - 7.5.99"
142-
reason: "indices without soft deletes are deprecated in 7.6"
143-
features: "warnings"
144-
145-
- do:
146-
indices.create:
147-
index: test
148-
body:
149-
settings:
150-
soft_deletes.enabled: false
151-
warnings:
152-
- Creating indices with soft-deletes disabled is deprecated and will be removed in future Elasticsearch versions.
153-
Please do not specify value for setting [index.soft_deletes.enabled] of index [test].
154-
155-
- do:
156-
cluster.health:
157-
wait_for_no_initializing_shards: true
158-
wait_for_events: languid
159-
- do:
160-
index:
161-
index: test
162-
id: 1
163-
body: { "foo": "bar" }
164-
165-
- do:
166-
index:
167-
index: test
168-
id: 2
169-
body: { "foo": "bar" }
170-
171-
- do:
172-
index:
173-
index: test
174-
id: 3
175-
body: { "foo": "bar" }
176-
177-
- do:
178-
indices.stats:
179-
metric: [ translog ]
180-
- match: { indices.test.primaries.translog.operations: 3 }
181-
- match: { indices.test.primaries.translog.uncommitted_operations: 3 }
182-
183-
- do:
184-
indices.close:
185-
index: test
186-
wait_for_active_shards: 1
187-
- is_true: acknowledged
188-
189-
- do:
190-
indices.stats:
191-
metric: [ translog ]
192-
expand_wildcards: all
193-
forbid_closed_indices: false
194-
- match: { indices.test.primaries.translog.operations: 3 }
195-
- match: { indices.test.primaries.translog.uncommitted_operations: 0 }
196-
197-
---
198-
"Translog stats on closed indices with soft-deletes":
199-
- skip:
200-
version: " - 7.3.99"
201-
reason: "start ignoring translog retention policy with soft-deletes enabled in 7.4"
61+
"Translog stats on closed indices":
20262
- do:
20363
indices.create:
20464
index: test

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
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;
5756
import org.elasticsearch.common.settings.IndexScopedSettings;
5857
import org.elasticsearch.common.settings.Setting;
5958
import org.elasticsearch.common.settings.Settings;
@@ -104,7 +103,6 @@
104103
*/
105104
public class MetaDataCreateIndexService {
106105
private static final Logger logger = LogManager.getLogger(MetaDataCreateIndexService.class);
107-
private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(logger);
108106

109107
public static final int MAX_INDEX_NAME_BYTES = 255;
110108

@@ -439,10 +437,10 @@ static Settings aggregateIndexSettings(ClusterState currentState, CreateIndexClu
439437
* that will be used to create this index.
440438
*/
441439
MetaDataCreateIndexService.checkShardLimit(indexSettings, currentState);
442-
if (indexSettings.getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true) == false) {
443-
DEPRECATION_LOGGER.deprecatedAndMaybeLog("soft_deletes_disabled",
444-
"Creating indices with soft-deletes disabled is deprecated and will be removed in future Elasticsearch versions. " +
445-
"Please do not specify value for setting [index.soft_deletes.enabled] of index [" + request.index() + "].");
440+
if (IndexSettings.INDEX_SOFT_DELETES_SETTING.get(indexSettings) == false
441+
&& IndexMetaData.SETTING_INDEX_VERSION_CREATED.get(indexSettings).onOrAfter(Version.V_8_0_0)) {
442+
throw new IllegalArgumentException("Creating indices with soft-deletes disabled is no longer supported. " +
443+
"Please do not specify a value for setting [index.soft_deletes.enabled].");
446444
}
447445
return indexSettings;
448446
}

0 commit comments

Comments
 (0)