Search in sources :

Example 1 with BucketNode

use of com.facebook.presto.raptor.metadata.BucketNode in project presto by prestodb.

the class BucketBalancer method fetchClusterState.

@VisibleForTesting
ClusterState fetchClusterState() {
    Set<String> activeNodes = nodeSupplier.getWorkerNodes().stream().map(Node::getNodeIdentifier).collect(toSet());
    Map<String, Long> assignedNodeSize = new HashMap<>(activeNodes.stream().collect(toMap(node -> node, node -> 0L)));
    ImmutableMultimap.Builder<Distribution, BucketAssignment> distributionAssignments = ImmutableMultimap.builder();
    ImmutableMap.Builder<Distribution, Long> distributionBucketSize = ImmutableMap.builder();
    for (Distribution distribution : shardManager.getDistributions()) {
        long distributionSize = shardManager.getDistributionSizeInBytes(distribution.getId());
        long bucketSize = (long) (1.0 * distributionSize) / distribution.getBucketCount();
        distributionBucketSize.put(distribution, bucketSize);
        for (BucketNode bucketNode : shardManager.getBucketNodes(distribution.getId())) {
            String node = bucketNode.getNodeIdentifier();
            distributionAssignments.put(distribution, new BucketAssignment(distribution.getId(), bucketNode.getBucketNumber(), node));
            assignedNodeSize.merge(node, bucketSize, Math::addExact);
        }
    }
    return new ClusterState(activeNodes, assignedNodeSize, distributionAssignments.build(), distributionBucketSize.build());
}
Also used : HashMap(java.util.HashMap) BucketNode(com.facebook.presto.raptor.metadata.BucketNode) ImmutableMap(com.google.common.collect.ImmutableMap) Distribution(com.facebook.presto.raptor.metadata.Distribution) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

BucketNode (com.facebook.presto.raptor.metadata.BucketNode)1 Distribution (com.facebook.presto.raptor.metadata.Distribution)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 HashMap (java.util.HashMap)1