Search in sources :

Example 1 with ClusterStateHealth

use of org.elasticsearch.cluster.health.ClusterStateHealth in project elasticsearch by elastic.

the class PrimaryTermsTests method applyRerouteResult.

private void applyRerouteResult(ClusterState newClusterState) {
    ClusterState previousClusterState = this.clusterState;
    ClusterState.Builder builder = ClusterState.builder(newClusterState).incrementVersion();
    if (previousClusterState.routingTable() != newClusterState.routingTable()) {
        builder.routingTable(RoutingTable.builder(newClusterState.routingTable()).version(newClusterState.routingTable().version() + 1).build());
    }
    if (previousClusterState.metaData() != newClusterState.metaData()) {
        builder.metaData(MetaData.builder(newClusterState.metaData()).version(newClusterState.metaData().version() + 1));
    }
    this.clusterState = builder.build();
    final ClusterStateHealth clusterHealth = new ClusterStateHealth(clusterState);
    logger.info("applied reroute. active shards: p [{}], t [{}], init shards: [{}], relocating: [{}]", clusterHealth.getActivePrimaryShards(), clusterHealth.getActiveShards(), clusterHealth.getInitializingShards(), clusterHealth.getRelocatingShards());
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateHealth(org.elasticsearch.cluster.health.ClusterStateHealth)

Example 2 with ClusterStateHealth

use of org.elasticsearch.cluster.health.ClusterStateHealth in project elasticsearch by elastic.

the class TransportClusterStatsAction method nodeOperation.

@Override
protected ClusterStatsNodeResponse nodeOperation(ClusterStatsNodeRequest nodeRequest) {
    NodeInfo nodeInfo = nodeService.info(true, true, false, true, false, true, false, true, false, false);
    NodeStats nodeStats = nodeService.stats(CommonStatsFlags.NONE, true, true, true, false, true, false, false, false, false, false, false);
    List<ShardStats> shardsStats = new ArrayList<>();
    for (IndexService indexService : indicesService) {
        for (IndexShard indexShard : indexService) {
            if (indexShard.routingEntry() != null && indexShard.routingEntry().active()) {
                // only report on fully started shards
                shardsStats.add(new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indicesService.getIndicesQueryCache(), indexShard, SHARD_STATS_FLAGS), indexShard.commitStats(), indexShard.seqNoStats()));
            }
        }
    }
    ClusterHealthStatus clusterStatus = null;
    if (clusterService.state().nodes().isLocalNodeElectedMaster()) {
        clusterStatus = new ClusterStateHealth(clusterService.state()).getStatus();
    }
    return new ClusterStatsNodeResponse(nodeInfo.getNode(), clusterStatus, nodeInfo, nodeStats, shardsStats.toArray(new ShardStats[shardsStats.size()]));
}
Also used : ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) ClusterStateHealth(org.elasticsearch.cluster.health.ClusterStateHealth) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) IndexService(org.elasticsearch.index.IndexService) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) IndexShard(org.elasticsearch.index.shard.IndexShard) ArrayList(java.util.ArrayList)

Example 3 with ClusterStateHealth

use of org.elasticsearch.cluster.health.ClusterStateHealth in project elasticsearch by elastic.

the class AllocationService method buildResultAndLogHealthChange.

protected ClusterState buildResultAndLogHealthChange(ClusterState oldState, RoutingAllocation allocation, String reason) {
    RoutingTable oldRoutingTable = oldState.routingTable();
    RoutingNodes newRoutingNodes = allocation.routingNodes();
    final RoutingTable newRoutingTable = new RoutingTable.Builder().updateNodes(oldRoutingTable.version(), newRoutingNodes).build();
    MetaData newMetaData = allocation.updateMetaDataWithRoutingChanges(newRoutingTable);
    // validates the routing table is coherent with the cluster state metadata
    assert newRoutingTable.validate(newMetaData);
    final ClusterState.Builder newStateBuilder = ClusterState.builder(oldState).routingTable(newRoutingTable).metaData(newMetaData);
    final RestoreInProgress restoreInProgress = allocation.custom(RestoreInProgress.TYPE);
    if (restoreInProgress != null) {
        RestoreInProgress updatedRestoreInProgress = allocation.updateRestoreInfoWithRoutingChanges(restoreInProgress);
        if (updatedRestoreInProgress != restoreInProgress) {
            ImmutableOpenMap.Builder<String, ClusterState.Custom> customsBuilder = ImmutableOpenMap.builder(allocation.getCustoms());
            customsBuilder.put(RestoreInProgress.TYPE, updatedRestoreInProgress);
            newStateBuilder.customs(customsBuilder.build());
        }
    }
    final ClusterState newState = newStateBuilder.build();
    logClusterHealthStateChange(new ClusterStateHealth(oldState), new ClusterStateHealth(newState), reason);
    return newState;
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateHealth(org.elasticsearch.cluster.health.ClusterStateHealth) RestoreInProgress(org.elasticsearch.cluster.RestoreInProgress) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) RoutingNodes(org.elasticsearch.cluster.routing.RoutingNodes) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap)

Example 4 with ClusterStateHealth

use of org.elasticsearch.cluster.health.ClusterStateHealth in project elasticsearch by elastic.

the class DecisionsImpactOnClusterHealthTests method runAllocationTest.

private ClusterState runAllocationTest(final Settings settings, final String indexName, final Set<AllocationDecider> allocationDeciders, final ClusterHealthStatus expectedStatus) throws IOException {
    final String clusterName = "test-cluster";
    final AllocationService allocationService = newAllocationService(settings, allocationDeciders);
    logger.info("Building initial routing table");
    final int numShards = randomIntBetween(1, 5);
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder(indexName).settings(settings(Version.CURRENT)).numberOfShards(numShards).numberOfReplicas(1)).build();
    RoutingTable routingTable = RoutingTable.builder().addAsNew(metaData.index(indexName)).build();
    ClusterState clusterState = ClusterState.builder(new ClusterName(clusterName)).metaData(metaData).routingTable(routingTable).build();
    logger.info("--> adding nodes");
    // we need at least as many nodes as shards for the THROTTLE case, because
    // once a shard has been throttled on a node, that node no longer accepts
    // any allocations on it
    final DiscoveryNodes.Builder discoveryNodes = DiscoveryNodes.builder();
    for (int i = 0; i < numShards; i++) {
        discoveryNodes.add(newNode("node" + i));
    }
    clusterState = ClusterState.builder(clusterState).nodes(discoveryNodes).build();
    logger.info("--> do the reroute");
    routingTable = allocationService.reroute(clusterState, "reroute").routingTable();
    clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
    logger.info("--> assert cluster health");
    ClusterStateHealth health = new ClusterStateHealth(clusterState);
    assertThat(health.getStatus(), equalTo(expectedStatus));
    return clusterState;
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateHealth(org.elasticsearch.cluster.health.ClusterStateHealth) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ClusterName(org.elasticsearch.cluster.ClusterName) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 5 with ClusterStateHealth

use of org.elasticsearch.cluster.health.ClusterStateHealth in project elasticsearch by elastic.

the class ClusterHealthResponse method readFrom.

@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    clusterName = in.readString();
    clusterHealthStatus = ClusterHealthStatus.fromValue(in.readByte());
    clusterStateHealth = new ClusterStateHealth(in);
    numberOfPendingTasks = in.readInt();
    timedOut = in.readBoolean();
    numberOfInFlightFetch = in.readInt();
    delayedUnassignedShards = in.readInt();
    taskMaxWaitingTime = new TimeValue(in);
}
Also used : ClusterStateHealth(org.elasticsearch.cluster.health.ClusterStateHealth) TimeValue(org.elasticsearch.common.unit.TimeValue)

Aggregations

ClusterStateHealth (org.elasticsearch.cluster.health.ClusterStateHealth)7 ClusterState (org.elasticsearch.cluster.ClusterState)4 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)3 ClusterName (org.elasticsearch.cluster.ClusterName)2 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)2 MetaData (org.elasticsearch.cluster.metadata.MetaData)2 RoutingNodes (org.elasticsearch.cluster.routing.RoutingNodes)2 ArrayList (java.util.ArrayList)1 NodeInfo (org.elasticsearch.action.admin.cluster.node.info.NodeInfo)1 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)1 CommonStats (org.elasticsearch.action.admin.indices.stats.CommonStats)1 ShardStats (org.elasticsearch.action.admin.indices.stats.ShardStats)1 RestoreInProgress (org.elasticsearch.cluster.RestoreInProgress)1 ClusterHealthStatus (org.elasticsearch.cluster.health.ClusterHealthStatus)1 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)1 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)1 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)1 TimeValue (org.elasticsearch.common.unit.TimeValue)1 IndexService (org.elasticsearch.index.IndexService)1 IndexShard (org.elasticsearch.index.shard.IndexShard)1