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);
}
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);
}
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());
}
Aggregations