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
This commit is contained in:
parent
a6c0166d68
commit
e9dda75834
|
@ -243,9 +243,11 @@ public final class IndexSettings {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies if the index should use soft-delete instead of hard-delete for update/delete operations.
|
* Specifies if the index should use soft-delete instead of hard-delete for update/delete operations.
|
||||||
|
* Soft-deletes is enabled by default for 7.0+ indices.
|
||||||
*/
|
*/
|
||||||
public static final Setting<Boolean> INDEX_SOFT_DELETES_SETTING =
|
public static final Setting<Boolean> INDEX_SOFT_DELETES_SETTING = Setting.boolSetting("index.soft_deletes.enabled",
|
||||||
Setting.boolSetting("index.soft_deletes.enabled", true, Property.IndexScope, Property.Final);
|
settings -> Boolean.toString(IndexMetaData.SETTING_INDEX_VERSION_CREATED.get(settings).onOrAfter(Version.V_7_0_0)),
|
||||||
|
Property.IndexScope, Property.Final);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls how many soft-deleted documents will be kept around before being merged away. Keeping more deleted
|
* Controls how many soft-deleted documents will be kept around before being merged away. Keeping more deleted
|
||||||
|
|
|
@ -561,4 +561,20 @@ public class IndexSettingsTests extends ESTestCase {
|
||||||
Settings.builder(), Settings.builder(), "index"));
|
Settings.builder(), Settings.builder(), "index"));
|
||||||
assertThat(error.getMessage(), equalTo("final index setting [index.soft_deletes.enabled], not updateable"));
|
assertThat(error.getMessage(), equalTo("final index setting [index.soft_deletes.enabled], not updateable"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSoftDeletesDefaultSetting() {
|
||||||
|
// enabled by default on 7.0+ or later
|
||||||
|
{
|
||||||
|
Version createdVersion = VersionUtils.randomVersionBetween(random(), Version.V_7_0_0, Version.CURRENT);
|
||||||
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_INDEX_VERSION_CREATED.getKey(), createdVersion).build();
|
||||||
|
assertTrue(IndexSettings.INDEX_SOFT_DELETES_SETTING.get(settings));
|
||||||
|
}
|
||||||
|
// disabled by default on the previous versions
|
||||||
|
{
|
||||||
|
Version prevVersion = VersionUtils.randomVersionBetween(
|
||||||
|
random(), Version.V_6_5_0, VersionUtils.getPreviousVersion(Version.V_7_0_0));
|
||||||
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_INDEX_VERSION_CREATED.getKey(), prevVersion).build();
|
||||||
|
assertFalse(IndexSettings.INDEX_SOFT_DELETES_SETTING.get(settings));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2216,10 +2216,11 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
||||||
{
|
{
|
||||||
SnapshotStatus snapshotStatus = client.admin().cluster().prepareSnapshotStatus("test-repo")
|
SnapshotStatus snapshotStatus = client.admin().cluster().prepareSnapshotStatus("test-repo")
|
||||||
.setSnapshots("test-2").get().getSnapshots().get(0);
|
.setSnapshots("test-2").get().getSnapshots().get(0);
|
||||||
|
Settings settings = client.admin().indices().prepareGetSettings("test").get().getIndexToSettings().get("test");
|
||||||
List<SnapshotIndexShardStatus> shards = snapshotStatus.getShards();
|
List<SnapshotIndexShardStatus> shards = snapshotStatus.getShards();
|
||||||
for (SnapshotIndexShardStatus status : shards) {
|
for (SnapshotIndexShardStatus status : shards) {
|
||||||
// we flush before the snapshot such that we have to process the segments_N files plus the .del file
|
// we flush before the snapshot such that we have to process the segments_N files plus the .del file
|
||||||
if (INDEX_SOFT_DELETES_SETTING.get(indexSettings)) {
|
if (INDEX_SOFT_DELETES_SETTING.get(settings)) {
|
||||||
// soft-delete generates DV files.
|
// soft-delete generates DV files.
|
||||||
assertThat(status.getStats().getProcessedFileCount(), greaterThan(2));
|
assertThat(status.getStats().getProcessedFileCount(), greaterThan(2));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -11,7 +11,6 @@ import org.apache.logging.log4j.Logger;
|
||||||
import org.apache.logging.log4j.message.ParameterizedMessage;
|
import org.apache.logging.log4j.message.ParameterizedMessage;
|
||||||
import org.elasticsearch.ElasticsearchException;
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.ExceptionsHelper;
|
import org.elasticsearch.ExceptionsHelper;
|
||||||
import org.elasticsearch.Version;
|
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
||||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
||||||
|
@ -448,9 +447,7 @@ public class AutoFollowCoordinator implements ClusterStateListener {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final Settings leaderIndexSettings = remoteMetadata.getIndexSafe(indexToFollow).getSettings();
|
final Settings leaderIndexSettings = remoteMetadata.getIndexSafe(indexToFollow).getSettings();
|
||||||
if (leaderIndexSettings.getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(),
|
if (IndexSettings.INDEX_SOFT_DELETES_SETTING.get(leaderIndexSettings) == false) {
|
||||||
IndexMetaData.SETTING_INDEX_VERSION_CREATED.get(leaderIndexSettings).onOrAfter(Version.V_7_0_0)) == false) {
|
|
||||||
|
|
||||||
String message = String.format(Locale.ROOT, "index [%s] cannot be followed, because soft deletes are not enabled",
|
String message = String.format(Locale.ROOT, "index [%s] cannot be followed, because soft deletes are not enabled",
|
||||||
indexToFollow.getName());
|
indexToFollow.getName());
|
||||||
LOGGER.warn(message);
|
LOGGER.warn(message);
|
||||||
|
|
|
@ -9,7 +9,6 @@ package org.elasticsearch.xpack.ccr.action;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.apache.logging.log4j.message.ParameterizedMessage;
|
import org.apache.logging.log4j.message.ParameterizedMessage;
|
||||||
import org.elasticsearch.Version;
|
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreClusterStateListener;
|
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreClusterStateListener;
|
||||||
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest;
|
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest;
|
||||||
|
@ -124,9 +123,7 @@ public final class TransportPutFollowAction
|
||||||
listener.onFailure(new IllegalArgumentException("leader index [" + request.getLeaderIndex() + "] does not exist"));
|
listener.onFailure(new IllegalArgumentException("leader index [" + request.getLeaderIndex() + "] does not exist"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// soft deletes are enabled by default on indices created on 7.0.0 or later
|
if (IndexSettings.INDEX_SOFT_DELETES_SETTING.get(leaderIndexMetaData.getSettings()) == false) {
|
||||||
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() +
|
listener.onFailure(new IllegalArgumentException("leader index [" + request.getLeaderIndex() +
|
||||||
"] does not have soft deletes enabled"));
|
"] does not have soft deletes enabled"));
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
package org.elasticsearch.xpack.ccr.action;
|
package org.elasticsearch.xpack.ccr.action;
|
||||||
|
|
||||||
import org.elasticsearch.Version;
|
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.support.ActionFilters;
|
import org.elasticsearch.action.support.ActionFilters;
|
||||||
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
||||||
|
@ -214,9 +213,7 @@ public class TransportResumeFollowAction extends TransportMasterNodeAction<Resum
|
||||||
"] as history uuid");
|
"] as history uuid");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// soft deletes are enabled by default on indices created on 7.0.0 or later
|
if (IndexSettings.INDEX_SOFT_DELETES_SETTING.get(leaderIndex.getSettings()) == false) {
|
||||||
if (leaderIndex.getSettings().getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(),
|
|
||||||
IndexMetaData.SETTING_INDEX_VERSION_CREATED.get(leaderIndex.getSettings()).onOrAfter(Version.V_7_0_0)) == false) {
|
|
||||||
throw new IllegalArgumentException("leader index [" + leaderIndex.getIndex().getName() +
|
throw new IllegalArgumentException("leader index [" + leaderIndex.getIndex().getName() +
|
||||||
"] does not have soft deletes enabled");
|
"] does not have soft deletes enabled");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue