81
81
import java .util .stream .StreamSupport ;
82
82
83
83
import static org .elasticsearch .common .util .concurrent .ConcurrentCollections .newConcurrentSet ;
84
- import static org .elasticsearch .discovery .DiscoverySettings .NO_MASTER_BLOCK_WRITES ;
84
+ import static org .elasticsearch .discovery .DiscoverySettings .NO_MASTER_BLOCK_ID ;
85
85
import static org .elasticsearch .gateway .ClusterStateUpdaters .hideStateIfNotRecovered ;
86
86
import static org .elasticsearch .gateway .GatewayService .STATE_NOT_RECOVERED_BLOCK ;
87
87
@@ -102,6 +102,7 @@ public class Coordinator extends AbstractLifecycleComponent implements Discovery
102
102
private final JoinHelper joinHelper ;
103
103
private final NodeRemovalClusterStateTaskExecutor nodeRemovalExecutor ;
104
104
private final Supplier <CoordinationState .PersistedState > persistedStateSupplier ;
105
+ private final DiscoverySettings discoverySettings ;
105
106
// TODO: the following two fields are package-private as some tests require access to them
106
107
// These tests can be rewritten to use public methods once Coordinator is more feature-complete
107
108
final Object mutex = new Object ();
@@ -147,6 +148,7 @@ public Coordinator(String nodeName, Settings settings, ClusterSettings clusterSe
147
148
this .joinHelper = new JoinHelper (settings , allocationService , masterService , transportService ,
148
149
this ::getCurrentTerm , this ::handleJoinRequest , this ::joinLeaderInTerm );
149
150
this .persistedStateSupplier = persistedStateSupplier ;
151
+ this .discoverySettings = new DiscoverySettings (settings , clusterSettings );
150
152
this .lastKnownLeader = Optional .empty ();
151
153
this .lastJoin = Optional .empty ();
152
154
this .joinAccumulator = new InitialJoinAccumulator ();
@@ -528,7 +530,7 @@ protected void doStart() {
528
530
ClusterState initialState = ClusterState .builder (ClusterName .CLUSTER_NAME_SETTING .get (settings ))
529
531
.blocks (ClusterBlocks .builder ()
530
532
.addGlobalBlock (STATE_NOT_RECOVERED_BLOCK )
531
- .addGlobalBlock (NO_MASTER_BLOCK_WRITES )) // TODO: allow dynamically configuring NO_MASTER_BLOCK_ALL
533
+ .addGlobalBlock (discoverySettings . getNoMasterBlock ()))
532
534
.nodes (DiscoveryNodes .builder ().add (getLocalNode ()).localNodeId (getLocalNode ().getId ()))
533
535
.build ();
534
536
applierState = initialState ;
@@ -568,7 +570,7 @@ public void invariant() {
568
570
assert peerFinder .getCurrentTerm () == getCurrentTerm ();
569
571
assert followersChecker .getFastResponseState ().term == getCurrentTerm () : followersChecker .getFastResponseState ();
570
572
assert followersChecker .getFastResponseState ().mode == getMode () : followersChecker .getFastResponseState ();
571
- assert (applierState .nodes ().getMasterNodeId () == null ) == applierState .blocks ().hasGlobalBlock (NO_MASTER_BLOCK_WRITES . id () );
573
+ assert (applierState .nodes ().getMasterNodeId () == null ) == applierState .blocks ().hasGlobalBlock (NO_MASTER_BLOCK_ID );
572
574
assert preVoteCollector .getPreVoteResponse ().equals (getPreVoteResponse ())
573
575
: preVoteCollector + " vs " + getPreVoteResponse ();
574
576
@@ -873,11 +875,10 @@ ClusterState getStateForMasterService() {
873
875
private ClusterState clusterStateWithNoMasterBlock (ClusterState clusterState ) {
874
876
if (clusterState .nodes ().getMasterNodeId () != null ) {
875
877
// remove block if it already exists before adding new one
876
- assert clusterState .blocks ().hasGlobalBlock (DiscoverySettings . NO_MASTER_BLOCK_ID ) == false :
878
+ assert clusterState .blocks ().hasGlobalBlock (NO_MASTER_BLOCK_ID ) == false :
877
879
"NO_MASTER_BLOCK should only be added by Coordinator" ;
878
- // TODO: allow dynamically configuring NO_MASTER_BLOCK_ALL
879
880
final ClusterBlocks clusterBlocks = ClusterBlocks .builder ().blocks (clusterState .blocks ()).addGlobalBlock (
880
- NO_MASTER_BLOCK_WRITES ).build ();
881
+ discoverySettings . getNoMasterBlock () ).build ();
881
882
final DiscoveryNodes discoveryNodes = new DiscoveryNodes .Builder (clusterState .nodes ()).masterNodeId (null ).build ();
882
883
return ClusterState .builder (clusterState ).blocks (clusterBlocks ).nodes (discoveryNodes ).build ();
883
884
} else {
0 commit comments