public void globalBlockedRaiseException(ClusterBlockLevel level) throws ClusterBlockException { ClusterBlockException blockException = globalBlockedException(level); if (blockException != null) { throw blockException; } }
@Override protected ClusterBlockException checkRequestBlock(ClusterState state, ClearIndicesCacheRequest request, String[] concreteIndices) { return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, concreteIndices); } }
private ClusterBlockException blockExceptions(final ClusterState state, final String indexName) { ClusterBlockLevel globalBlockLevel = globalBlockLevel(); if (globalBlockLevel != null) { ClusterBlockException blockException = state.blocks().globalBlockedException(globalBlockLevel); if (blockException != null) { return blockException; } } ClusterBlockLevel indexBlockLevel = indexBlockLevel(); if (indexBlockLevel != null) { ClusterBlockException blockException = state.blocks().indexBlockedException(indexBlockLevel, indexName); if (blockException != null) { return blockException; } } return null; }
public boolean indexBlocked(ClusterBlockLevel level, String index) { return globalBlocked(level) || blocksForIndex(level, index).isEmpty() == false; }
public ClusterBlockException globalBlockedException(ClusterBlockLevel level) { if (globalBlocked(level) == false) { return null; } return new ClusterBlockException(global(level)); }
@Override protected ClusterBlockException checkBlock(CreateSnapshotRequest request, ClusterState state) { // We are reading the cluster metadata and indices - so we need to check both blocks ClusterBlockException clusterBlockException = state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ); if (clusterBlockException != null) { return clusterBlockException; } return state.blocks() .indicesBlockedException(ClusterBlockLevel.READ, indexNameExpressionResolver.concreteIndexNames(state, request)); }
@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(); }
public ClusterBlockException indicesBlockedException(ClusterBlockLevel level, String[] indices) { boolean indexIsBlocked = false; for (String index : indices) { if (indexBlocked(level, index)) { indexIsBlocked = true; } } if (globalBlocked(level) == false && indexIsBlocked == false) { return null; } Function<String, Stream<ClusterBlock>> blocksForIndexAtLevel = index -> blocksForIndex(level, index).stream(); Stream<ClusterBlock> blocks = concat( global(level).stream(), Stream.of(indices).flatMap(blocksForIndexAtLevel)); return new ClusterBlockException(unmodifiableSet(blocks.collect(toSet()))); }
@Override protected void doExecute(MultiSearchRequest request, ActionListener<MultiSearchResponse> listener) { ClusterState clusterState = clusterService.state(); clusterState.blocks().globalBlockedRaiseException(ClusterBlockLevel.READ); int maxConcurrentSearches = request.maxConcurrentSearchRequests(); if (maxConcurrentSearches == MultiSearchRequest.MAX_CONCURRENT_SEARCH_REQUESTS_DEFAULT) { maxConcurrentSearches = defaultMaxConcurrentSearches(availableProcessors, clusterState); } Queue<SearchRequestSlot> searchRequestSlots = new ConcurrentLinkedQueue<>(); for (int i = 0; i < request.requests().size(); i++) { SearchRequest searchRequest = request.requests().get(i); searchRequestSlots.add(new SearchRequestSlot(searchRequest, i)); } int numRequests = request.requests().size(); final AtomicArray<MultiSearchResponse.Item> responses = new AtomicArray<>(numRequests); final AtomicInteger responseCounter = new AtomicInteger(numRequests); int numConcurrentSearches = Math.min(numRequests, maxConcurrentSearches); for (int i = 0; i < numConcurrentSearches; i++) { executeSearch(searchRequestSlots, responses, responseCounter, listener); } }
public void indexBlockedRaiseException(ClusterBlockLevel level, String index) throws ClusterBlockException { ClusterBlockException blockException = indexBlockedException(level, index); if (blockException != null) { throw blockException; } }
public ClusterBlockException indexBlockedException(ClusterBlockLevel level, String index) { if (!indexBlocked(level, index)) { return null; } Stream<ClusterBlock> blocks = concat( global(level).stream(), blocksForIndex(level, index).stream()); return new ClusterBlockException(unmodifiableSet(blocks.collect(toSet()))); }
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) { if (currentState.blocks().disableStatePersistence()) { return currentState; ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks()); RoutingTable.Builder routingTableBuilder = RoutingTable.builder(currentState.routingTable()); final Version minIndexCompatibilityVersion = currentState.getNodes().getMaxNodeVersion()
@Override public void clusterChanged(ClusterChangedEvent event) { if (event.state().blocks().disableStatePersistence() == false) { processDanglingIndices(event.state().metaData()); } } }
public ClusterBlocks build() { // We copy the block sets here in case of the builder is modified after build is called ImmutableOpenMap.Builder<String, Set<ClusterBlock>> indicesBuilder = ImmutableOpenMap.builder(indices.size()); for (Map.Entry<String, Set<ClusterBlock>> entry : indices.entrySet()) { indicesBuilder.put(entry.getKey(), unmodifiableSet(new HashSet<>(entry.getValue()))); } return new ClusterBlocks(unmodifiableSet(new HashSet<>(global)), indicesBuilder.build()); } }
protected AbstractSearchAsyncAction(ESLogger logger, SearchServiceTransportAction searchService, ClusterService clusterService, IndexNameExpressionResolver indexNameExpressionResolver, SearchPhaseController searchPhaseController, ThreadPool threadPool, SearchRequest request, ActionListener<SearchResponse> listener) { this.logger = logger; this.searchService = searchService; this.indexNameExpressionResolver = indexNameExpressionResolver; this.searchPhaseController = searchPhaseController; this.threadPool = threadPool; this.request = request; this.listener = listener; this.clusterState = clusterService.state(); nodes = clusterState.nodes(); clusterState.blocks().globalBlockedRaiseException(ClusterBlockLevel.READ); // TODO: I think startTime() should become part of ActionRequest and that should be used both for index name // date math expressions and $now in scripts. This way all apis will deal with now in the same way instead // of just for the _search api String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request.indicesOptions(), startTime(), request.indices()); for (String index : concreteIndices) { clusterState.blocks().indexBlockedRaiseException(ClusterBlockLevel.READ, index); } Map<String, Set<String>> routingMap = indexNameExpressionResolver.resolveSearchRouting(clusterState, request.routing(), request.indices()); shardsIts = clusterService.operationRouting().searchShards(clusterState, concreteIndices, routingMap, request.preference()); expectedSuccessfulOps = shardsIts.size(); // we need to add 1 for non active partition, since we count it in the total! expectedTotalOps = shardsIts.totalSizeWith1ForEmpty(); firstResults = new AtomicArray<>(shardsIts.size()); }
/** * Returns <code>true</code> iff non of the given have a {@link ClusterBlockLevel#METADATA_WRITE} in place where the * {@link ClusterBlock#isAllowReleaseResources()} returns <code>false</code>. This is used in places where resources will be released * like the deletion of an index to free up resources on nodes. * @param indices the indices to check */ public ClusterBlockException indicesAllowReleaseResources(String[] indices) { final Function<String, Stream<ClusterBlock>> blocksForIndexAtLevel = index -> blocksForIndex(ClusterBlockLevel.METADATA_WRITE, index).stream(); Stream<ClusterBlock> blocks = concat( global(ClusterBlockLevel.METADATA_WRITE).stream(), Stream.of(indices).flatMap(blocksForIndexAtLevel)).filter(clusterBlock -> clusterBlock.isAllowReleaseResources() == false); Set<ClusterBlock> clusterBlocks = unmodifiableSet(blocks.collect(toSet())); if (clusterBlocks.isEmpty()) { return null; } return new ClusterBlockException(clusterBlocks); }
public boolean indexBlocked(ClusterBlockLevel level, String index) { if (globalBlocked(level)) { return true; } ImmutableSet<ClusterBlock> indexBlocks = indices(level).get(index); if (indexBlocks != null && !indexBlocks.isEmpty()) { return true; } return false; }
@Override public ClusterBlocks readFrom(StreamInput in) throws IOException { ImmutableSet<ClusterBlock> global = readBlockSet(in); ImmutableMap.Builder<String, ImmutableSet<ClusterBlock>> indicesBuilder = ImmutableMap.builder(); int size = in.readVInt(); for (int j = 0; j < size; j++) { indicesBuilder.put(in.readString().intern(), readBlockSet(in)); } return new ClusterBlocks(global, indicesBuilder.build()); }