Search in sources :

Example 6 with TabletServerIdImpl

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

the class SimpleLoadBalancer method getAssignment.

public TabletServerId getAssignment(SortedMap<TabletServerId, TServerStatus> locations, TabletServerId last) {
    if (locations.isEmpty())
        return null;
    if (last != null) {
        // Maintain locality
        String fakeSessionID = " ";
        TabletServerId simple = new TabletServerIdImpl(last.getHost(), last.getPort(), fakeSessionID);
        Iterator<TabletServerId> find = locations.tailMap(simple).keySet().iterator();
        if (find.hasNext()) {
            TabletServerId current = find.next();
            if (current.getHost().equals(last.getHost()))
                return current;
        }
    }
    // in the current list.
    if (assignments == null || !assignments.hasNext())
        assignments = randomize(locations.keySet()).iterator();
    TabletServerId result = assignments.next();
    if (!locations.containsKey(result)) {
        assignments = null;
        return randomize(locations.keySet()).iterator().next();
    }
    return result;
}
Also used : TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) TabletServerIdImpl(org.apache.accumulo.core.manager.balancer.TabletServerIdImpl)

Example 7 with TabletServerIdImpl

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

the class GroupBalancer method getAssignments.

@Override
public void getAssignments(AssignmentParameters params) {
    if (params.currentStatus().isEmpty()) {
        return;
    }
    Function<TabletId, String> partitioner = getPartitioner();
    List<ComparablePair<String, TabletId>> tabletsByGroup = new ArrayList<>();
    for (Entry<TabletId, TabletServerId> entry : params.unassignedTablets().entrySet()) {
        TabletServerId last = entry.getValue();
        if (last != null) {
            // Maintain locality
            String fakeSessionID = " ";
            TabletServerId simple = new TabletServerIdImpl(last.getHost(), last.getPort(), fakeSessionID);
            Iterator<TabletServerId> find = params.currentStatus().tailMap(simple).keySet().iterator();
            if (find.hasNext()) {
                TabletServerId tserver = find.next();
                if (tserver.getHost().equals(last.getHost())) {
                    params.addAssignment(entry.getKey(), tserver);
                    continue;
                }
            }
        }
        tabletsByGroup.add(new ComparablePair<>(partitioner.apply(entry.getKey()), entry.getKey()));
    }
    Collections.sort(tabletsByGroup);
    Iterator<TabletServerId> tserverIter = Iterators.cycle(params.currentStatus().keySet());
    for (ComparablePair<String, TabletId> pair : tabletsByGroup) {
        TabletId tabletId = pair.getSecond();
        params.addAssignment(tabletId, tserverIter.next());
    }
}
Also used : TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) ArrayList(java.util.ArrayList) TabletId(org.apache.accumulo.core.data.TabletId) ComparablePair(org.apache.accumulo.core.util.ComparablePair) TabletServerIdImpl(org.apache.accumulo.core.manager.balancer.TabletServerIdImpl)

Example 8 with TabletServerIdImpl

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

the class SimpleLoadBalancerTest method testUnevenAssignment2.

@Test
public void testUnevenAssignment2() {
    // make 26 servers
    for (char c : "abcdefghijklmnopqrstuvwxyz".toCharArray()) {
        TabletServerId tsid = new TabletServerIdImpl("127.0.0.1", c, Character.toString(c));
        FakeTServer fakeTServer = new FakeTServer();
        servers.put(tsid, fakeTServer);
    }
    // put 60 tablets on 25 of them
    List<Entry<TabletServerId, FakeTServer>> shortList = new ArrayList<>(servers.entrySet());
    Entry<TabletServerId, FakeTServer> shortServer = shortList.remove(0);
    int c = 0;
    for (int i = 0; i < 60; i++) {
        for (Entry<TabletServerId, FakeTServer> entry : shortList) {
            entry.getValue().tablets.add(makeTablet("t" + c, null, null));
        }
    }
    // put 10 on the that short server:
    for (int i = 0; i < 10; i++) {
        shortServer.getValue().tablets.add(makeTablet("s" + i, null, 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++;
            last.remove(migration.getTablet());
            servers.get(migration.getNewTabletServer()).tablets.add(migration.getTablet());
            last.put(migration.getTablet(), migration.getNewTabletServer());
        }
    }
    // average is 58, with 2 at 59: we need 48 more moved to the short server
    assertEquals(48, 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) Entry(java.util.Map.Entry) TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) TabletId(org.apache.accumulo.core.data.TabletId) Test(org.junit.jupiter.api.Test)

Example 9 with TabletServerIdImpl

use of org.apache.accumulo.core.manager.balancer.TabletServerIdImpl 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

TabletServerIdImpl (org.apache.accumulo.core.manager.balancer.TabletServerIdImpl)9 TabletServerId (org.apache.accumulo.core.spi.balancer.data.TabletServerId)9 ArrayList (java.util.ArrayList)6 TabletId (org.apache.accumulo.core.data.TabletId)6 TabletMigration (org.apache.accumulo.core.spi.balancer.data.TabletMigration)5 HashMap (java.util.HashMap)4 TreeMap (java.util.TreeMap)4 BalanceParamsImpl (org.apache.accumulo.core.manager.balancer.BalanceParamsImpl)4 TServerStatus (org.apache.accumulo.core.spi.balancer.data.TServerStatus)3 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 SortedMap (java.util.SortedMap)2 TableId (org.apache.accumulo.core.data.TableId)2 AssignmentParamsImpl (org.apache.accumulo.core.manager.balancer.AssignmentParamsImpl)2 TServerStatusImpl (org.apache.accumulo.core.manager.balancer.TServerStatusImpl)2 TableInfo (org.apache.accumulo.core.master.thrift.TableInfo)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 RateLimiter (com.google.common.util.concurrent.RateLimiter)1