Search in sources :

Example 1 with ShardStoreInfo

use of org.elasticsearch.cluster.routing.allocation.NodeAllocationResult.ShardStoreInfo in project elasticsearch by elastic.

the class PrimaryShardAllocator method shardStoreInfo.

private static ShardStoreInfo shardStoreInfo(NodeGatewayStartedShards nodeShardState, Set<String> inSyncAllocationIds) {
    final Exception storeErr = nodeShardState.storeException();
    final boolean inSync = nodeShardState.allocationId() != null && inSyncAllocationIds.contains(nodeShardState.allocationId());
    return new ShardStoreInfo(nodeShardState.allocationId(), inSync, storeErr);
}
Also used : ShardStoreInfo(org.elasticsearch.cluster.routing.allocation.NodeAllocationResult.ShardStoreInfo) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException)

Example 2 with ShardStoreInfo

use of org.elasticsearch.cluster.routing.allocation.NodeAllocationResult.ShardStoreInfo in project elasticsearch by elastic.

the class ReplicaShardAllocator method findMatchingNodes.

private MatchingNodes findMatchingNodes(ShardRouting shard, RoutingAllocation allocation, TransportNodesListShardStoreMetaData.StoreFilesMetaData primaryStore, AsyncShardFetch.FetchResult<NodeStoreFilesMetaData> data, boolean explain) {
    ObjectLongMap<DiscoveryNode> nodesToSize = new ObjectLongHashMap<>();
    Map<String, NodeAllocationResult> nodeDecisions = explain ? new HashMap<>() : null;
    for (Map.Entry<DiscoveryNode, NodeStoreFilesMetaData> nodeStoreEntry : data.getData().entrySet()) {
        DiscoveryNode discoNode = nodeStoreEntry.getKey();
        TransportNodesListShardStoreMetaData.StoreFilesMetaData storeFilesMetaData = nodeStoreEntry.getValue().storeFilesMetaData();
        // we don't have any files at all, it is an empty index
        if (storeFilesMetaData.isEmpty()) {
            continue;
        }
        RoutingNode node = allocation.routingNodes().node(discoNode.getId());
        if (node == null) {
            continue;
        }
        // check if we can allocate on that node...
        // we only check for NO, since if this node is THROTTLING and it has enough "same data"
        // then we will try and assign it next time
        Decision decision = allocation.deciders().canAllocate(shard, node, allocation);
        long matchingBytes = -1;
        if (explain) {
            matchingBytes = computeMatchingBytes(primaryStore, storeFilesMetaData);
            ShardStoreInfo shardStoreInfo = new ShardStoreInfo(matchingBytes);
            nodeDecisions.put(node.nodeId(), new NodeAllocationResult(discoNode, shardStoreInfo, decision));
        }
        if (decision.type() == Decision.Type.NO) {
            continue;
        }
        if (matchingBytes < 0) {
            matchingBytes = computeMatchingBytes(primaryStore, storeFilesMetaData);
        }
        nodesToSize.put(discoNode, matchingBytes);
        if (logger.isTraceEnabled()) {
            if (matchingBytes == Long.MAX_VALUE) {
                logger.trace("{}: node [{}] has same sync id {} as primary", shard, discoNode.getName(), storeFilesMetaData.syncId());
            } else {
                logger.trace("{}: node [{}] has [{}/{}] bytes of re-usable data", shard, discoNode.getName(), new ByteSizeValue(matchingBytes), matchingBytes);
            }
        }
    }
    return new MatchingNodes(nodesToSize, nodeDecisions);
}
Also used : ObjectLongHashMap(com.carrotsearch.hppc.ObjectLongHashMap) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) TransportNodesListShardStoreMetaData(org.elasticsearch.indices.store.TransportNodesListShardStoreMetaData) AllocateUnassignedDecision(org.elasticsearch.cluster.routing.allocation.AllocateUnassignedDecision) Decision(org.elasticsearch.cluster.routing.allocation.decider.Decision) ShardStoreInfo(org.elasticsearch.cluster.routing.allocation.NodeAllocationResult.ShardStoreInfo) RoutingNode(org.elasticsearch.cluster.routing.RoutingNode) HashMap(java.util.HashMap) ObjectLongHashMap(com.carrotsearch.hppc.ObjectLongHashMap) Map(java.util.Map) ObjectLongMap(com.carrotsearch.hppc.ObjectLongMap) NodeAllocationResult(org.elasticsearch.cluster.routing.allocation.NodeAllocationResult) NodeStoreFilesMetaData(org.elasticsearch.indices.store.TransportNodesListShardStoreMetaData.NodeStoreFilesMetaData)

Example 3 with ShardStoreInfo

use of org.elasticsearch.cluster.routing.allocation.NodeAllocationResult.ShardStoreInfo in project elasticsearch by elastic.

the class NodeAllocationResultTests method testShardStore.

public void testShardStore() throws IOException {
    DiscoveryNode node = new DiscoveryNode("node1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    Decision decision = randomFrom(Decision.YES, Decision.THROTTLE, Decision.NO);
    long matchingBytes = (long) randomIntBetween(1, 1000);
    ShardStoreInfo shardStoreInfo = new ShardStoreInfo(matchingBytes);
    NodeAllocationResult explanation = new NodeAllocationResult(node, shardStoreInfo, decision);
    BytesStreamOutput output = new BytesStreamOutput();
    explanation.writeTo(output);
    NodeAllocationResult readExplanation = new NodeAllocationResult(output.bytes().streamInput());
    assertNodeExplanationEquals(explanation, readExplanation);
    assertEquals(matchingBytes, explanation.getShardStoreInfo().getMatchingBytes());
    assertNull(explanation.getShardStoreInfo().getAllocationId());
    assertFalse(explanation.getShardStoreInfo().isInSync());
    assertFalse(explanation.getShardStoreInfo().hasMatchingSyncId());
    String allocId = randomAsciiOfLength(5);
    boolean inSync = randomBoolean();
    shardStoreInfo = new ShardStoreInfo(allocId, inSync, randomBoolean() ? new Exception("bad stuff") : null);
    explanation = new NodeAllocationResult(node, shardStoreInfo, decision);
    output = new BytesStreamOutput();
    explanation.writeTo(output);
    readExplanation = new NodeAllocationResult(output.bytes().streamInput());
    assertNodeExplanationEquals(explanation, readExplanation);
    assertEquals(inSync, explanation.getShardStoreInfo().isInSync());
    assertEquals(-1, explanation.getShardStoreInfo().getMatchingBytes());
    assertFalse(explanation.getShardStoreInfo().hasMatchingSyncId());
    assertEquals(allocId, explanation.getShardStoreInfo().getAllocationId());
}
Also used : ShardStoreInfo(org.elasticsearch.cluster.routing.allocation.NodeAllocationResult.ShardStoreInfo) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Decision(org.elasticsearch.cluster.routing.allocation.decider.Decision) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) IOException(java.io.IOException)

Aggregations

ShardStoreInfo (org.elasticsearch.cluster.routing.allocation.NodeAllocationResult.ShardStoreInfo)3 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)2 Decision (org.elasticsearch.cluster.routing.allocation.decider.Decision)2 ObjectLongHashMap (com.carrotsearch.hppc.ObjectLongHashMap)1 ObjectLongMap (com.carrotsearch.hppc.ObjectLongMap)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 RoutingNode (org.elasticsearch.cluster.routing.RoutingNode)1 AllocateUnassignedDecision (org.elasticsearch.cluster.routing.allocation.AllocateUnassignedDecision)1 NodeAllocationResult (org.elasticsearch.cluster.routing.allocation.NodeAllocationResult)1 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)1 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)1 ShardLockObtainFailedException (org.elasticsearch.env.ShardLockObtainFailedException)1 TransportNodesListShardStoreMetaData (org.elasticsearch.indices.store.TransportNodesListShardStoreMetaData)1 NodeStoreFilesMetaData (org.elasticsearch.indices.store.TransportNodesListShardStoreMetaData.NodeStoreFilesMetaData)1