Java Code Examples for org.elasticsearch.cluster.node.DiscoveryNode#dataNode()

The following examples show how to use org.elasticsearch.cluster.node.DiscoveryNode#dataNode() . 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: SnapshotShardsService.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Inject
public SnapshotShardsService(Settings settings, ClusterService clusterService, SnapshotsService snapshotsService, ThreadPool threadPool,
                             TransportService transportService, IndicesService indicesService) {
    super(settings);
    this.indicesService = indicesService;
    this.snapshotsService = snapshotsService;
    this.transportService = transportService;
    this.clusterService = clusterService;
    this.threadPool = threadPool;
    if (DiscoveryNode.dataNode(settings)) {
        // this is only useful on the nodes that can hold data
        // addLast to make sure that Repository will be created before snapshot
        clusterService.addLast(this);
    }

    if (DiscoveryNode.masterNode(settings)) {
        // This needs to run only on nodes that can become masters
        transportService.registerRequestHandler(UPDATE_SNAPSHOT_ACTION_NAME, UpdateIndexShardSnapshotStatusRequest.class, ThreadPool.Names.SAME, new UpdateSnapshotStateRequestHandler());
    }

}
 
Example 2
Source File: RepositoriesService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public RepositoriesService(Settings settings, ClusterService clusterService, TransportService transportService, RepositoryTypesRegistry typesRegistry, Injector injector) {
    super(settings);
    this.typesRegistry = typesRegistry;
    this.injector = injector;
    this.clusterService = clusterService;
    // Doesn't make sense to maintain repositories on non-master and non-data nodes
    // Nothing happens there anyway
    if (DiscoveryNode.dataNode(settings) || DiscoveryNode.masterNode(settings)) {
        clusterService.add(this);
    }
    this.verifyAction = new VerifyNodeRepositoryAction(settings, transportService, clusterService, this);
}
 
Example 3
Source File: GatewayMetaState.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public GatewayMetaState(Settings settings, NodeEnvironment nodeEnv, MetaStateService metaStateService,
                        DanglingIndicesState danglingIndicesState, TransportNodesListGatewayMetaState nodesListGatewayMetaState,
                        MetaDataIndexUpgradeService metaDataIndexUpgradeService) throws Exception {
    super(settings);
    this.nodeEnv = nodeEnv;
    this.metaStateService = metaStateService;
    this.danglingIndicesState = danglingIndicesState;
    this.metaDataIndexUpgradeService = metaDataIndexUpgradeService;
    nodesListGatewayMetaState.init(this);

    if (DiscoveryNode.dataNode(settings)) {
        ensureNoPre019ShardState(nodeEnv);
        MultiDataPathUpgrader.upgradeMultiDataPath(nodeEnv, logger);
    }

    if (DiscoveryNode.masterNode(settings) || DiscoveryNode.dataNode(settings)) {
        nodeEnv.ensureAtomicMoveSupported();
    }
    if (DiscoveryNode.masterNode(settings) || DiscoveryNode.dataNode(settings)) {
        try {
            ensureNoPre019State();
            pre20Upgrade();
            long startNS = System.nanoTime();
            metaStateService.loadFullState();
            logger.debug("took {} to load state", TimeValue.timeValueMillis(TimeValue.nsecToMSec(System.nanoTime() - startNS)));
        } catch (Exception e) {
            logger.error("failed to read local state, exiting...", e);
            throw e;
        }
    }
}
 
Example 4
Source File: ClusterStatsNodes.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public void addNodeInfo(NodeInfo nodeInfo) {
    total++;
    DiscoveryNode node = nodeInfo.getNode();
    if (node.masterNode()) {
        if (node.dataNode()) {
            masterData++;
        } else {
            masterOnly++;
        }
    } else if (node.dataNode()) {
        dataOnly++;
    } else if (node.clientNode()) {
        client++;
    }
}
 
Example 5
Source File: InternalClusterInfoService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@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.dataNode()) {
            dataNodeAdded = true;
            break;
        }
    }

    if (this.isMaster && dataNodeAdded && clusterService.state().getNodes().getDataNodes().size() > 1) {
        if (logger.isDebugEnabled()) {
            logger.debug("data node was added, retrieving new cluster info");
        }
        threadPool.executor(executorName()).execute(new Runnable() {
            @Override
            public void run() {
                maybeRefresh();
            }
        });
    }

    if (this.isMaster && event.nodesRemoved()) {
        for (DiscoveryNode removedNode : event.nodesDelta().removedNodes()) {
            if (removedNode.dataNode()) {
                if (logger.isTraceEnabled()) {
                    logger.trace("Removing node from cluster info: {}", removedNode.getId());
                }
                if (leastAvailableSpaceUsages.containsKey(removedNode.getId())) {
                    Map<String, DiskUsage> newMaxUsages = new HashMap<>(leastAvailableSpaceUsages);
                    newMaxUsages.remove(removedNode.getId());
                    leastAvailableSpaceUsages = Collections.unmodifiableMap(newMaxUsages);
                }
                if (mostAvailableSpaceUsages.containsKey(removedNode.getId())) {
                    Map<String, DiskUsage> newMinUsages = new HashMap<>(mostAvailableSpaceUsages);
                    newMinUsages.remove(removedNode.getId());
                    mostAvailableSpaceUsages = Collections.unmodifiableMap(newMinUsages);
                }
            }
        }
    }
}