Deprecate delaying state recovery for master nodes (#53646)

It is useful to be able to delay state recovery until enough data nodes have
joined the cluster, since this gives the shard allocator a decent opportunity
to re-use as much existing data as possible. However we also have the option to
delay state recovery until a certain number of master-eligible nodes have
joined, and this is unnecessary: we require a majority of master-eligible nodes
for state recovery, and there is no advantage in waiting for more.

This commit deprecates the unnecessary settings in preparation for their
removal.

Relates #51806
This commit is contained in:
Tianlun Li 2020-03-18 03:03:21 -07:00 committed by David Turner
parent ec13c093df
commit e7ae9ae596
3 changed files with 30 additions and 17 deletions

View File

@ -10,12 +10,14 @@ recover the cluster state and the cluster's data:
`gateway.expected_nodes`:: `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. 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 Recovery of local shards will start as soon as the expected number of
nodes have joined the cluster. Defaults to `0` nodes have joined the cluster. Defaults to `0`
`gateway.expected_master_nodes`:: `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. 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 Recovery of local shards will start as soon as the expected number of
master nodes have joined the cluster. Defaults to `0` master nodes have joined the cluster. Defaults to `0`
@ -37,10 +39,12 @@ as long as the following conditions are met:
`gateway.recover_after_nodes`:: `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. Recover as long as this many data or master nodes have joined the cluster.
`gateway.recover_after_master_nodes`:: `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. Recover as long as this many master nodes have joined the cluster.
`gateway.recover_after_data_nodes`:: `gateway.recover_after_data_nodes`::
@ -53,8 +57,8 @@ NOTE: These settings only take effect on a full cluster restart.
=== Dangling indices === Dangling indices
When a node joins the cluster, any shards stored in its local data 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 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 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 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 the other indices in the cluster, adding the old nodes will cause the old
indices to be imported, instead of being deleted. indices to be imported, instead of being deleted.

View File

@ -51,19 +51,19 @@ public class GatewayService extends AbstractLifecycleComponent implements Cluste
private static final Logger logger = LogManager.getLogger(GatewayService.class); private static final Logger logger = LogManager.getLogger(GatewayService.class);
public static final Setting<Integer> EXPECTED_NODES_SETTING = public static final Setting<Integer> 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<Integer> EXPECTED_DATA_NODES_SETTING = public static final Setting<Integer> EXPECTED_DATA_NODES_SETTING =
Setting.intSetting("gateway.expected_data_nodes", -1, -1, Property.NodeScope); Setting.intSetting("gateway.expected_data_nodes", -1, -1, Property.NodeScope);
public static final Setting<Integer> EXPECTED_MASTER_NODES_SETTING = public static final Setting<Integer> 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<TimeValue> RECOVER_AFTER_TIME_SETTING = public static final Setting<TimeValue> RECOVER_AFTER_TIME_SETTING =
Setting.positiveTimeSetting("gateway.recover_after_time", TimeValue.timeValueMillis(0), Property.NodeScope); Setting.positiveTimeSetting("gateway.recover_after_time", TimeValue.timeValueMillis(0), Property.NodeScope);
public static final Setting<Integer> RECOVER_AFTER_NODES_SETTING = public static final Setting<Integer> 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<Integer> RECOVER_AFTER_DATA_NODES_SETTING = public static final Setting<Integer> RECOVER_AFTER_DATA_NODES_SETTING =
Setting.intSetting("gateway.recover_after_data_nodes", -1, -1, Property.NodeScope); Setting.intSetting("gateway.recover_after_data_nodes", -1, -1, Property.NodeScope);
public static final Setting<Integer> RECOVER_AFTER_MASTER_NODES_SETTING = public static final Setting<Integer> 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, public static final ClusterBlock STATE_NOT_RECOVERED_BLOCK = new ClusterBlock(1, "state not recovered / initialized", true, true,
false, RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL); false, RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL);

View File

@ -21,6 +21,7 @@ package org.elasticsearch.gateway;
import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
@ -40,24 +41,32 @@ public class GatewayServiceTests extends ESTestCase {
GatewayService service = createService(Settings.builder()); GatewayService service = createService(Settings.builder());
assertNull(service.recoverAfterTime()); 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 // ensure default is set when setting expected_data_nodes
service = createService(Settings.builder().put("gateway.expected_data_nodes", 1)); 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)); 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 // ensure settings override default
final TimeValue timeValue = TimeValue.timeValueHours(3); final TimeValue timeValue = TimeValue.timeValueHours(3);
// ensure default is set when setting expected_nodes // 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())); timeValue.toString()));
assertThat(service.recoverAfterTime().millis(), Matchers.equalTo(timeValue.millis())); 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 });
}
} }