From 51800de2a8d21fe970eadcc3197fbaa9b0245775 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Tue, 11 Dec 2018 18:58:49 -0500 Subject: [PATCH] Enable soft-deletes by default on 7.0.0 or later (#36141) This change enables soft-deletes by default on ES 7.0.0 or later. Relates #33222 Co-authored-by: Jason Tedor --- docs/reference/ccr/getting-started.asciidoc | 18 +++++----- docs/reference/ccr/requirements.asciidoc | 13 +++---- docs/reference/indices/flush.asciidoc | 3 +- .../upgrades/FullClusterRestartIT.java | 2 +- .../elasticsearch/upgrades/RecoveryIT.java | 2 +- .../indices/shrink/TransportResizeAction.java | 3 +- .../elasticsearch/index/IndexSettings.java | 2 +- .../RemoveCorruptedShardDataCommandTests.java | 2 +- .../ccr/action/AutoFollowCoordinator.java | 7 +++- .../ccr/action/TransportPutFollowAction.java | 5 ++- .../action/TransportResumeFollowAction.java | 10 ++++-- .../TransportResumeFollowActionTests.java | 35 +++++++++++-------- 12 files changed, 58 insertions(+), 44 deletions(-) diff --git a/docs/reference/ccr/getting-started.asciidoc b/docs/reference/ccr/getting-started.asciidoc index 662bfbb92e2..85116cd6d4a 100644 --- a/docs/reference/ccr/getting-started.asciidoc +++ b/docs/reference/ccr/getting-started.asciidoc @@ -156,12 +156,12 @@ remote cluster. [[ccr-getting-started-leader-index]] === Creating a leader index -Leader indices require special index settings to ensure that the operations that -need to be replicated are available when the -follower requests them from the leader. These settings are used to enable soft -deletes on the leader index and to control how many soft deletes are retained. A -_soft delete_ occurs whenever a document is deleted or updated. Soft deletes can -be enabled only on new indices created on or after {es} 6.5.0. +Leader indices require a special index setting to ensure that the operations +that need to be replicated are available when the follower requests them from +the leader. This setting is used to control how many soft deletes are retained. +A _soft delete_ occurs whenever a document is deleted or updated. Soft deletes +can be enabled only on new indices created on or after {es} 6.5.0, and enabled +by default on new indices created on or after {es} 7.0.0. In the following example, we will create a leader index in the remote cluster: @@ -174,9 +174,8 @@ PUT /server-metrics "number_of_shards" : 1, "number_of_replicas" : 0, "soft_deletes" : { - "enabled" : true, <1> "retention" : { - "operations" : 1024 <2> + "operations" : 1024 <1> } } } @@ -212,8 +211,7 @@ PUT /server-metrics -------------------------------------------------- // CONSOLE // TEST[continued] -<1> Enables soft deletes on the leader index. -<2> Sets that up to 1024 soft deletes will be retained. +<1> Sets that up to 1024 soft deletes will be retained. [float] [[ccr-getting-started-follower-index]] diff --git a/docs/reference/ccr/requirements.asciidoc b/docs/reference/ccr/requirements.asciidoc index 14ac66a8b9c..944e317dd02 100644 --- a/docs/reference/ccr/requirements.asciidoc +++ b/docs/reference/ccr/requirements.asciidoc @@ -16,10 +16,8 @@ shards and made available to the follower shard tasks as it replays the history of operations. Soft deletes must be enabled for indices that you want to use as leader -indices. Enabling soft deletes requires the addition of some index settings at -index creation time. You must add these settings to your create index -requests or to the index templates that you use to manage the creation of new -indices. +indices. Soft deletes are enabled by default on new indices created on +or after {es} 7.0.0. IMPORTANT: This means that {ccr} can not be used on existing indices. If you have existing data that you want to replicate from another cluster, you must @@ -34,7 +32,7 @@ enabled. Whether or not soft deletes are enabled on the index. Soft deletes can only be configured at index creation and only on indices created on or after 6.5.0. The -default value is `false`. +default value is `true`. `index.soft_deletes.retention.operations`:: @@ -49,8 +47,8 @@ For more information about index settings, see {ref}/index-modules.html[Index mo ==== Setting soft deletes on indices created by APM Server or Beats If you want to replicate indices created by APM Server or Beats, and are -allowing APM Server or Beats to manage index templates, you need to enable -soft deletes on the underlying index templates. To enable soft deletes on the +allowing APM Server or Beats to manage index templates, you need to configure +soft deletes on the underlying index templates. To configure soft deletes on the underlying index templates, add the following changes to the relevant APM Server or Beats configuration file. @@ -58,7 +56,6 @@ or Beats configuration file. ---------------------------------------------------------------------- setup.template.overwrite: true setup.template.settings: - index.soft_deletes.enabled: true index.soft_deletes.retention.operations: 1024 ---------------------------------------------------------------------- diff --git a/docs/reference/indices/flush.asciidoc b/docs/reference/indices/flush.asciidoc index 8583afc96ab..37d48eec2a2 100644 --- a/docs/reference/indices/flush.asciidoc +++ b/docs/reference/indices/flush.asciidoc @@ -101,7 +101,8 @@ which returns something similar to: "translog_generation" : "2", "max_seq_no" : "-1", "sync_id" : "AVvFY-071siAOuFGEO9P", <1> - "max_unsafe_auto_id_timestamp" : "-1" + "max_unsafe_auto_id_timestamp" : "-1", + "min_retained_seq_no": "0" }, "num_docs" : 0 } diff --git a/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java b/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java index 48b7b3dbb0a..7eaf4709a8b 100644 --- a/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java +++ b/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java @@ -970,7 +970,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { mappingsAndSettings.startObject("settings"); mappingsAndSettings.field("number_of_shards", 1); mappingsAndSettings.field("number_of_replicas", 1); - if (getOldClusterVersion().onOrAfter(Version.V_6_5_0)) { + if (getOldClusterVersion().onOrAfter(Version.V_6_5_0) && randomBoolean()) { mappingsAndSettings.field("soft_deletes.enabled", true); } mappingsAndSettings.endObject(); diff --git a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java index 4d9f1fd9add..f7f847712ee 100644 --- a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java +++ b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java @@ -285,7 +285,7 @@ public class RecoveryIT extends AbstractRollingTestCase { // before timing out .put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "100ms") .put(SETTING_ALLOCATION_MAX_RETRY.getKey(), "0"); // fail faster - if (getNodeId(v -> v.onOrAfter(Version.V_6_5_0)) != null) { + if (getNodeId(v -> v.onOrAfter(Version.V_6_5_0)) != null && randomBoolean()) { settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true); } createIndex(index, settings.build()); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/shrink/TransportResizeAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/shrink/TransportResizeAction.java index 0bf79a72b6f..a4b9fa8e66d 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/shrink/TransportResizeAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/shrink/TransportResizeAction.java @@ -172,8 +172,7 @@ public class TransportResizeAction extends TransportMasterNodeAction INDEX_SOFT_DELETES_SETTING = - Setting.boolSetting("index.soft_deletes.enabled", false, Property.IndexScope, Property.Final); + 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/shard/RemoveCorruptedShardDataCommandTests.java b/server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandTests.java index 93e0515c1cd..02e26604dcd 100644 --- a/server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandTests.java +++ b/server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandTests.java @@ -225,7 +225,7 @@ public class RemoveCorruptedShardDataCommandTests extends IndexShardTestCase { final Throwable cause = exception.getCause() instanceof EngineException ? exception.getCause().getCause() : exception.getCause(); assertThat(cause, instanceOf(TranslogCorruptedException.class)); - closeShards(corruptedShard); + closeShard(corruptedShard, false); // translog is corrupted already - do not check consistency final RemoveCorruptedShardDataCommand command = new RemoveCorruptedShardDataCommand(); final MockTerminal t = new MockTerminal(); diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java index 707cd1abe5e..688a7561092 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; import org.elasticsearch.client.Client; @@ -23,6 +24,7 @@ import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.collect.CopyOnWriteHashMap; import org.elasticsearch.common.collect.Tuple; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.AtomicArray; import org.elasticsearch.common.util.concurrent.CountDown; @@ -416,7 +418,10 @@ public class AutoFollowCoordinator implements ClusterStateListener { // has a leader index uuid custom metadata entry that matches with uuid of leaderIndexMetaData variable // If so then handle it differently: not follow it, but just add an entry to // AutoFollowMetadata#followedLeaderIndexUUIDs - if (leaderIndexMetaData.getSettings().getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), false)) { + final Settings leaderIndexSettings = leaderIndexMetaData.getSettings(); + // soft deletes are enabled by default on indices created on 7.0.0 or later + if (leaderIndexSettings.getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), + IndexMetaData.SETTING_INDEX_VERSION_CREATED.get(leaderIndexSettings).onOrAfter(Version.V_7_0_0))) { leaderIndicesToFollow.add(leaderIndexMetaData.getIndex()); } } diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java index 2562882bc29..bca8608904a 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java @@ -8,6 +8,7 @@ package org.elasticsearch.xpack.ccr.action; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.elasticsearch.ResourceAlreadyExistsException; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.ActiveShardCount; @@ -122,7 +123,9 @@ public final class TransportPutFollowAction listener.onFailure(new IllegalArgumentException("leader index [" + request.getLeaderIndex() + "] does not exist")); return; } - if (leaderIndexMetaData.getSettings().getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), false) == false) { + // soft deletes are enabled by default on indices created on 7.0.0 or later + if (leaderIndexMetaData.getSettings().getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), + IndexMetaData.SETTING_INDEX_VERSION_CREATED.get(leaderIndexMetaData.getSettings()).onOrAfter(Version.V_7_0_0)) == false) { listener.onFailure( new IllegalArgumentException("leader index [" + request.getLeaderIndex() + "] does not have soft deletes enabled")); return; diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java index 7e761e00bd9..5d6982d8a38 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java @@ -6,6 +6,7 @@ package org.elasticsearch.xpack.ccr.action; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.master.AcknowledgedResponse; @@ -211,12 +212,13 @@ public class TransportResumeFollowAction extends TransportMasterNodeAction validate(request, leaderIMD, followIMD, UUIDs, null)); + assertThat(e.getMessage(), equalTo("leader index [index1] does not have soft deletes enabled")); + } + { + // should fail because leader index does not have soft deletes enabled (by default). + Version prevVersion = VersionUtils.randomVersionBetween( + random(), Version.V_6_5_0, VersionUtils.getPreviousVersion(Version.V_7_0_0)); + IndexMetaData leaderIMD = IndexMetaData.builder("index1").settings(settings(prevVersion)).numberOfShards(1) + .numberOfReplicas(0).setRoutingNumShards(1).putMapping("_doc", "{\"properties\": {}}").build(); IndexMetaData followIMD = createIMD("index2", 5, Settings.EMPTY, customMetaData); Exception e = expectThrows(IllegalArgumentException.class, () -> validate(request, leaderIMD, followIMD, UUIDs, null)); assertThat(e.getMessage(), equalTo("leader index [index1] does not have soft deletes enabled")); } { // should fail because the follower index does not have soft deletes enabled - IndexMetaData leaderIMD = createIMD("index1", 5, Settings.builder() - .put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true").build(), null); - IndexMetaData followIMD = createIMD("index2", 5, Settings.EMPTY, customMetaData); + IndexMetaData leaderIMD = createIMD("index1", 5, Settings.EMPTY, null); + IndexMetaData followIMD = createIMD("index2", 5, Settings.builder() + .put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "false").build(), customMetaData); Exception e = expectThrows(IllegalArgumentException.class, () -> validate(request, leaderIMD, followIMD, UUIDs, null)); assertThat(e.getMessage(), equalTo("follower index [index2] does not have soft deletes enabled")); } { // should fail because the number of primary shards between leader and follow index are not equal - IndexMetaData leaderIMD = createIMD("index1", 5, Settings.builder() - .put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true").build(), null); - IndexMetaData followIMD = createIMD("index2", 4, - Settings.builder().put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true").build(), customMetaData); + IndexMetaData leaderIMD = createIMD("index1", 5, Settings.EMPTY, null); + IndexMetaData followIMD = createIMD("index2", 4, Settings.EMPTY, customMetaData); Exception e = expectThrows(IllegalArgumentException.class, () -> validate(request, leaderIMD, followIMD, UUIDs, null)); assertThat(e.getMessage(), equalTo("leader index primary shards [5] does not match with the number of shards of the follow index [4]")); @@ -100,17 +110,14 @@ public class TransportResumeFollowActionTests extends ESTestCase { // should fail, because leader index is closed IndexMetaData leaderIMD = createIMD("index1", State.CLOSE, "{}", 5, Settings.builder() .put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true").build(), null); - IndexMetaData followIMD = createIMD("index2", State.OPEN, "{}", 5, - Settings.builder().put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true").build(), customMetaData); + IndexMetaData followIMD = createIMD("index2", State.OPEN, "{}", 5, Settings.EMPTY, customMetaData); Exception e = expectThrows(IllegalArgumentException.class, () -> validate(request, leaderIMD, followIMD, UUIDs, null)); assertThat(e.getMessage(), equalTo("leader and follow index must be open")); } { // should fail, because index.xpack.ccr.following_index setting has not been enabled in leader index - IndexMetaData leaderIMD = createIMD("index1", 1, - Settings.builder().put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true").build(), null); - IndexMetaData followIMD = createIMD("index2", 1, - Settings.builder().put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true").build(), customMetaData); + IndexMetaData leaderIMD = createIMD("index1", 1, Settings.EMPTY, null); + IndexMetaData followIMD = createIMD("index2", 1, Settings.EMPTY, customMetaData); MapperService mapperService = MapperTestUtils.newMapperService(xContentRegistry(), createTempDir(), Settings.EMPTY, "index2"); mapperService.updateMapping(null, followIMD); Exception e = expectThrows(IllegalArgumentException.class,