Search in sources :

Example 6 with AssignmentParamsImpl

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

the class HostRegexTableLoadBalancerTest method testPartiallyAssigned.

@Test
public void testPartiallyAssigned() {
    init(DEFAULT_TABLE_PROPERTIES);
    Map<TabletId, TabletServerId> assignments = new HashMap<>();
    Map<TabletId, TabletServerId> unassigned = new HashMap<>();
    int i = 0;
    for (List<TabletId> tablets : tableTablets.values()) {
        for (TabletId tabletId : tablets) {
            if ((i % 2) == 0) {
                unassigned.put(tabletId, null);
            }
            i++;
        }
    }
    this.getAssignments(new AssignmentParamsImpl(Collections.unmodifiableSortedMap(allTabletServers), Collections.unmodifiableMap(unassigned), assignments));
    assertEquals(unassigned.size(), assignments.size());
    // Ensure unique tservers
    for (Entry<TabletId, TabletServerId> e : assignments.entrySet()) {
        for (Entry<TabletId, TabletServerId> e2 : assignments.entrySet()) {
            if (e.getKey().equals(e2.getKey())) {
                continue;
            }
            if (e.getValue().equals(e2.getValue())) {
                fail("Assignment failure");
            }
        }
    }
    // Ensure assignments are correct
    for (Entry<TabletId, TabletServerId> e : assignments.entrySet()) {
        if (!tabletInBounds(e.getKey(), e.getValue())) {
            fail("tablet not in bounds: " + e.getKey() + " -> " + e.getValue().getHost());
        }
    }
}
Also used : HashMap(java.util.HashMap) TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) TabletId(org.apache.accumulo.core.data.TabletId) AssignmentParamsImpl(org.apache.accumulo.core.manager.balancer.AssignmentParamsImpl) Test(org.junit.jupiter.api.Test)

Example 7 with AssignmentParamsImpl

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

the class HostRegexTableLoadBalancerReconfigurationTest method testConfigurationChanges.

@Test
public void testConfigurationChanges() {
    HashMap<String, TableId> tables = new HashMap<>();
    tables.put(FOO.getTableName(), FOO.getId());
    tables.put(BAR.getTableName(), BAR.getId());
    tables.put(BAZ.getTableName(), BAZ.getId());
    ConfigurationCopy config = new ConfigurationCopy(SiteConfiguration.auto());
    DEFAULT_TABLE_PROPERTIES.forEach(config::set);
    ConfigurationImpl configImpl = new ConfigurationImpl(config);
    BalancerEnvironment environment = createMock(BalancerEnvironment.class);
    expect(environment.getConfiguration()).andReturn(configImpl).anyTimes();
    expect(environment.getTableIdMap()).andReturn(tables).anyTimes();
    expect(environment.getConfiguration(anyObject(TableId.class))).andReturn(configImpl).anyTimes();
    replay(environment);
    init(environment);
    Map<TabletId, TabletServerId> unassigned = new HashMap<>();
    for (List<TabletId> tablets : tableTablets.values()) {
        for (TabletId tablet : tablets) {
            unassigned.put(tablet, null);
        }
    }
    this.getAssignments(new AssignmentParamsImpl(Collections.unmodifiableSortedMap(allTabletServers), Collections.unmodifiableMap(unassigned), assignments));
    assertEquals(15, assignments.size());
    // Ensure unique tservers
    for (Entry<TabletId, TabletServerId> e : assignments.entrySet()) {
        for (Entry<TabletId, TabletServerId> e2 : assignments.entrySet()) {
            if (e.getKey().equals(e2.getKey())) {
                continue;
            }
            if (e.getValue().equals(e2.getValue())) {
                fail("Assignment failure. " + e.getKey() + " and " + e2.getKey() + " are assigned to the same host: " + e.getValue());
            }
        }
    }
    // Ensure assignments are correct
    for (Entry<TabletId, TabletServerId> e : assignments.entrySet()) {
        if (!tabletInBounds(e.getKey(), e.getValue())) {
            fail("tablet not in bounds: " + e.getKey() + " -> " + e.getValue().getHost());
        }
    }
    Set<TabletId> migrations = new HashSet<>();
    List<TabletMigration> migrationsOut = new ArrayList<>();
    // Wait to trigger the out of bounds check which will call our version of
    // getOnlineTabletsForTable
    UtilWaitThread.sleep(3000);
    this.balance(new BalanceParamsImpl(Collections.unmodifiableSortedMap(allTabletServers), migrations, migrationsOut));
    assertEquals(0, migrationsOut.size());
    // Change property, simulate call by TableConfWatcher
    config.set(HostRegexTableLoadBalancer.HOST_BALANCER_PREFIX + BAR.getTableName(), "r01.*");
    // Wait to trigger the out of bounds check and the repool check
    UtilWaitThread.sleep(10000);
    this.balance(new BalanceParamsImpl(Collections.unmodifiableSortedMap(allTabletServers), migrations, migrationsOut));
    assertEquals(5, migrationsOut.size());
    for (TabletMigration migration : migrationsOut) {
        assertTrue(migration.getNewTabletServer().getHost().startsWith("192.168.0.1") || migration.getNewTabletServer().getHost().startsWith("192.168.0.2") || migration.getNewTabletServer().getHost().startsWith("192.168.0.3") || migration.getNewTabletServer().getHost().startsWith("192.168.0.4") || migration.getNewTabletServer().getHost().startsWith("192.168.0.5"));
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) BalanceParamsImpl(org.apache.accumulo.core.manager.balancer.BalanceParamsImpl) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) TabletMigration(org.apache.accumulo.core.spi.balancer.data.TabletMigration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AssignmentParamsImpl(org.apache.accumulo.core.manager.balancer.AssignmentParamsImpl) TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) TabletId(org.apache.accumulo.core.data.TabletId) ConfigurationImpl(org.apache.accumulo.core.util.ConfigurationImpl) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 8 with AssignmentParamsImpl

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

the class ChaoticLoadBalancerTest method testAssignMigrations.

@Test
public void testAssignMigrations() {
    servers.clear();
    servers.put(new TabletServerIdImpl("127.0.0.1", 1234, "a"), new FakeTServer());
    servers.put(new TabletServerIdImpl("127.0.0.1", 1235, "b"), new FakeTServer());
    servers.put(new TabletServerIdImpl("127.0.0.1", 1236, "c"), new FakeTServer());
    Map<TabletId, TabletServerId> metadataTable = new TreeMap<>();
    String table = "t1";
    metadataTable.put(makeTablet(table, null, null), null);
    table = "t2";
    metadataTable.put(makeTablet(table, "a", null), null);
    metadataTable.put(makeTablet(table, null, "a"), null);
    table = "t3";
    metadataTable.put(makeTablet(table, "a", null), null);
    metadataTable.put(makeTablet(table, "b", "a"), null);
    metadataTable.put(makeTablet(table, "c", "b"), null);
    metadataTable.put(makeTablet(table, "d", "c"), null);
    metadataTable.put(makeTablet(table, "e", "d"), null);
    metadataTable.put(makeTablet(table, null, "e"), null);
    TestChaoticLoadBalancer balancer = new TestChaoticLoadBalancer();
    Map<TabletId, TabletServerId> assignments = new HashMap<>();
    balancer.getAssignments(new AssignmentParamsImpl(getAssignments(servers), metadataTable, assignments));
    assertEquals(assignments.size(), metadataTable.size());
}
Also used : HashMap(java.util.HashMap) TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) TabletId(org.apache.accumulo.core.data.TabletId) TabletServerIdImpl(org.apache.accumulo.core.manager.balancer.TabletServerIdImpl) TreeMap(java.util.TreeMap) AssignmentParamsImpl(org.apache.accumulo.core.manager.balancer.AssignmentParamsImpl) Test(org.junit.Test)

Example 9 with AssignmentParamsImpl

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

the class HostRegexTableLoadBalancer method getAssignments.

@Override
public void getAssignments(AssignmentParameters params) {
    Map<String, SortedMap<TabletServerId, TServerStatus>> pools = splitCurrentByRegex(params.currentStatus());
    // group the unassigned into tables
    Map<TableId, Map<TabletId, TabletServerId>> groupedUnassigned = new HashMap<>();
    params.unassignedTablets().forEach((ke, lastTserver) -> groupedUnassigned.computeIfAbsent(ke.getTable(), k -> new HashMap<>()).put(ke, lastTserver));
    Map<TableId, String> tableIdToTableName = environment.getTableIdMap().entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));
    // Send a view of the current servers to the tables tablet balancer
    for (Entry<TableId, Map<TabletId, TabletServerId>> e : groupedUnassigned.entrySet()) {
        Map<TabletId, TabletServerId> newAssignments = new HashMap<>();
        String tableName = tableIdToTableName.get(e.getKey());
        String poolName = getPoolNameForTable(tableName);
        SortedMap<TabletServerId, TServerStatus> currentView = pools.get(poolName);
        if (currentView == null || currentView.isEmpty()) {
            LOG.warn("No tablet servers online for table {}, assigning within default pool", tableName);
            currentView = pools.get(DEFAULT_POOL);
            if (currentView == null) {
                LOG.error("No tablet servers exist in the default pool, unable to assign tablets for table {}", tableName);
                continue;
            }
        }
        LOG.debug("Sending {} tablets to balancer for table {} for assignment within tservers {}", e.getValue().size(), tableName, currentView.keySet());
        getBalancerForTable(e.getKey()).getAssignments(new AssignmentParamsImpl(currentView, e.getValue(), newAssignments));
        newAssignments.forEach(params::addAssignment);
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) HashMap(java.util.HashMap) TServerStatus(org.apache.accumulo.core.spi.balancer.data.TServerStatus) AssignmentParamsImpl(org.apache.accumulo.core.manager.balancer.AssignmentParamsImpl) TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) SortedMap(java.util.SortedMap) TabletId(org.apache.accumulo.core.data.TabletId) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 10 with AssignmentParamsImpl

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

the class TabletBalancer method getAssignments.

@Override
public void getAssignments(AssignmentParameters params) {
    AssignmentParamsImpl api = (AssignmentParamsImpl) params;
    getAssignments(api.thriftCurrentStatus(), api.thriftUnassigned(), api.thriftAssignmentsOut());
}
Also used : AssignmentParamsImpl(org.apache.accumulo.core.manager.balancer.AssignmentParamsImpl)

Aggregations

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