Search in sources :

Example 1 with ClusterState

use of com.facebook.presto.raptor.storage.BucketBalancer.ClusterState in project presto by prestodb.

the class TestBucketBalancer method assertBalancing.

private static void assertBalancing(BucketBalancer balancer, int expectedMoves) {
    int actualMoves = balancer.balance();
    assertEquals(actualMoves, expectedMoves);
    // check that number of buckets per node is within bounds
    ClusterState clusterState = balancer.fetchClusterState();
    for (Distribution distribution : clusterState.getDistributionAssignments().keySet()) {
        Multiset<String> allocationCounts = HashMultiset.create();
        clusterState.getDistributionAssignments().get(distribution).stream().map(BucketAssignment::getNodeIdentifier).forEach(allocationCounts::add);
        double bucketsPerNode = (1.0 * allocationCounts.size()) / clusterState.getActiveNodes().size();
        for (String node : allocationCounts) {
            assertGreaterThanOrEqual(allocationCounts.count(node), (int) Math.floor(bucketsPerNode), node + " has fewer buckets than expected");
            assertLessThanOrEqual(allocationCounts.count(node), (int) Math.ceil(bucketsPerNode), node + " has more buckets than expected");
        }
    }
    // check stability
    assertEquals(balancer.balance(), 0);
}
Also used : ClusterState(com.facebook.presto.raptor.storage.BucketBalancer.ClusterState) Distribution(com.facebook.presto.raptor.metadata.Distribution)

Aggregations

Distribution (com.facebook.presto.raptor.metadata.Distribution)1 ClusterState (com.facebook.presto.raptor.storage.BucketBalancer.ClusterState)1