static int defaultMaxConcurrentSearches(int availableProcessors, ClusterState state) { int numDateNodes = state.getNodes().getDataNodes().size(); // availableProcessors will never be larger than 32, so max defaultMaxConcurrentSearches will never be larger than 49, // but we don't know about about other search requests that are being executed so lets cap at 10 per node int defaultSearchThreadPoolSize = Math.min(ThreadPool.searchThreadPoolSize(availableProcessors), 10); return Math.max(1, numDateNodes * defaultSearchThreadPoolSize); }
/** * Fills the shard fetched data with new (data) nodes and a fresh NodeEntry, and removes from * it nodes that are no longer part of the state. */ private void fillShardCacheWithDataNodes(Map<String, NodeEntry<T>> shardCache, DiscoveryNodes nodes) { // verify that all current data nodes are there for (ObjectObjectCursor<String, DiscoveryNode> cursor : nodes.getDataNodes()) { DiscoveryNode node = cursor.value; if (shardCache.containsKey(node.getId()) == false) { shardCache.put(node.getId(), new NodeEntry<T>(node.getId())); } } // remove nodes that are not longer part of the data nodes set shardCache.keySet().removeIf(nodeId -> !nodes.nodeExists(nodeId)); }
private boolean hasDeadNodes(RoutingAllocation allocation) { for (RoutingNode routingNode : allocation.routingNodes()) { if (allocation.nodes().getDataNodes().containsKey(routingNode.nodeId()) == false) { return true; } } return false; }
continue; for (ObjectCursor<DiscoveryNode> cursor : entry.getValue().getState().nodes().getDataNodes().values()) { newNodes.add(cursor.value);
/** * Checks if the are replicas with the auto-expand feature that need to be adapted. * Returns a map of updates, which maps the indices to be updated to the desired number of replicas. * The map has the desired number of replicas as key and the indices to update as value, as this allows the result * of this method to be directly applied to RoutingTable.Builder#updateNumberOfReplicas. */ public static Map<Integer, List<String>> getAutoExpandReplicaChanges(MetaData metaData, DiscoveryNodes discoveryNodes) { // used for translating "all" to a number final int dataNodeCount = discoveryNodes.getDataNodes().size(); Map<Integer, List<String>> nrReplicasChanged = new HashMap<>(); for (final IndexMetaData indexMetaData : metaData) { if (indexMetaData.getState() != IndexMetaData.State.CLOSE) { AutoExpandReplicas autoExpandReplicas = SETTING.get(indexMetaData.getSettings()); autoExpandReplicas.getDesiredNumberOfReplicas(dataNodeCount).ifPresent(numberOfReplicas -> { if (numberOfReplicas != indexMetaData.getNumberOfReplicas()) { nrReplicasChanged.computeIfAbsent(numberOfReplicas, ArrayList::new).add(indexMetaData.getIndex().getName()); } }); } } return nrReplicasChanged; } }
@Override public void onMaster() { this.isMaster = true; if (logger.isTraceEnabled()) { logger.trace("I have been elected master, scheduling a ClusterInfoUpdateJob"); } try { // Submit a job that will start after DEFAULT_STARTING_INTERVAL, and reschedule itself after running threadPool.schedule(updateFrequency, executorName(), new SubmitReschedulingClusterInfoUpdatedJob()); if (clusterService.state().getNodes().getDataNodes().size() > 1) { // Submit an info update job to be run immediately threadPool.executor(executorName()).execute(() -> maybeRefresh()); } } catch (EsRejectedExecutionException ex) { if (logger.isDebugEnabled()) { logger.debug("Couldn't schedule cluster info update task - node might be shutting down", ex); } } }
for (ObjectCursor<DiscoveryNode> cursor : clusterState.nodes().getDataNodes().values()) { nodesToShards.put(cursor.value.getId(), new LinkedHashMap<>()); // LinkedHashMap to preserve order
int nodeCount = state.getNodes().getDataNodes().size();
executeSearch((SearchTask)task, timeProvider, searchRequest, localIndices, Collections.emptyList(), (clusterName, nodeId) -> null, clusterState, Collections.emptyMap(), listener, clusterState.getNodes().getDataNodes().size(), SearchResponse.Clusters.EMPTY); } else { remoteClusterService.collectSearchShards(searchRequest.indicesOptions(), searchRequest.preference(), remoteClusterIndices, remoteShardIterators, remoteAliasFilters); int numNodesInvolved = searchShardsResponses.values().stream().mapToInt(r -> r.getNodes().length).sum() + clusterState.getNodes().getDataNodes().size(); SearchResponse.Clusters clusters = buildClusters(localIndices, remoteClusterIndices, searchShardsResponses); executeSearch((SearchTask) task, timeProvider, searchRequest, localIndices,
private Decision earlyTerminate(RoutingAllocation allocation, ImmutableOpenMap<String, DiskUsage> usages) { // Always allow allocation if the decider is disabled if (diskThresholdSettings.isEnabled() == false) { return allocation.decision(Decision.YES, NAME, "the disk threshold decider is disabled"); } // Allow allocation regardless if only a single data node is available if (allocation.nodes().getDataNodes().size() <= 1) { if (logger.isTraceEnabled()) { logger.trace("only a single data node is present, allowing allocation"); } return allocation.decision(Decision.YES, NAME, "there is only a single data node present"); } // Fail open there is no info available final ClusterInfo clusterInfo = allocation.clusterInfo(); if (clusterInfo == null) { if (logger.isTraceEnabled()) { logger.trace("cluster info unavailable for disk threshold decider, allowing allocation."); } return allocation.decision(Decision.YES, NAME, "the cluster info is unavailable"); } // Fail open if there are no disk usages available if (usages.isEmpty()) { if (logger.isTraceEnabled()) { logger.trace("unable to determine disk usages for disk-aware allocation, allowing allocation"); } return allocation.decision(Decision.YES, NAME, "disk usages are unavailable"); } return null; }
private void deassociateDeadNodes(RoutingAllocation allocation) { for (Iterator<RoutingNode> it = allocation.routingNodes().mutableIterator(); it.hasNext(); ) { RoutingNode node = it.next(); if (allocation.nodes().getDataNodes().containsKey(node.nodeId())) { // its a live node, continue continue; } // now, go over all the shards routing on the node, and fail them for (ShardRouting shardRouting : node.copyShards()) { final IndexMetaData indexMetaData = allocation.metaData().getIndexSafe(shardRouting.index()); boolean delayed = INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.get(indexMetaData.getSettings()).nanos() > 0; UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.NODE_LEFT, "node_left[" + node.nodeId() + "]", null, 0, allocation.getCurrentNanoTime(), System.currentTimeMillis(), delayed, AllocationStatus.NO_ATTEMPT); allocation.routingNodes().failShard(logger, shardRouting, unassignedInfo, indexMetaData, allocation.changes()); } // its a dead node, remove it, note, its important to remove it *after* we apply failed shard // since it relies on the fact that the RoutingNode exists in the list of nodes it.remove(); } }
logger.debug("not recovering from gateway, nodes_size (data+master) [{}] < recover_after_nodes [{}]", nodes.getMasterAndDataNodes().size(), recoverAfterNodes); } else if (recoverAfterDataNodes != -1 && nodes.getDataNodes().size() < recoverAfterDataNodes) { logger.debug("not recovering from gateway, nodes_size (data) [{}] < recover_after_data_nodes [{}]", nodes.getDataNodes().size(), recoverAfterDataNodes); } else if (recoverAfterMasterNodes != -1 && nodes.getMasterNodes().size() < recoverAfterMasterNodes) { logger.debug("not recovering from gateway, nodes_size (master) [{}] < recover_after_master_nodes [{}]", enforceRecoverAfterTime = true; reason = "expecting [" + expectedNodes + "] nodes, but only have [" + nodes.getMasterAndDataNodes().size() + "]"; } else if (expectedDataNodes != -1 && (nodes.getDataNodes().size() < expectedDataNodes)) { // does not meet the expected... enforceRecoverAfterTime = true; reason = "expecting [" + expectedDataNodes + "] data nodes, but only have [" + nodes.getDataNodes().size() + "]"; } else if (expectedMasterNodes != -1 && (nodes.getMasterNodes().size() < expectedMasterNodes)) {
final boolean explain = allocation.debugDecision(); Map<String, NodeAllocationResult> nodeDecisions = explain ? new HashMap<>() : null; for (ObjectCursor<DiscoveryNode> cursor : allocation.nodes().getDataNodes().values()) { RoutingNode node = allocation.routingNodes().node(cursor.value.getId()); if (node == null) {
if (this.isMaster && dataNodeAdded && event.state().getNodes().getDataNodes().size() > 1) { if (logger.isDebugEnabled()) { logger.debug("data node was added, retrieving new cluster info");
numberOfDataNodes = clusterState.nodes().getDataNodes().size(); indices = new HashMap<>(); for (String index : concreteIndices) {
static int defaultMaxConcurrentSearches(int availableProcessors, ClusterState state) { int numDateNodes = state.getNodes().getDataNodes().size(); // availableProcessors will never be larger than 32, so max defaultMaxConcurrentSearches will never be larger than 49, // but we don't know about about other search requests that are being executed so lets cap at 10 per node int defaultSearchThreadPoolSize = Math.min(ThreadPool.searchThreadPoolSize(availableProcessors), 10); return Math.max(1, numDateNodes * defaultSearchThreadPoolSize); }
static int defaultMaxConcurrentSearches(int availableProcessors, ClusterState state) { int numDateNodes = state.getNodes().getDataNodes().size(); // availableProcessors will never be larger than 32, so max defaultMaxConcurrentSearches will never be larger than 49, // but we don't know about about other search requests that are being executed so lets cap at 10 per node int defaultSearchThreadPoolSize = Math.min(ThreadPool.searchThreadPoolSize(availableProcessors), 10); return Math.max(1, numDateNodes * defaultSearchThreadPoolSize); }
static int defaultMaxConcurrentSearches(int availableProcessors, ClusterState state) { int numDateNodes = state.getNodes().getDataNodes().size(); // availableProcessors will never be larger than 32, so max defaultMaxConcurrentSearches will never be larger than 49, // but we don't know about about other search requests that are being executed so lets cap at 10 per node int defaultSearchThreadPoolSize = Math.min(ThreadPool.searchThreadPoolSize(availableProcessors), 10); return Math.max(1, numDateNodes * defaultSearchThreadPoolSize); }
private boolean hasDeadNodes(RoutingAllocation allocation) { for (RoutingNode routingNode : allocation.routingNodes()) { if (allocation.nodes().getDataNodes().containsKey(routingNode.nodeId()) == false) { return true; } } return false; }
private boolean hasDeadNodes(RoutingAllocation allocation) { for (RoutingNode routingNode : allocation.routingNodes()) { if (allocation.nodes().getDataNodes().containsKey(routingNode.nodeId()) == false) { return true; } } return false; }