Skip to content

Commit 3b2a0d7

Browse files
authored
Rename no-master-block setting (#38350)
Replaces `discovery.zen.no_master_block` with `cluster.no_master_block`. Any value set for the old setting is now ignored.
1 parent 2d114a0 commit 3b2a0d7

File tree

25 files changed

+268
-112
lines changed

25 files changed

+268
-112
lines changed

docs/reference/migration/migrate_7_0/discovery.asciidoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,11 @@ file:
3838
- `discovery.seed_hosts`
3939
- `discovery.seed_providers`
4040
- `cluster.initial_master_nodes`
41+
42+
[float]
43+
==== New name for `no_master_block` setting
44+
45+
The `discovery.zen.no_master_block` setting is now known as
46+
`cluster.no_master_block`. Any value set for `discovery.zen.no_master_block` is
47+
now ignored. You should remove this setting and, if needed, set
48+
`cluster.no_master_block` appropriately after the upgrade.

docs/reference/modules/discovery/discovery-settings.asciidoc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Discovery and cluster formation are affected by the following settings:
134134
the addresses of seed nodes. By default, it is the
135135
<<settings-based-hosts-provider,settings-based hosts provider>>.
136136

137-
[[no-master-block]]`discovery.zen.no_master_block`::
137+
[[no-master-block]]`cluster.no_master_block`::
138138
Specifies which operations are rejected when there is no active master in a
139139
cluster. This setting has two valid values:
140140
+
@@ -150,12 +150,16 @@ cluster.
150150

151151
[NOTE]
152152
===============================
153-
* The `discovery.zen.no_master_block` setting doesn't apply to nodes-based APIs
153+
* The `cluster.no_master_block` setting doesn't apply to nodes-based APIs
154154
(for example, cluster stats, node info, and node stats APIs). Requests to these
155155
APIs are not be blocked and can run on any available node.
156156
157157
* For the cluster to be fully operational, it must have an active master.
158158
===============================
159+
160+
WARNING: This setting replaces the `discovery.zen.no_master_block` setting in
161+
earlier versions. The `discovery.zen.no_master_block` setting is ignored.
162+
159163
--
160164

161165
`discovery.seed_hosts`::

modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/RankEvalResponseTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.action.search.SearchPhaseExecutionException;
2525
import org.elasticsearch.action.search.ShardSearchFailure;
2626
import org.elasticsearch.cluster.block.ClusterBlockException;
27+
import org.elasticsearch.cluster.coordination.NoMasterBlockService;
2728
import org.elasticsearch.common.ParsingException;
2829
import org.elasticsearch.common.breaker.CircuitBreaker;
2930
import org.elasticsearch.common.breaker.CircuitBreakingException;
@@ -37,7 +38,6 @@
3738
import org.elasticsearch.common.xcontent.XContentLocation;
3839
import org.elasticsearch.common.xcontent.XContentParser;
3940
import org.elasticsearch.common.xcontent.XContentType;
40-
import org.elasticsearch.discovery.DiscoverySettings;
4141
import org.elasticsearch.index.shard.ShardId;
4242
import org.elasticsearch.search.SearchHit;
4343
import org.elasticsearch.search.SearchParseException;
@@ -64,7 +64,7 @@
6464
public class RankEvalResponseTests extends ESTestCase {
6565

6666
private static final Exception[] RANDOM_EXCEPTIONS = new Exception[] {
67-
new ClusterBlockException(singleton(DiscoverySettings.NO_MASTER_BLOCK_WRITES)),
67+
new ClusterBlockException(singleton(NoMasterBlockService.NO_MASTER_BLOCK_WRITES)),
6868
new CircuitBreakingException("Data too large", 123, 456, CircuitBreaker.Durability.PERMANENT),
6969
new SearchParseException(new TestSearchContext(null), "Parse failure", new XContentLocation(12, 98)),
7070
new IllegalArgumentException("Closed resource", new RuntimeException("Resource")),

server/src/main/java/org/elasticsearch/cluster/coordination/Coordinator.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import org.elasticsearch.common.xcontent.XContentHelper;
5959
import org.elasticsearch.common.xcontent.json.JsonXContent;
6060
import org.elasticsearch.discovery.Discovery;
61-
import org.elasticsearch.discovery.DiscoverySettings;
6261
import org.elasticsearch.discovery.DiscoveryStats;
6362
import org.elasticsearch.discovery.HandshakingTransportAddressConnector;
6463
import org.elasticsearch.discovery.PeerFinder;
@@ -82,7 +81,7 @@
8281
import java.util.stream.Collectors;
8382
import java.util.stream.StreamSupport;
8483

85-
import static org.elasticsearch.discovery.DiscoverySettings.NO_MASTER_BLOCK_ID;
84+
import static org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_ID;
8685
import static org.elasticsearch.gateway.ClusterStateUpdaters.hideStateIfNotRecovered;
8786
import static org.elasticsearch.gateway.GatewayService.STATE_NOT_RECOVERED_BLOCK;
8887

@@ -103,7 +102,7 @@ public class Coordinator extends AbstractLifecycleComponent implements Discovery
103102
private final JoinHelper joinHelper;
104103
private final NodeRemovalClusterStateTaskExecutor nodeRemovalExecutor;
105104
private final Supplier<CoordinationState.PersistedState> persistedStateSupplier;
106-
private final DiscoverySettings discoverySettings;
105+
private final NoMasterBlockService noMasterBlockService;
107106
// TODO: the following field is package-private as some tests require access to it
108107
// These tests can be rewritten to use public methods once Coordinator is more feature-complete
109108
final Object mutex = new Object();
@@ -149,7 +148,7 @@ public Coordinator(String nodeName, Settings settings, ClusterSettings clusterSe
149148
this.joinHelper = new JoinHelper(settings, allocationService, masterService, transportService,
150149
this::getCurrentTerm, this::getStateForMasterService, this::handleJoinRequest, this::joinLeaderInTerm, this.onJoinValidators);
151150
this.persistedStateSupplier = persistedStateSupplier;
152-
this.discoverySettings = new DiscoverySettings(settings, clusterSettings);
151+
this.noMasterBlockService = new NoMasterBlockService(settings, clusterSettings);
153152
this.lastKnownLeader = Optional.empty();
154153
this.lastJoin = Optional.empty();
155154
this.joinAccumulator = new InitialJoinAccumulator();
@@ -632,7 +631,7 @@ protected void doStart() {
632631
ClusterState initialState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings))
633632
.blocks(ClusterBlocks.builder()
634633
.addGlobalBlock(STATE_NOT_RECOVERED_BLOCK)
635-
.addGlobalBlock(discoverySettings.getNoMasterBlock()))
634+
.addGlobalBlock(noMasterBlockService.getNoMasterBlock()))
636635
.nodes(DiscoveryNodes.builder().add(getLocalNode()).localNodeId(getLocalNode().getId()))
637636
.build();
638637
applierState = initialState;
@@ -934,7 +933,7 @@ private ClusterState clusterStateWithNoMasterBlock(ClusterState clusterState) {
934933
assert clusterState.blocks().hasGlobalBlockWithId(NO_MASTER_BLOCK_ID) == false :
935934
"NO_MASTER_BLOCK should only be added by Coordinator";
936935
final ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(clusterState.blocks()).addGlobalBlock(
937-
discoverySettings.getNoMasterBlock()).build();
936+
noMasterBlockService.getNoMasterBlock()).build();
938937
final DiscoveryNodes discoveryNodes = new DiscoveryNodes.Builder(clusterState.nodes()).masterNodeId(null).build();
939938
return ClusterState.builder(clusterState).blocks(clusterBlocks).nodes(discoveryNodes).build();
940939
} else {

server/src/main/java/org/elasticsearch/cluster/coordination/JoinTaskExecutor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.elasticsearch.cluster.node.DiscoveryNodes;
3131
import org.elasticsearch.cluster.routing.allocation.AllocationService;
3232
import org.elasticsearch.common.settings.Settings;
33-
import org.elasticsearch.discovery.DiscoverySettings;
3433
import org.elasticsearch.discovery.zen.ElectMasterService;
3534
import org.elasticsearch.persistent.PersistentTasksCustomMetaData;
3635

@@ -191,7 +190,7 @@ protected ClusterState.Builder becomeMasterAndTrimConflictingNodes(ClusterState
191190
// or removed by us above
192191
ClusterState tmpState = ClusterState.builder(currentState).nodes(nodesBuilder).blocks(ClusterBlocks.builder()
193192
.blocks(currentState.blocks())
194-
.removeGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID))
193+
.removeGlobalBlock(NoMasterBlockService.NO_MASTER_BLOCK_ID))
195194
.minimumMasterNodesOnPublishingMaster(minimumMasterNodesOnLocalNode)
196195
.build();
197196
logger.trace("becomeMasterAndTrimConflictingNodes: {}", tmpState.nodes());
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.elasticsearch.cluster.coordination;
20+
21+
import org.elasticsearch.cluster.block.ClusterBlock;
22+
import org.elasticsearch.cluster.block.ClusterBlockLevel;
23+
import org.elasticsearch.common.settings.ClusterSettings;
24+
import org.elasticsearch.common.settings.Setting;
25+
import org.elasticsearch.common.settings.Setting.Property;
26+
import org.elasticsearch.common.settings.Settings;
27+
import org.elasticsearch.rest.RestStatus;
28+
29+
import java.util.EnumSet;
30+
31+
public class NoMasterBlockService {
32+
public static final int NO_MASTER_BLOCK_ID = 2;
33+
public static final ClusterBlock NO_MASTER_BLOCK_WRITES = new ClusterBlock(NO_MASTER_BLOCK_ID, "no master", true, false, false,
34+
RestStatus.SERVICE_UNAVAILABLE, EnumSet.of(ClusterBlockLevel.WRITE, ClusterBlockLevel.METADATA_WRITE));
35+
public static final ClusterBlock NO_MASTER_BLOCK_ALL = new ClusterBlock(NO_MASTER_BLOCK_ID, "no master", true, true, false,
36+
RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL);
37+
38+
public static final Setting<ClusterBlock> LEGACY_NO_MASTER_BLOCK_SETTING =
39+
new Setting<>("discovery.zen.no_master_block", "write", NoMasterBlockService::parseNoMasterBlock,
40+
Property.Dynamic, Property.NodeScope, Property.Deprecated);
41+
public static final Setting<ClusterBlock> NO_MASTER_BLOCK_SETTING =
42+
new Setting<>("cluster.no_master_block", "write", NoMasterBlockService::parseNoMasterBlock,
43+
Property.Dynamic, Property.NodeScope);
44+
45+
private volatile ClusterBlock noMasterBlock;
46+
47+
public NoMasterBlockService(Settings settings, ClusterSettings clusterSettings) {
48+
this.noMasterBlock = NO_MASTER_BLOCK_SETTING.get(settings);
49+
clusterSettings.addSettingsUpdateConsumer(NO_MASTER_BLOCK_SETTING, this::setNoMasterBlock);
50+
51+
LEGACY_NO_MASTER_BLOCK_SETTING.get(settings); // for deprecation warnings
52+
clusterSettings.addSettingsUpdateConsumer(LEGACY_NO_MASTER_BLOCK_SETTING, b -> {}); // for deprecation warnings
53+
}
54+
55+
private static ClusterBlock parseNoMasterBlock(String value) {
56+
switch (value) {
57+
case "all":
58+
return NO_MASTER_BLOCK_ALL;
59+
case "write":
60+
return NO_MASTER_BLOCK_WRITES;
61+
default:
62+
throw new IllegalArgumentException("invalid no-master block [" + value + "], must be one of [all, write]");
63+
}
64+
}
65+
66+
public ClusterBlock getNoMasterBlock() {
67+
return noMasterBlock;
68+
}
69+
70+
private void setNoMasterBlock(ClusterBlock noMasterBlock) {
71+
this.noMasterBlock = noMasterBlock;
72+
}
73+
}

server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.elasticsearch.cluster.coordination.JoinHelper;
4242
import org.elasticsearch.cluster.coordination.LagDetector;
4343
import org.elasticsearch.cluster.coordination.LeaderChecker;
44+
import org.elasticsearch.cluster.coordination.NoMasterBlockService;
4445
import org.elasticsearch.cluster.coordination.Reconfigurator;
4546
import org.elasticsearch.cluster.metadata.IndexGraveyard;
4647
import org.elasticsearch.cluster.metadata.MetaData;
@@ -232,7 +233,8 @@ public void apply(Settings value, Settings current, Settings previous) {
232233
DiscoverySettings.PUBLISH_TIMEOUT_SETTING,
233234
DiscoverySettings.PUBLISH_DIFF_ENABLE_SETTING,
234235
DiscoverySettings.COMMIT_TIMEOUT_SETTING,
235-
DiscoverySettings.NO_MASTER_BLOCK_SETTING,
236+
NoMasterBlockService.NO_MASTER_BLOCK_SETTING,
237+
NoMasterBlockService.LEGACY_NO_MASTER_BLOCK_SETTING,
236238
GatewayService.EXPECTED_DATA_NODES_SETTING,
237239
GatewayService.EXPECTED_MASTER_NODES_SETTING,
238240
GatewayService.EXPECTED_NODES_SETTING,

server/src/main/java/org/elasticsearch/discovery/DiscoverySettings.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,17 @@
1919

2020
package org.elasticsearch.discovery;
2121

22-
import org.elasticsearch.cluster.block.ClusterBlock;
23-
import org.elasticsearch.cluster.block.ClusterBlockLevel;
2422
import org.elasticsearch.common.settings.ClusterSettings;
2523
import org.elasticsearch.common.settings.Setting;
2624
import org.elasticsearch.common.settings.Setting.Property;
2725
import org.elasticsearch.common.settings.Settings;
2826
import org.elasticsearch.common.unit.TimeValue;
29-
import org.elasticsearch.rest.RestStatus;
30-
31-
import java.util.EnumSet;
3227

3328
/**
3429
* Exposes common discovery settings that may be supported by all the different discovery implementations
3530
*/
3631
public class DiscoverySettings {
3732

38-
public static final int NO_MASTER_BLOCK_ID = 2;
39-
public static final ClusterBlock NO_MASTER_BLOCK_ALL = new ClusterBlock(NO_MASTER_BLOCK_ID, "no master", true, true, false,
40-
RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL);
41-
public static final ClusterBlock NO_MASTER_BLOCK_WRITES = new ClusterBlock(NO_MASTER_BLOCK_ID, "no master", true, false, false,
42-
RestStatus.SERVICE_UNAVAILABLE, EnumSet.of(ClusterBlockLevel.WRITE, ClusterBlockLevel.METADATA_WRITE));
4333
/**
4434
* sets the timeout for a complete publishing cycle, including both sending and committing. the master
4535
* will continue to process the next cluster state update after this time has elapsed
@@ -56,26 +46,20 @@ public class DiscoverySettings {
5646
new Setting<>("discovery.zen.commit_timeout", PUBLISH_TIMEOUT_SETTING::getRaw,
5747
(s) -> TimeValue.parseTimeValue(s, TimeValue.timeValueSeconds(30), "discovery.zen.commit_timeout"),
5848
Property.Dynamic, Property.NodeScope, Property.Deprecated);
59-
public static final Setting<ClusterBlock> NO_MASTER_BLOCK_SETTING =
60-
new Setting<>("discovery.zen.no_master_block", "write", DiscoverySettings::parseNoMasterBlock,
61-
Property.Dynamic, Property.NodeScope);
6249
public static final Setting<Boolean> PUBLISH_DIFF_ENABLE_SETTING =
6350
Setting.boolSetting("discovery.zen.publish_diff.enable", true, Property.Dynamic, Property.NodeScope, Property.Deprecated);
6451
public static final Setting<TimeValue> INITIAL_STATE_TIMEOUT_SETTING =
6552
Setting.positiveTimeSetting("discovery.initial_state_timeout", TimeValue.timeValueSeconds(30), Property.NodeScope);
6653

67-
private volatile ClusterBlock noMasterBlock;
6854
private volatile TimeValue publishTimeout;
6955

7056
private volatile TimeValue commitTimeout;
7157
private volatile boolean publishDiff;
7258

7359
public DiscoverySettings(Settings settings, ClusterSettings clusterSettings) {
74-
clusterSettings.addSettingsUpdateConsumer(NO_MASTER_BLOCK_SETTING, this::setNoMasterBlock);
7560
clusterSettings.addSettingsUpdateConsumer(PUBLISH_DIFF_ENABLE_SETTING, this::setPublishDiff);
7661
clusterSettings.addSettingsUpdateConsumer(COMMIT_TIMEOUT_SETTING, this::setCommitTimeout);
7762
clusterSettings.addSettingsUpdateConsumer(PUBLISH_TIMEOUT_SETTING, this::setPublishTimeout);
78-
this.noMasterBlock = NO_MASTER_BLOCK_SETTING.get(settings);
7963
this.publishTimeout = PUBLISH_TIMEOUT_SETTING.get(settings);
8064
this.commitTimeout = COMMIT_TIMEOUT_SETTING.get(settings);
8165
this.publishDiff = PUBLISH_DIFF_ENABLE_SETTING.get(settings);
@@ -92,14 +76,6 @@ public TimeValue getCommitTimeout() {
9276
return commitTimeout;
9377
}
9478

95-
public ClusterBlock getNoMasterBlock() {
96-
return noMasterBlock;
97-
}
98-
99-
private void setNoMasterBlock(ClusterBlock noMasterBlock) {
100-
this.noMasterBlock = noMasterBlock;
101-
}
102-
10379
private void setPublishDiff(boolean publishDiff) {
10480
this.publishDiff = publishDiff;
10581
}
@@ -114,14 +90,4 @@ private void setCommitTimeout(TimeValue commitTimeout) {
11490

11591
public boolean getPublishDiff() { return publishDiff;}
11692

117-
private static ClusterBlock parseNoMasterBlock(String value) {
118-
switch (value) {
119-
case "all":
120-
return NO_MASTER_BLOCK_ALL;
121-
case "write":
122-
return NO_MASTER_BLOCK_WRITES;
123-
default:
124-
throw new IllegalArgumentException("invalid master block [" + value + "]");
125-
}
126-
}
12793
}

0 commit comments

Comments
 (0)