Search in sources :

Example 21 with TabletServerId

use of org.apache.accumulo.core.spi.balancer.data.TabletServerId 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 22 with TabletServerId

use of org.apache.accumulo.core.spi.balancer.data.TabletServerId in project accumulo by apache.

the class HostRegexTableLoadBalancerReconfigurationTest method getOnlineTabletsForTable.

@Override
public List<TabletStatistics> getOnlineTabletsForTable(TabletServerId tserver, TableId tableId) {
    List<TabletStatistics> tablets = new ArrayList<>();
    // Report assignment information
    for (Entry<TabletId, TabletServerId> e : this.assignments.entrySet()) {
        if (e.getValue().equals(tserver) && e.getKey().getTable().equals(tableId)) {
            TabletStats ts = new TabletStats();
            TabletId tid = e.getKey();
            ts.setExtent(new KeyExtent(tid.getTable(), tid.getEndRow(), tid.getPrevEndRow()).toThrift());
            tablets.add(new TabletStatisticsImpl(ts));
        }
    }
    return tablets;
}
Also used : TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) TabletStats(org.apache.accumulo.core.tabletserver.thrift.TabletStats) ArrayList(java.util.ArrayList) TabletStatistics(org.apache.accumulo.core.spi.balancer.data.TabletStatistics) TabletId(org.apache.accumulo.core.data.TabletId) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) TabletStatisticsImpl(org.apache.accumulo.core.manager.balancer.TabletStatisticsImpl)

Example 23 with TabletServerId

use of org.apache.accumulo.core.spi.balancer.data.TabletServerId in project accumulo by apache.

the class SimpleLoadBalancerTest method assignTablets.

private void assignTablets(List<TabletId> metadataTable, Map<TabletServerId, FakeTServer> servers, SortedMap<TabletServerId, TServerStatus> status, TestSimpleLoadBalancer balancer) {
    // Assign tablets
    for (TabletId tabletId : metadataTable) {
        TabletServerId assignment = balancer.getAssignment(status, last.get(tabletId));
        assertNotNull(assignment);
        assertFalse(servers.get(assignment).tablets.contains(tabletId));
        servers.get(assignment).tablets.add(tabletId);
        last.put(tabletId, assignment);
    }
}
Also used : TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) TabletId(org.apache.accumulo.core.data.TabletId)

Example 24 with TabletServerId

use of org.apache.accumulo.core.spi.balancer.data.TabletServerId 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 25 with TabletServerId

use of org.apache.accumulo.core.spi.balancer.data.TabletServerId 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

TabletServerId (org.apache.accumulo.core.spi.balancer.data.TabletServerId)26 TabletId (org.apache.accumulo.core.data.TabletId)22 HashMap (java.util.HashMap)17 ArrayList (java.util.ArrayList)14 TabletMigration (org.apache.accumulo.core.spi.balancer.data.TabletMigration)11 AssignmentParamsImpl (org.apache.accumulo.core.manager.balancer.AssignmentParamsImpl)10 TabletServerIdImpl (org.apache.accumulo.core.manager.balancer.TabletServerIdImpl)10 TServerStatus (org.apache.accumulo.core.spi.balancer.data.TServerStatus)10 Test (org.junit.jupiter.api.Test)10 TableId (org.apache.accumulo.core.data.TableId)8 TreeMap (java.util.TreeMap)7 BalanceParamsImpl (org.apache.accumulo.core.manager.balancer.BalanceParamsImpl)7 Map (java.util.Map)6 SortedMap (java.util.SortedMap)5 TServerStatusImpl (org.apache.accumulo.core.manager.balancer.TServerStatusImpl)4 TabletStatistics (org.apache.accumulo.core.spi.balancer.data.TabletStatistics)4 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)3 TableInfo (org.apache.accumulo.core.master.thrift.TableInfo)3 TableStatistics (org.apache.accumulo.core.spi.balancer.data.TableStatistics)3 Collections (java.util.Collections)2