protected void rejoin(String reason) { assert Thread.holdsLock(stateMutex); ClusterState clusterState = committedState.get(); logger.warn("{}, current nodes: {}", reason, clusterState.nodes()); nodesFD.stop(); masterFD.stop(reason); // TODO: do we want to force a new thread if we actively removed the master? this is to give a full pinging cycle // before a decision is made. joinThreadControl.startNewThreadIfNotRunning(); if (clusterState.nodes().getMasterNodeId() != null) { // remove block if it already exists before adding new one assert clusterState.blocks().hasGlobalBlock(discoverySettings.getNoMasterBlock().id()) == false : "NO_MASTER_BLOCK should only be added by ZenDiscovery"; ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(clusterState.blocks()) .addGlobalBlock(discoverySettings.getNoMasterBlock()) .build(); DiscoveryNodes discoveryNodes = new DiscoveryNodes.Builder(clusterState.nodes()).masterNodeId(null).build(); clusterState = ClusterState.builder(clusterState) .blocks(clusterBlocks) .nodes(discoveryNodes) .build(); committedState.set(clusterState); clusterApplier.onNewClusterState(reason, this::clusterState, (source, e) -> {}); // don't wait for state to be applied } }
@Override protected void doStart() { DiscoveryNode localNode = transportService.getLocalNode(); assert localNode != null; synchronized (stateMutex) { // set initial state assert committedState.get() == null; assert localNode != null; ClusterState.Builder builder = clusterApplier.newClusterStateBuilder(); ClusterState initialState = builder .blocks(ClusterBlocks.builder() .addGlobalBlock(STATE_NOT_RECOVERED_BLOCK) .addGlobalBlock(discoverySettings.getNoMasterBlock())) .nodes(DiscoveryNodes.builder().add(localNode).localNodeId(localNode.getId())) .build(); committedState.set(initialState); clusterApplier.setInitialState(initialState); nodesFD.setLocalNode(localNode); joinThreadControl.start(); } zenPing.start(); }
|| MetaData.SETTING_READ_ONLY_SETTING.get(metaData.transientSettings()); if (updatedReadOnly) { blocks.addGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK); } else { blocks.removeGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK); || MetaData.SETTING_READ_ONLY_ALLOW_DELETE_SETTING.get(metaData.transientSettings()); if (updatedReadOnlyAllowDelete) { blocks.addGlobalBlock(MetaData.CLUSTER_READ_ONLY_ALLOW_DELETE_BLOCK); } else { blocks.removeGlobalBlock(MetaData.CLUSTER_READ_ONLY_ALLOW_DELETE_BLOCK);
|| MetaData.SETTING_READ_ONLY_SETTING.get(metaData.transientSettings()); if (updatedReadOnly) { blocks.addGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK); } else { blocks.removeGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK); || MetaData.SETTING_READ_ONLY_ALLOW_DELETE_SETTING.get(metaData.transientSettings()); if (updatedReadOnlyAllowDelete) { blocks.addGlobalBlock(MetaData.CLUSTER_READ_ONLY_ALLOW_DELETE_BLOCK); } else { blocks.removeGlobalBlock(MetaData.CLUSTER_READ_ONLY_ALLOW_DELETE_BLOCK);
protected void rejoin(String reason) { assert Thread.holdsLock(stateMutex); ClusterState clusterState = committedState.get(); logger.warn("{}, current nodes: {}", reason, clusterState.nodes()); nodesFD.stop(); masterFD.stop(reason); // TODO: do we want to force a new thread if we actively removed the master? this is to give a full pinging cycle // before a decision is made. joinThreadControl.startNewThreadIfNotRunning(); if (clusterState.nodes().getMasterNodeId() != null) { // remove block if it already exists before adding new one assert clusterState.blocks().hasGlobalBlock(discoverySettings.getNoMasterBlock().id()) == false : "NO_MASTER_BLOCK should only be added by ZenDiscovery"; ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(clusterState.blocks()) .addGlobalBlock(discoverySettings.getNoMasterBlock()) .build(); DiscoveryNodes discoveryNodes = new DiscoveryNodes.Builder(clusterState.nodes()).masterNodeId(null).build(); clusterState = ClusterState.builder(clusterState) .blocks(clusterBlocks) .nodes(discoveryNodes) .build(); committedState.set(clusterState); clusterApplier.onNewClusterState(reason, this::clusterState, (source, e) -> {}); // don't wait for state to be applied } }
@Override public ClusterState execute(ClusterState currentState) { assert currentState.metaData().indices().isEmpty(); // remove the block, since we recovered from gateway ClusterBlocks.Builder blocks = ClusterBlocks.builder() .blocks(currentState.blocks()) .blocks(recoveredState.blocks()) .removeGlobalBlock(STATE_NOT_RECOVERED_BLOCK); MetaData.Builder metaDataBuilder = MetaData.builder(recoveredState.metaData()); // automatically generate a UID for the metadata if we need to metaDataBuilder.generateClusterUuidIfNeeded(); if (recoveredState.metaData().settings().getAsBoolean("cluster.blocks.read_only", false)) { blocks.addGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK); } for (IndexMetaData indexMetaData : recoveredState.metaData()) { metaDataBuilder.put(indexMetaData, false); blocks.addBlocks(indexMetaData); } // update the state to reflect the new metadata and routing ClusterState updatedState = ClusterState.builder(currentState) .blocks(blocks) .metaData(metaDataBuilder) .build(); RoutingTable newRoutingTable = RoutingTable.build(CassandraGatewayService.this.clusterService, updatedState); return ClusterState.builder(updatedState).incrementVersion().routingTable(newRoutingTable).build(); }
@Inject public InternalClusterService(Settings settings, DiscoveryService discoveryService, OperationRouting operationRouting, TransportService transportService, NodeSettingsService nodeSettingsService, ThreadPool threadPool, ClusterName clusterName, DiscoveryNodeService discoveryNodeService, Version version) { super(settings); this.operationRouting = operationRouting; this.transportService = transportService; this.discoveryService = discoveryService; this.threadPool = threadPool; this.nodeSettingsService = nodeSettingsService; this.discoveryNodeService = discoveryNodeService; this.version = version; // will be replaced on doStart. this.clusterState = ClusterState.builder(clusterName).build(); this.nodeSettingsService.setClusterService(this); this.nodeSettingsService.addListener(new ApplySettings()); this.reconnectInterval = this.settings.getAsTime(SETTING_CLUSTER_SERVICE_RECONNECT_INTERVAL, TimeValue.timeValueSeconds(10)); this.slowTaskLoggingThreshold = this.settings.getAsTime(SETTING_CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD, TimeValue.timeValueSeconds(30)); localNodeMasterListeners = new LocalNodeMasterListeners(threadPool); initialBlocks = ClusterBlocks.builder().addGlobalBlock(discoveryService.getNoMasterBlock()); taskManager = transportService.getTaskManager(); }
@Override protected void doStart() { DiscoveryNode localNode = transportService.getLocalNode(); assert localNode != null; synchronized (stateMutex) { // set initial state assert committedState.get() == null; assert localNode != null; ClusterState.Builder builder = clusterApplier.newClusterStateBuilder(); ClusterState initialState = builder .blocks(ClusterBlocks.builder() .addGlobalBlock(STATE_NOT_RECOVERED_BLOCK) .addGlobalBlock(discoverySettings.getNoMasterBlock())) .nodes(DiscoveryNodes.builder().add(localNode).localNodeId(localNode.getId())) .build(); committedState.set(initialState); clusterApplier.setInitialState(initialState); nodesFD.setLocalNode(localNode); joinThreadControl.start(); } zenPing.start(); }
@Override protected void doStart() { DiscoveryNode localNode = transportService.getLocalNode(); assert localNode != null; synchronized (stateMutex) { // set initial state assert committedState.get() == null; assert localNode != null; ClusterState.Builder builder = clusterApplier.newClusterStateBuilder(); ClusterState initialState = builder .blocks(ClusterBlocks.builder() .addGlobalBlock(STATE_NOT_RECOVERED_BLOCK) .addGlobalBlock(discoverySettings.getNoMasterBlock())) .nodes(DiscoveryNodes.builder().add(localNode).localNodeId(localNode.getId())) .build(); committedState.set(initialState); clusterApplier.setInitialState(initialState); nodesFD.setLocalNode(localNode); joinThreadControl.start(); } zenPing.start(); }
protected void rejoin(String reason) { assert Thread.holdsLock(stateMutex); ClusterState clusterState = committedState.get(); logger.warn("{}, current nodes: {}", reason, clusterState.nodes()); nodesFD.stop(); masterFD.stop(reason); // TODO: do we want to force a new thread if we actively removed the master? this is to give a full pinging cycle // before a decision is made. joinThreadControl.startNewThreadIfNotRunning(); if (clusterState.nodes().getMasterNodeId() != null) { // remove block if it already exists before adding new one assert clusterState.blocks().hasGlobalBlock(discoverySettings.getNoMasterBlock().id()) == false : "NO_MASTER_BLOCK should only be added by ZenDiscovery"; ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(clusterState.blocks()) .addGlobalBlock(discoverySettings.getNoMasterBlock()) .build(); DiscoveryNodes discoveryNodes = new DiscoveryNodes.Builder(clusterState.nodes()).masterNodeId(null).build(); clusterState = ClusterState.builder(clusterState) .blocks(clusterBlocks) .nodes(discoveryNodes) .build(); committedState.set(clusterState); clusterApplier.onNewClusterState(reason, this::clusterState, (source, e) -> {}); // don't wait for state to be applied } }
protected ClusterState rejoin(ClusterState clusterState, String reason) { // *** called from within an cluster state update task *** // assert Thread.currentThread().getName().contains(InternalClusterService.UPDATE_THREAD_NAME); logger.warn(reason + ", current nodes: {}", clusterState.nodes()); nodesFD.stop(); masterFD.stop(reason); ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(clusterState.blocks()) .addGlobalBlock(discoverySettings.getNoMasterBlock()) .build(); // clean the nodes, we are now not connected to anybody, since we try and reform the cluster DiscoveryNodes discoveryNodes = new DiscoveryNodes.Builder(clusterState.nodes()).masterNodeId(null).build(); // TODO: do we want to force a new thread if we actively removed the master? this is to give a full pinging cycle // before a decision is made. joinThreadControl.startNewThreadIfNotRunning(); return ClusterState.builder(clusterState) .blocks(clusterBlocks) .nodes(discoveryNodes) .build(); }
public BaseClusterService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool, Supplier<DiscoveryNode> localNodeSupplier) { super(settings); this.localNodeSupplier = localNodeSupplier; this.operationRouting = new OperationRouting(settings, clusterSettings); this.threadPool = threadPool; this.clusterSettings = clusterSettings; this.clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings); // will be replaced on doStart. this.state = new AtomicReference<>(ClusterState.builder(clusterName).build()); this.clusterSettings.addSettingsUpdateConsumer(CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING, this::setSlowTaskLoggingThreshold); this.slowTaskLoggingThreshold = CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING.get(settings); localNodeMasterListeners = new LocalNodeMasterListeners(threadPool); //initialBlocks = ClusterBlocks.builder(); // Add NO_CASSANDRA_RING_BLOCK to avoid to save metadata while cassandra ring not ready. initialBlocks = ClusterBlocks.builder().addGlobalBlock(CassandraGatewayService.NO_CASSANDRA_RING_BLOCK); }
@Override public ClusterState execute(ClusterState currentState) { // read metadata from the clusterService thread to avoid freeze in gossip. MetaData schemaMetaData = clusterService.checkForNewMetaData(version); ClusterState.Builder newStateBuilder = ClusterState.builder(currentState).nodes(nodes()); // update blocks ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks()); if (schemaMetaData.settings().getAsBoolean("cluster.blocks.read_only", false)) blocks.addGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK); if (schemaMetaData != null) { newStateBuilder.metaData(schemaMetaData); // update indices block. for (IndexMetaData indexMetaData : schemaMetaData) blocks.updateBlocks(indexMetaData); } return clusterService.updateNumberOfShardsAndReplicas( newStateBuilder.blocks(blocks).build() ); }
@Override protected ClusterState createInitialState(DiscoveryNode localNode) { ClusterBlocks.Builder clusterBlocks = ClusterBlocks.builder(); // don't add no_master / state recovery block if (BLOCKS_WRITE_SETTING.get(settings)) { clusterBlocks.addGlobalBlock(TRIBE_WRITE_BLOCK); } if (BLOCKS_METADATA_SETTING.get(settings)) { clusterBlocks.addGlobalBlock(TRIBE_METADATA_BLOCK); } return ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings)) .nodes(DiscoveryNodes.builder().add(localNode).localNodeId(localNode.getId()).build()) .blocks(clusterBlocks).build(); }
/** * Adds an initial block to be set on the first cluster state created. */ public synchronized void addInitialStateBlock(ClusterBlock block) throws IllegalStateException { if (lifecycle.started()) { throw new IllegalStateException("can't set initial block when started"); } initialBlocks.addGlobalBlock(block); }
@Override public void addInitialStateBlock(ClusterBlock block) throws IllegalStateException { if (lifecycle.started()) { throw new IllegalStateException("can't set initial block when started"); } initialBlocks.addGlobalBlock(block); }
protected ClusterState createInitialState(DiscoveryNode localNode) { ClusterState.Builder builder = clusterApplier.newClusterStateBuilder(); return builder.nodes(DiscoveryNodes.builder().add(localNode) .localNodeId(localNode.getId()) .masterNodeId(localNode.getId()) .build()) .blocks(ClusterBlocks.builder() .addGlobalBlock(STATE_NOT_RECOVERED_BLOCK)) .build(); }
protected ClusterState createInitialState(DiscoveryNode localNode) { ClusterState.Builder builder = clusterApplier.newClusterStateBuilder(); return builder.nodes(DiscoveryNodes.builder().add(localNode) .localNodeId(localNode.getId()) .masterNodeId(localNode.getId()) .build()) .blocks(ClusterBlocks.builder() .addGlobalBlock(STATE_NOT_RECOVERED_BLOCK)) .build(); }
blocks.addGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK); blocks.addGlobalBlock(MetaData.CLUSTER_READ_ONLY_ALLOW_DELETE_BLOCK);
protected ClusterState createInitialState(DiscoveryNode localNode) { ClusterState.Builder builder = clusterApplier.newClusterStateBuilder(); return builder.nodes(DiscoveryNodes.builder().add(localNode) .localNodeId(localNode.getId()) .masterNodeId(localNode.getId()) .build()) .blocks(ClusterBlocks.builder() .addGlobalBlock(STATE_NOT_RECOVERED_BLOCK)) .build(); }