Search in sources :

Example 36 with ShardRouting

use of org.elasticsearch.cluster.routing.ShardRouting in project elasticsearch by elastic.

the class ClusterSearchShardsGroup method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    shardId.writeTo(out);
    out.writeVInt(shards.length);
    for (ShardRouting shardRouting : shards) {
        shardRouting.writeToThin(out);
    }
}
Also used : ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 37 with ShardRouting

use of org.elasticsearch.cluster.routing.ShardRouting in project elasticsearch by elastic.

the class ClusterSearchShardsGroup method readFrom.

@Override
public void readFrom(StreamInput in) throws IOException {
    shardId = ShardId.readShardId(in);
    shards = new ShardRouting[in.readVInt()];
    for (int i = 0; i < shards.length; i++) {
        shards[i] = new ShardRouting(shardId, in);
    }
}
Also used : ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 38 with ShardRouting

use of org.elasticsearch.cluster.routing.ShardRouting in project elasticsearch by elastic.

the class ClusterSearchShardsGroup method toXContent.

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startArray();
    for (ShardRouting shard : getShards()) {
        shard.toXContent(builder, params);
    }
    builder.endArray();
    return builder;
}
Also used : ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 39 with ShardRouting

use of org.elasticsearch.cluster.routing.ShardRouting in project elasticsearch by elastic.

the class SameShardAllocationDecider method canAllocate.

@Override
public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
    Iterable<ShardRouting> assignedShards = allocation.routingNodes().assignedShards(shardRouting.shardId());
    Decision decision = decideSameNode(shardRouting, node, allocation, assignedShards);
    if (decision.type() == Decision.Type.NO || sameHost == false) {
        // if its already a NO decision looking at the node, or we aren't configured to look at the host, return the decision
        return decision;
    }
    if (node.node() != null) {
        for (RoutingNode checkNode : allocation.routingNodes()) {
            if (checkNode.node() == null) {
                continue;
            }
            // check if its on the same host as the one we want to allocate to
            boolean checkNodeOnSameHostName = false;
            boolean checkNodeOnSameHostAddress = false;
            if (Strings.hasLength(checkNode.node().getHostAddress()) && Strings.hasLength(node.node().getHostAddress())) {
                if (checkNode.node().getHostAddress().equals(node.node().getHostAddress())) {
                    checkNodeOnSameHostAddress = true;
                }
            } else if (Strings.hasLength(checkNode.node().getHostName()) && Strings.hasLength(node.node().getHostName())) {
                if (checkNode.node().getHostName().equals(node.node().getHostName())) {
                    checkNodeOnSameHostName = true;
                }
            }
            if (checkNodeOnSameHostAddress || checkNodeOnSameHostName) {
                for (ShardRouting assignedShard : assignedShards) {
                    if (checkNode.nodeId().equals(assignedShard.currentNodeId())) {
                        String hostType = checkNodeOnSameHostAddress ? "address" : "name";
                        String host = checkNodeOnSameHostAddress ? node.node().getHostAddress() : node.node().getHostName();
                        return allocation.decision(Decision.NO, NAME, "the shard cannot be allocated on host %s [%s], where it already exists on node [%s]; " + "set cluster setting [%s] to false to allow multiple nodes on the same host to hold the same " + "shard copies", hostType, host, node.nodeId(), CLUSTER_ROUTING_ALLOCATION_SAME_HOST_SETTING.getKey());
                    }
                }
            }
        }
    }
    return allocation.decision(Decision.YES, NAME, "the shard does not exist on the same host");
}
Also used : RoutingNode(org.elasticsearch.cluster.routing.RoutingNode) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 40 with ShardRouting

use of org.elasticsearch.cluster.routing.ShardRouting in project elasticsearch by elastic.

the class ShardsLimitAllocationDecider method doDecide.

private Decision doDecide(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation, BiPredicate<Integer, Integer> decider) {
    IndexMetaData indexMd = allocation.metaData().getIndexSafe(shardRouting.index());
    final int indexShardLimit = INDEX_TOTAL_SHARDS_PER_NODE_SETTING.get(indexMd.getSettings(), settings);
    // Capture the limit here in case it changes during this method's
    // execution
    final int clusterShardLimit = this.clusterShardLimit;
    if (indexShardLimit <= 0 && clusterShardLimit <= 0) {
        return allocation.decision(Decision.YES, NAME, "total shard limits are disabled: [index: %d, cluster: %d] <= 0", indexShardLimit, clusterShardLimit);
    }
    int indexShardCount = 0;
    int nodeShardCount = 0;
    for (ShardRouting nodeShard : node) {
        // don't count relocating shards...
        if (nodeShard.relocating()) {
            continue;
        }
        nodeShardCount++;
        if (nodeShard.index().equals(shardRouting.index())) {
            indexShardCount++;
        }
    }
    if (clusterShardLimit > 0 && decider.test(nodeShardCount, clusterShardLimit)) {
        return allocation.decision(Decision.NO, NAME, "too many shards [%d] allocated to this node, cluster setting [%s=%d]", nodeShardCount, CLUSTER_TOTAL_SHARDS_PER_NODE_SETTING.getKey(), clusterShardLimit);
    }
    if (indexShardLimit > 0 && decider.test(indexShardCount, indexShardLimit)) {
        return allocation.decision(Decision.NO, NAME, "too many shards [%d] allocated to this node for index [%s], index setting [%s=%d]", indexShardCount, shardRouting.getIndexName(), INDEX_TOTAL_SHARDS_PER_NODE_SETTING.getKey(), indexShardLimit);
    }
    return allocation.decision(Decision.YES, NAME, "the shard count [%d] for this node is under the index limit [%d] and cluster level node limit [%d]", nodeShardCount, indexShardLimit, clusterShardLimit);
}
Also used : ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Aggregations

ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)372 ClusterState (org.elasticsearch.cluster.ClusterState)162 ShardId (org.elasticsearch.index.shard.ShardId)104 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)92 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)79 RoutingNode (org.elasticsearch.cluster.routing.RoutingNode)75 TestShardRouting (org.elasticsearch.cluster.routing.TestShardRouting)75 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)74 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)71 Index (org.elasticsearch.index.Index)50 HashSet (java.util.HashSet)49 UnassignedInfo (org.elasticsearch.cluster.routing.UnassignedInfo)49 ArrayList (java.util.ArrayList)48 IndexShard (org.elasticsearch.index.shard.IndexShard)48 Settings (org.elasticsearch.common.settings.Settings)46 MetaData (org.elasticsearch.cluster.metadata.MetaData)45 IndexRoutingTable (org.elasticsearch.cluster.routing.IndexRoutingTable)44 IOException (java.io.IOException)43 HashMap (java.util.HashMap)41 RoutingNodes (org.elasticsearch.cluster.routing.RoutingNodes)41