8181import java .util .stream .StreamSupport ;
8282
8383import 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 ;
8585import static org .elasticsearch .gateway .ClusterStateUpdaters .hideStateIfNotRecovered ;
8686import static org .elasticsearch .gateway .GatewayService .STATE_NOT_RECOVERED_BLOCK ;
8787
@@ -102,6 +102,7 @@ public class Coordinator extends AbstractLifecycleComponent implements Discovery
102102 private final JoinHelper joinHelper ;
103103 private final NodeRemovalClusterStateTaskExecutor nodeRemovalExecutor ;
104104 private final Supplier <CoordinationState .PersistedState > persistedStateSupplier ;
105+ private final DiscoverySettings discoverySettings ;
105106 // TODO: the following two fields are package-private as some tests require access to them
106107 // These tests can be rewritten to use public methods once Coordinator is more feature-complete
107108 final Object mutex = new Object ();
@@ -147,6 +148,7 @@ public Coordinator(String nodeName, Settings settings, ClusterSettings clusterSe
147148 this .joinHelper = new JoinHelper (settings , allocationService , masterService , transportService ,
148149 this ::getCurrentTerm , this ::handleJoinRequest , this ::joinLeaderInTerm );
149150 this .persistedStateSupplier = persistedStateSupplier ;
151+ this .discoverySettings = new DiscoverySettings (settings , clusterSettings );
150152 this .lastKnownLeader = Optional .empty ();
151153 this .lastJoin = Optional .empty ();
152154 this .joinAccumulator = new InitialJoinAccumulator ();
@@ -528,7 +530,7 @@ protected void doStart() {
528530 ClusterState initialState = ClusterState .builder (ClusterName .CLUSTER_NAME_SETTING .get (settings ))
529531 .blocks (ClusterBlocks .builder ()
530532 .addGlobalBlock (STATE_NOT_RECOVERED_BLOCK )
531- .addGlobalBlock (NO_MASTER_BLOCK_WRITES )) // TODO: allow dynamically configuring NO_MASTER_BLOCK_ALL
533+ .addGlobalBlock (discoverySettings . getNoMasterBlock ()))
532534 .nodes (DiscoveryNodes .builder ().add (getLocalNode ()).localNodeId (getLocalNode ().getId ()))
533535 .build ();
534536 applierState = initialState ;
@@ -568,7 +570,7 @@ public void invariant() {
568570 assert peerFinder .getCurrentTerm () == getCurrentTerm ();
569571 assert followersChecker .getFastResponseState ().term == getCurrentTerm () : followersChecker .getFastResponseState ();
570572 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 );
572574 assert preVoteCollector .getPreVoteResponse ().equals (getPreVoteResponse ())
573575 : preVoteCollector + " vs " + getPreVoteResponse ();
574576
@@ -873,11 +875,10 @@ ClusterState getStateForMasterService() {
873875 private ClusterState clusterStateWithNoMasterBlock (ClusterState clusterState ) {
874876 if (clusterState .nodes ().getMasterNodeId () != null ) {
875877 // 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 :
877879 "NO_MASTER_BLOCK should only be added by Coordinator" ;
878- // TODO: allow dynamically configuring NO_MASTER_BLOCK_ALL
879880 final ClusterBlocks clusterBlocks = ClusterBlocks .builder ().blocks (clusterState .blocks ()).addGlobalBlock (
880- NO_MASTER_BLOCK_WRITES ).build ();
881+ discoverySettings . getNoMasterBlock () ).build ();
881882 final DiscoveryNodes discoveryNodes = new DiscoveryNodes .Builder (clusterState .nodes ()).masterNodeId (null ).build ();
882883 return ClusterState .builder (clusterState ).blocks (clusterBlocks ).nodes (discoveryNodes ).build ();
883884 } else {
0 commit comments