Search in sources :

Example 1 with ClusterState

use of io.trino.plugin.raptor.legacy.storage.BucketBalancer.ClusterState in project trino by trinodb.

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(io.trino.plugin.raptor.legacy.storage.BucketBalancer.ClusterState) Distribution(io.trino.plugin.raptor.legacy.metadata.Distribution)

Aggregations

Distribution (io.trino.plugin.raptor.legacy.metadata.Distribution)1 ClusterState (io.trino.plugin.raptor.legacy.storage.BucketBalancer.ClusterState)1