Search in sources :

Example 11 with BalanceParamsImpl

use of org.apache.accumulo.core.manager.balancer.BalanceParamsImpl in project accumulo by apache.

the class SimpleLoadBalancerTest method testUnevenAssignment.

@Test
public void testUnevenAssignment() {
    for (char c : "abcdefghijklmnopqrstuvwxyz".toCharArray()) {
        String cString = Character.toString(c);
        TabletServerId tsid = new TabletServerIdImpl("127.0.0.1", c, cString);
        FakeTServer fakeTServer = new FakeTServer();
        servers.put(tsid, fakeTServer);
        fakeTServer.tablets.add(makeTablet(cString, null, null));
    }
    // Put more tablets on one server, but not more than the number of servers
    Entry<TabletServerId, FakeTServer> first = servers.entrySet().iterator().next();
    first.getValue().tablets.add(makeTablet("newTable", "a", null));
    first.getValue().tablets.add(makeTablet("newTable", "b", "a"));
    first.getValue().tablets.add(makeTablet("newTable", "c", "b"));
    first.getValue().tablets.add(makeTablet("newTable", "d", "c"));
    first.getValue().tablets.add(makeTablet("newTable", "e", "d"));
    first.getValue().tablets.add(makeTablet("newTable", "f", "e"));
    first.getValue().tablets.add(makeTablet("newTable", "g", "f"));
    first.getValue().tablets.add(makeTablet("newTable", "h", "g"));
    first.getValue().tablets.add(makeTablet("newTable", "i", null));
    TestSimpleLoadBalancer balancer = new TestSimpleLoadBalancer();
    Set<TabletId> migrations = Collections.emptySet();
    int moved = 0;
    // balance until we can't balance no more!
    while (true) {
        List<TabletMigration> migrationsOut = new ArrayList<>();
        balancer.balance(new BalanceParamsImpl(getAssignments(servers), migrations, migrationsOut));
        if (migrationsOut.isEmpty())
            break;
        for (TabletMigration migration : migrationsOut) {
            if (servers.get(migration.getOldTabletServer()).tablets.remove(migration.getTablet()))
                moved++;
            servers.get(migration.getNewTabletServer()).tablets.add(migration.getTablet());
        }
    }
    assertEquals(8, moved);
}
Also used : BalanceParamsImpl(org.apache.accumulo.core.manager.balancer.BalanceParamsImpl) TabletMigration(org.apache.accumulo.core.spi.balancer.data.TabletMigration) ArrayList(java.util.ArrayList) TabletServerIdImpl(org.apache.accumulo.core.manager.balancer.TabletServerIdImpl) TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) TabletId(org.apache.accumulo.core.data.TabletId) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)11 BalanceParamsImpl (org.apache.accumulo.core.manager.balancer.BalanceParamsImpl)11 TabletMigration (org.apache.accumulo.core.spi.balancer.data.TabletMigration)10 TabletId (org.apache.accumulo.core.data.TabletId)9 Test (org.junit.jupiter.api.Test)7 TabletServerId (org.apache.accumulo.core.spi.balancer.data.TabletServerId)6 HashSet (java.util.HashSet)4 TableId (org.apache.accumulo.core.data.TableId)4 TabletServerIdImpl (org.apache.accumulo.core.manager.balancer.TabletServerIdImpl)4 HashMap (java.util.HashMap)3 Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 ConfigurationCopy (org.apache.accumulo.core.conf.ConfigurationCopy)2 TServerStatusImpl (org.apache.accumulo.core.manager.balancer.TServerStatusImpl)2 TServerStatus (org.apache.accumulo.core.spi.balancer.data.TServerStatus)2 TabletStatistics (org.apache.accumulo.core.spi.balancer.data.TabletStatistics)2 ConfigurationImpl (org.apache.accumulo.core.util.ConfigurationImpl)2 Collections (java.util.Collections)1 List (java.util.List)1