Skip to content

Commit e9dda75

Browse files
committed
Enable soft-deletes by default for 7.0+ indices (#38929)
Today when users upgrade to 7.0, existing indices will automatically switch to soft-deletes without an opt-out option. With this change, we only enable soft-deletes by default for new indices. Relates #36141
1 parent a6c0166 commit e9dda75

File tree

6 files changed

+25
-15
lines changed

6 files changed

+25
-15
lines changed

server/src/main/java/org/elasticsearch/index/IndexSettings.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,11 @@ public final class IndexSettings {
243243

244244
/**
245245
* Specifies if the index should use soft-delete instead of hard-delete for update/delete operations.
246+
* Soft-deletes is enabled by default for 7.0+ indices.
246247
*/
247-
public static final Setting<Boolean> INDEX_SOFT_DELETES_SETTING =
248-
Setting.boolSetting("index.soft_deletes.enabled", true, Property.IndexScope, Property.Final);
248+
public static final Setting<Boolean> INDEX_SOFT_DELETES_SETTING = Setting.boolSetting("index.soft_deletes.enabled",
249+
settings -> Boolean.toString(IndexMetaData.SETTING_INDEX_VERSION_CREATED.get(settings).onOrAfter(Version.V_7_0_0)),
250+
Property.IndexScope, Property.Final);
249251

250252
/**
251253
* Controls how many soft-deleted documents will be kept around before being merged away. Keeping more deleted

server/src/test/java/org/elasticsearch/index/IndexSettingsTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,4 +561,20 @@ public void testUpdateSoftDeletesFails() {
561561
Settings.builder(), Settings.builder(), "index"));
562562
assertThat(error.getMessage(), equalTo("final index setting [index.soft_deletes.enabled], not updateable"));
563563
}
564+
565+
public void testSoftDeletesDefaultSetting() {
566+
// enabled by default on 7.0+ or later
567+
{
568+
Version createdVersion = VersionUtils.randomVersionBetween(random(), Version.V_7_0_0, Version.CURRENT);
569+
Settings settings = Settings.builder().put(IndexMetaData.SETTING_INDEX_VERSION_CREATED.getKey(), createdVersion).build();
570+
assertTrue(IndexSettings.INDEX_SOFT_DELETES_SETTING.get(settings));
571+
}
572+
// disabled by default on the previous versions
573+
{
574+
Version prevVersion = VersionUtils.randomVersionBetween(
575+
random(), Version.V_6_5_0, VersionUtils.getPreviousVersion(Version.V_7_0_0));
576+
Settings settings = Settings.builder().put(IndexMetaData.SETTING_INDEX_VERSION_CREATED.getKey(), prevVersion).build();
577+
assertFalse(IndexSettings.INDEX_SOFT_DELETES_SETTING.get(settings));
578+
}
579+
}
564580
}

server/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2216,10 +2216,11 @@ public void testSnapshotMoreThanOnce() throws ExecutionException, InterruptedExc
22162216
{
22172217
SnapshotStatus snapshotStatus = client.admin().cluster().prepareSnapshotStatus("test-repo")
22182218
.setSnapshots("test-2").get().getSnapshots().get(0);
2219+
Settings settings = client.admin().indices().prepareGetSettings("test").get().getIndexToSettings().get("test");
22192220
List<SnapshotIndexShardStatus> shards = snapshotStatus.getShards();
22202221
for (SnapshotIndexShardStatus status : shards) {
22212222
// we flush before the snapshot such that we have to process the segments_N files plus the .del file
2222-
if (INDEX_SOFT_DELETES_SETTING.get(indexSettings)) {
2223+
if (INDEX_SOFT_DELETES_SETTING.get(settings)) {
22232224
// soft-delete generates DV files.
22242225
assertThat(status.getStats().getProcessedFileCount(), greaterThan(2));
22252226
} else {

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.apache.logging.log4j.message.ParameterizedMessage;
1212
import org.elasticsearch.ElasticsearchException;
1313
import org.elasticsearch.ExceptionsHelper;
14-
import org.elasticsearch.Version;
1514
import org.elasticsearch.action.ActionListener;
1615
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
1716
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
@@ -448,9 +447,7 @@ private void checkAutoFollowPattern(String autoFollowPattenName,
448447
}
449448
} else {
450449
final Settings leaderIndexSettings = remoteMetadata.getIndexSafe(indexToFollow).getSettings();
451-
if (leaderIndexSettings.getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(),
452-
IndexMetaData.SETTING_INDEX_VERSION_CREATED.get(leaderIndexSettings).onOrAfter(Version.V_7_0_0)) == false) {
453-
450+
if (IndexSettings.INDEX_SOFT_DELETES_SETTING.get(leaderIndexSettings) == false) {
454451
String message = String.format(Locale.ROOT, "index [%s] cannot be followed, because soft deletes are not enabled",
455452
indexToFollow.getName());
456453
LOGGER.warn(message);

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.apache.logging.log4j.LogManager;
1010
import org.apache.logging.log4j.Logger;
1111
import org.apache.logging.log4j.message.ParameterizedMessage;
12-
import org.elasticsearch.Version;
1312
import org.elasticsearch.action.ActionListener;
1413
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreClusterStateListener;
1514
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest;
@@ -124,9 +123,7 @@ private void createFollowerIndex(
124123
listener.onFailure(new IllegalArgumentException("leader index [" + request.getLeaderIndex() + "] does not exist"));
125124
return;
126125
}
127-
// soft deletes are enabled by default on indices created on 7.0.0 or later
128-
if (leaderIndexMetaData.getSettings().getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(),
129-
IndexMetaData.SETTING_INDEX_VERSION_CREATED.get(leaderIndexMetaData.getSettings()).onOrAfter(Version.V_7_0_0)) == false) {
126+
if (IndexSettings.INDEX_SOFT_DELETES_SETTING.get(leaderIndexMetaData.getSettings()) == false) {
130127
listener.onFailure(new IllegalArgumentException("leader index [" + request.getLeaderIndex() +
131128
"] does not have soft deletes enabled"));
132129
return;

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
package org.elasticsearch.xpack.ccr.action;
88

9-
import org.elasticsearch.Version;
109
import org.elasticsearch.action.ActionListener;
1110
import org.elasticsearch.action.support.ActionFilters;
1211
import org.elasticsearch.action.support.master.AcknowledgedResponse;
@@ -214,9 +213,7 @@ static void validate(
214213
"] as history uuid");
215214
}
216215
}
217-
// soft deletes are enabled by default on indices created on 7.0.0 or later
218-
if (leaderIndex.getSettings().getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(),
219-
IndexMetaData.SETTING_INDEX_VERSION_CREATED.get(leaderIndex.getSettings()).onOrAfter(Version.V_7_0_0)) == false) {
216+
if (IndexSettings.INDEX_SOFT_DELETES_SETTING.get(leaderIndex.getSettings()) == false) {
220217
throw new IllegalArgumentException("leader index [" + leaderIndex.getIndex().getName() +
221218
"] does not have soft deletes enabled");
222219
}

0 commit comments

Comments
 (0)