Java Code Examples for org.elasticsearch.cluster.node.DiscoveryNode#isDataNode()
The following examples show how to use
org.elasticsearch.cluster.node.DiscoveryNode#isDataNode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndicesStore.java From crate with Apache License 2.0 | 6 votes |
@Inject public IndicesStore(Settings settings, IndicesService indicesService, ClusterService clusterService, TransportService transportService, ThreadPool threadPool) { this.settings = settings; this.indicesService = indicesService; this.clusterService = clusterService; this.transportService = transportService; this.threadPool = threadPool; transportService.registerRequestHandler(ACTION_SHARD_EXISTS, ShardActiveRequest::new, ThreadPool.Names.SAME, new ShardActiveRequestHandler()); this.deleteShardTimeout = INDICES_STORE_DELETE_SHARD_TIMEOUT.get(settings); // Doesn't make sense to delete shards on non-data nodes if (DiscoveryNode.isDataNode(settings)) { // we double check nothing has changed when responses come back from other nodes. // it's easier to do that check when the current cluster state is visible. // also it's good in general to let things settle down clusterService.addListener(this); } }
Example 2
Source File: SnapshotShardsService.java From crate with Apache License 2.0 | 6 votes |
@Inject public SnapshotShardsService(Settings settings, ClusterService clusterService, RepositoriesService repositoriesService, ThreadPool threadPool, TransportService transportService, IndicesService indicesService, IndexNameExpressionResolver indexNameExpressionResolver) { this.indicesService = indicesService; this.repositoriesService = repositoriesService; this.transportService = transportService; this.clusterService = clusterService; this.threadPool = threadPool; if (DiscoveryNode.isDataNode(settings)) { // this is only useful on the nodes that can hold data clusterService.addListener(this); } // The constructor of UpdateSnapshotStatusAction will register itself to the TransportService. this.updateSnapshotStatusHandler = new UpdateSnapshotStatusAction(transportService, clusterService, threadPool, indexNameExpressionResolver); }
Example 3
Source File: RoutingProvider.java From crate with Apache License 2.0 | 6 votes |
public Routing forRandomMasterOrDataNode(RelationName relationName, DiscoveryNodes nodes) { DiscoveryNode localNode = nodes.getLocalNode(); if (localNode.isMasterNode() || localNode.isDataNode()) { return forTableOnSingleNode(relationName, localNode.getId()); } ImmutableOpenMap<String, DiscoveryNode> masterAndDataNodes = nodes.getMasterAndDataNodes(); int randomIdx = seed % masterAndDataNodes.size(); Iterator<DiscoveryNode> it = masterAndDataNodes.valuesIt(); int currIdx = 0; while (it.hasNext()) { if (currIdx == randomIdx) { return forTableOnSingleNode(relationName, it.next().getId()); } currIdx++; } throw new AssertionError("Cannot find a master or data node with given random index " + randomIdx); }
Example 4
Source File: DiscoveryNodeFilterer.java From anomaly-detection with Apache License 2.0 | 5 votes |
@Override public boolean test(DiscoveryNode discoveryNode) { return discoveryNode.isDataNode() && discoveryNode .getAttributes() .getOrDefault(CommonName.BOX_TYPE_KEY, CommonName.HOT_BOX_TYPE) .equals(CommonName.HOT_BOX_TYPE); }
Example 5
Source File: IndicesClusterStateService.java From crate with Apache License 2.0 | 5 votes |
@Override protected void doStart() { // Doesn't make sense to manage shards on non-master and non-data nodes if (DiscoveryNode.isDataNode(settings) || DiscoveryNode.isMasterNode(settings)) { clusterService.addHighPriorityApplier(this); } }
Example 6
Source File: RepositoriesService.java From crate with Apache License 2.0 | 5 votes |
@Inject public RepositoriesService(Settings settings, ClusterService clusterService, TransportService transportService, Map<String, Repository.Factory> typesRegistry, ThreadPool threadPool) { this.typesRegistry = typesRegistry; this.clusterService = clusterService; this.threadPool = threadPool; // Doesn't make sense to maintain repositories on non-master and non-data nodes // Nothing happens there anyway if (DiscoveryNode.isDataNode(settings) || DiscoveryNode.isMasterNode(settings)) { clusterService.addStateApplier(this); } this.verifyAction = new VerifyNodeRepositoryAction(transportService, clusterService, this); }
Example 7
Source File: NodeRepurposeCommand.java From crate with Apache License 2.0 | 5 votes |
@Override protected boolean validateBeforeLock(Terminal terminal, Environment env) { Settings settings = env.settings(); if (DiscoveryNode.isDataNode(settings)) { terminal.println(Terminal.Verbosity.NORMAL, NO_CLEANUP); return false; } return true; }
Example 8
Source File: AbstractAllocateAllocationCommand.java From crate with Apache License 2.0 | 5 votes |
/** * Handle case where a disco node cannot be found in the routing table. Usually means that it's not a data node. */ protected RerouteExplanation explainOrThrowMissingRoutingNode(RoutingAllocation allocation, boolean explain, DiscoveryNode discoNode) { if (!discoNode.isDataNode()) { return explainOrThrowRejectedCommand(explain, allocation, "allocation can only be done on data nodes, not [" + node + "]"); } else { return explainOrThrowRejectedCommand(explain, allocation, "could not find [" + node + "] among the routing nodes"); } }
Example 9
Source File: ExplainAnalyzeIntegrationTest.java From crate with Apache License 2.0 | 5 votes |
@Test public void testExplainAnalyzeReportsExecutionTimesOnBothNodesInclQueryBreakdown() { execute("explain analyze select * from locations where name like 'a%' or name = 'foo' order by date desc"); Map<String, Object> analysis = (Map<String, Object>) response.rows()[0][0]; Map<String, Object> executeAnalysis = (Map<String, Object>) analysis.get("Execute"); assertThat(executeAnalysis, is(notNullValue())); assertTrue(executeAnalysis.keySet().contains("Total")); Map<String, Map<String, Object>> phasesAnalysis = (Map<String, Map<String, Object>>) executeAnalysis.get("Phases"); assertThat(phasesAnalysis, is(notNullValue())); assertThat(phasesAnalysis.keySet(), contains("0-collect", "1-mergeOnHandler")); DiscoveryNodes nodes = clusterService().state().nodes(); for (DiscoveryNode discoveryNode : nodes) { if (discoveryNode.isDataNode()) { Object actual = executeAnalysis.get(discoveryNode.getId()); assertThat(actual, instanceOf(Map.class)); Map<String, Object> timings = (Map) actual; assertThat(timings, Matchers.hasKey("QueryBreakdown")); Map<String, Object> queryBreakdown = ((Map) ((List) timings.get("QueryBreakdown")).get(0)); assertThat(queryBreakdown, Matchers.hasEntry("QueryName", "BooleanQuery")); } } }
Example 10
Source File: TransportLeaderShardIngestAction.java From elasticsearch-helper with Apache License 2.0 | 4 votes |
public int findQuorum(ClusterState clusterState, ShardIterator shardIt, IngestLeaderShardRequest request) { if (request.requiredConsistency() == Consistency.IGNORE) { return 0; } int numberOfDataNodes = 0; for (DiscoveryNode node : clusterState.getNodes()) { if (node.isDataNode()) { numberOfDataNodes++; } } // single node, do not care about replica if (numberOfDataNodes == 1) { return 0; } int replicaLevelOfIndex = clusterState.metaData().index(request.index()).getNumberOfReplicas(); // no replica defined, so nothing to check if (replicaLevelOfIndex == 0) { return 0; } int replicaLevel = findReplicaLevel(shardIt) + 1; switch (request.requiredConsistency()) { case ONE: if (replicaLevel >= 1 && replicaLevelOfIndex >= 1) { return 1; } break; case QUORUM: int quorum = (replicaLevelOfIndex / 2) + 1; if (replicaLevel >= quorum) { return quorum; } break; case ALL: if (replicaLevel == replicaLevelOfIndex) { return replicaLevel; } break; } // quorum not matched - we have a problem return -1; }
Example 11
Source File: IndicesClusterStateService.java From crate with Apache License 2.0 | 4 votes |
@Override protected void doStop() { if (DiscoveryNode.isDataNode(settings) || DiscoveryNode.isMasterNode(settings)) { clusterService.removeApplier(this); } }
Example 12
Source File: IndicesStore.java From crate with Apache License 2.0 | 4 votes |
@Override public void close() { if (DiscoveryNode.isDataNode(settings)) { clusterService.removeListener(this); } }
Example 13
Source File: GatewayMetaState.java From crate with Apache License 2.0 | 4 votes |
protected boolean isMasterOrDataNode() { return DiscoveryNode.isMasterNode(settings) || DiscoveryNode.isDataNode(settings); }
Example 14
Source File: InternalClusterInfoService.java From crate with Apache License 2.0 | 4 votes |
@Override public void clusterChanged(ClusterChangedEvent event) { if (!this.enabled) { return; } // Check whether it was a data node that was added boolean dataNodeAdded = false; for (DiscoveryNode addedNode : event.nodesDelta().addedNodes()) { if (addedNode.isDataNode()) { dataNodeAdded = true; break; } } if (this.isMaster && dataNodeAdded && event.state().getNodes().getDataNodes().size() > 1) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("data node was added, retrieving new cluster info"); } threadPool.executor(executorName()).execute(this::maybeRefresh); } if (this.isMaster && event.nodesRemoved()) { for (DiscoveryNode removedNode : event.nodesDelta().removedNodes()) { if (removedNode.isDataNode()) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Removing node from cluster info: {}", removedNode.getId()); } if (leastAvailableSpaceUsages.containsKey(removedNode.getId())) { ImmutableOpenMap.Builder<String, DiskUsage> newMaxUsages = ImmutableOpenMap.builder(leastAvailableSpaceUsages); newMaxUsages.remove(removedNode.getId()); leastAvailableSpaceUsages = newMaxUsages.build(); } if (mostAvailableSpaceUsages.containsKey(removedNode.getId())) { ImmutableOpenMap.Builder<String, DiskUsage> newMinUsages = ImmutableOpenMap.builder(mostAvailableSpaceUsages); newMinUsages.remove(removedNode.getId()); mostAvailableSpaceUsages = newMinUsages.build(); } } } } }