From 2548c0df7e14e9aa24869a9080958ac5edc88f00 Mon Sep 17 00:00:00 2001 From: ShawnLi1014 Date: Mon, 16 Mar 2020 20:28:14 -0700 Subject: [PATCH 1/2] Deprecated support for delaying state recovery pending master nodes --- docs/reference/modules/gateway.asciidoc | 12 ++++++--- .../elasticsearch/gateway/GatewayService.java | 8 +++--- .../gateway/GatewayServiceTests.java | 27 ++++++++++++------- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/docs/reference/modules/gateway.asciidoc b/docs/reference/modules/gateway.asciidoc index 2b0783c9de0b0..e31bae693b800 100644 --- a/docs/reference/modules/gateway.asciidoc +++ b/docs/reference/modules/gateway.asciidoc @@ -13,12 +13,14 @@ recover the cluster state and the cluster's data: The number of (data or master) nodes that are expected to be in the cluster. Recovery of local shards will start as soon as the expected number of nodes have joined the cluster. Defaults to `0` + Deprecated and will be removed in 8.0 `gateway.expected_master_nodes`:: The number of master nodes that are expected to be in the cluster. Recovery of local shards will start as soon as the expected number of master nodes have joined the cluster. Defaults to `0` + Deprecated and will be removed in 8.0 `gateway.expected_data_nodes`:: @@ -38,10 +40,12 @@ as long as the following conditions are met: `gateway.recover_after_nodes`:: Recover as long as this many data or master nodes have joined the cluster. + Deprecated and will be removed in 8.0 `gateway.recover_after_master_nodes`:: Recover as long as this many master nodes have joined the cluster. + Deprecated and will be removed in 8.0 `gateway.recover_after_data_nodes`:: @@ -53,8 +57,8 @@ NOTE: These settings only take effect on a full cluster restart. === Dangling indices When a node joins the cluster, any shards stored in its local data -directory which do not already exist in the cluster will be imported into the -cluster. This functionality is intended as a best effort to help users who -lose all master nodes. If a new master node is started which is unaware of -the other indices in the cluster, adding the old nodes will cause the old +directory which do not already exist in the cluster will be imported into the +cluster. This functionality is intended as a best effort to help users who +lose all master nodes. If a new master node is started which is unaware of +the other indices in the cluster, adding the old nodes will cause the old indices to be imported, instead of being deleted. diff --git a/server/src/main/java/org/elasticsearch/gateway/GatewayService.java b/server/src/main/java/org/elasticsearch/gateway/GatewayService.java index 86f05f398d1f8..5219988237850 100644 --- a/server/src/main/java/org/elasticsearch/gateway/GatewayService.java +++ b/server/src/main/java/org/elasticsearch/gateway/GatewayService.java @@ -51,19 +51,19 @@ public class GatewayService extends AbstractLifecycleComponent implements Cluste private static final Logger logger = LogManager.getLogger(GatewayService.class); public static final Setting EXPECTED_NODES_SETTING = - Setting.intSetting("gateway.expected_nodes", -1, -1, Property.NodeScope); + Setting.intSetting("gateway.expected_nodes", -1, -1, Property.NodeScope, Property.Deprecated); public static final Setting EXPECTED_DATA_NODES_SETTING = Setting.intSetting("gateway.expected_data_nodes", -1, -1, Property.NodeScope); public static final Setting EXPECTED_MASTER_NODES_SETTING = - Setting.intSetting("gateway.expected_master_nodes", -1, -1, Property.NodeScope); + Setting.intSetting("gateway.expected_master_nodes", -1, -1, Property.NodeScope, Property.Deprecated); public static final Setting RECOVER_AFTER_TIME_SETTING = Setting.positiveTimeSetting("gateway.recover_after_time", TimeValue.timeValueMillis(0), Property.NodeScope); public static final Setting RECOVER_AFTER_NODES_SETTING = - Setting.intSetting("gateway.recover_after_nodes", -1, -1, Property.NodeScope); + Setting.intSetting("gateway.recover_after_nodes", -1, -1, Property.NodeScope, Property.Deprecated); public static final Setting RECOVER_AFTER_DATA_NODES_SETTING = Setting.intSetting("gateway.recover_after_data_nodes", -1, -1, Property.NodeScope); public static final Setting RECOVER_AFTER_MASTER_NODES_SETTING = - Setting.intSetting("gateway.recover_after_master_nodes", 0, 0, Property.NodeScope); + Setting.intSetting("gateway.recover_after_master_nodes", 0, 0, Property.NodeScope, Property.Deprecated); public static final ClusterBlock STATE_NOT_RECOVERED_BLOCK = new ClusterBlock(1, "state not recovered / initialized", true, true, false, RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL); diff --git a/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java b/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java index 4049cec796102..41c6dc6f72ae7 100644 --- a/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java +++ b/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java @@ -21,6 +21,7 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.ClusterSettings; +import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.test.ESTestCase; @@ -40,24 +41,32 @@ public void testDefaultRecoverAfterTime() { GatewayService service = createService(Settings.builder()); assertNull(service.recoverAfterTime()); - // ensure default is set when setting expected_nodes - service = createService(Settings.builder().put("gateway.expected_nodes", 1)); - assertThat(service.recoverAfterTime(), Matchers.equalTo(GatewayService.DEFAULT_RECOVER_AFTER_TIME_IF_EXPECTED_NODES_IS_SET)); - // ensure default is set when setting expected_data_nodes service = createService(Settings.builder().put("gateway.expected_data_nodes", 1)); assertThat(service.recoverAfterTime(), Matchers.equalTo(GatewayService.DEFAULT_RECOVER_AFTER_TIME_IF_EXPECTED_NODES_IS_SET)); - // ensure default is set when setting expected_master_nodes - service = createService(Settings.builder().put("gateway.expected_master_nodes", 1)); - assertThat(service.recoverAfterTime(), Matchers.equalTo(GatewayService.DEFAULT_RECOVER_AFTER_TIME_IF_EXPECTED_NODES_IS_SET)); - // ensure settings override default final TimeValue timeValue = TimeValue.timeValueHours(3); // ensure default is set when setting expected_nodes - service = createService(Settings.builder().put("gateway.expected_nodes", 1).put("gateway.recover_after_time", + service = createService(Settings.builder().put("gateway.recover_after_time", timeValue.toString())); assertThat(service.recoverAfterTime().millis(), Matchers.equalTo(timeValue.millis())); } + public void testDeprecatedSettings() { + GatewayService service = createService(Settings.builder()); + + service = createService(Settings.builder().put("gateway.expected_nodes", 1)); + assertSettingDeprecationsAndWarnings(new Setting[] {GatewayService.EXPECTED_NODES_SETTING }); + + service = createService(Settings.builder().put("gateway.expected_master_nodes", 1)); + assertSettingDeprecationsAndWarnings(new Setting[] {GatewayService.EXPECTED_MASTER_NODES_SETTING }); + + service = createService(Settings.builder().put("gateway.recover_after_nodes", 1)); + assertSettingDeprecationsAndWarnings(new Setting[] {GatewayService.RECOVER_AFTER_NODES_SETTING }); + + service = createService(Settings.builder().put("gateway.recover_after_master_nodes", 1)); + assertSettingDeprecationsAndWarnings(new Setting[] {GatewayService.RECOVER_AFTER_MASTER_NODES_SETTING }); + } + } From e61c873cd4176ceeb094f749128b0dd2f69d635e Mon Sep 17 00:00:00 2001 From: Tianlun Li Date: Tue, 17 Mar 2020 21:57:48 -0700 Subject: [PATCH 2/2] Apply suggestions from code review Co-Authored-By: David Turner --- docs/reference/modules/gateway.asciidoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/reference/modules/gateway.asciidoc b/docs/reference/modules/gateway.asciidoc index e31bae693b800..c5bb5d1579c4f 100644 --- a/docs/reference/modules/gateway.asciidoc +++ b/docs/reference/modules/gateway.asciidoc @@ -10,17 +10,17 @@ recover the cluster state and the cluster's data: `gateway.expected_nodes`:: + deprecated:[7.7.0, This setting will be removed in 8.0. You should use `gateway.expected_data_nodes` instead.] The number of (data or master) nodes that are expected to be in the cluster. Recovery of local shards will start as soon as the expected number of nodes have joined the cluster. Defaults to `0` - Deprecated and will be removed in 8.0 `gateway.expected_master_nodes`:: + deprecated:[7.7.0, This setting will be removed in 8.0. You should use `gateway.expected_data_nodes` instead.] The number of master nodes that are expected to be in the cluster. Recovery of local shards will start as soon as the expected number of master nodes have joined the cluster. Defaults to `0` - Deprecated and will be removed in 8.0 `gateway.expected_data_nodes`:: @@ -39,13 +39,13 @@ as long as the following conditions are met: `gateway.recover_after_nodes`:: + deprecated:[7.7.0, This setting will be removed in 8.0. You should use `gateway.recover_after_data_nodes` instead.] Recover as long as this many data or master nodes have joined the cluster. - Deprecated and will be removed in 8.0 `gateway.recover_after_master_nodes`:: + deprecated:[7.7.0, This setting will be removed in 8.0. You should use `gateway.recover_after_data_nodes` instead.] Recover as long as this many master nodes have joined the cluster. - Deprecated and will be removed in 8.0 `gateway.recover_after_data_nodes`::