Search in sources :

Example 1 with ConfigurationImpl

use of org.apache.accumulo.core.util.ConfigurationImpl in project accumulo by apache.

the class HostRegexTableLoadBalancerTest method init.

public void init(Map<String, String> tableProperties) {
    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());
    tableProperties.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);
}
Also used : TableId(org.apache.accumulo.core.data.TableId) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) HashMap(java.util.HashMap) ConfigurationImpl(org.apache.accumulo.core.util.ConfigurationImpl)

Example 2 with ConfigurationImpl

use of org.apache.accumulo.core.util.ConfigurationImpl in project accumulo by apache.

the class TableLoadBalancerTest method test.

@Test
public void test() {
    BalancerEnvironment environment = createMock(BalancerEnvironment.class);
    ConfigurationCopy cc = new ConfigurationCopy(Map.of(Property.TABLE_LOAD_BALANCER.getKey(), TestSimpleLoadBalancer.class.getName()));
    ConfigurationImpl tableConfig = new ConfigurationImpl(cc);
    Map<String, TableId> tableIdMap = TABLE_ID_MAP.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> TableId.of(e.getValue())));
    expect(environment.getTableIdMap()).andReturn(tableIdMap).anyTimes();
    expect(environment.isTableOnline(anyObject(TableId.class))).andReturn(true).anyTimes();
    expect(environment.getConfiguration(anyObject(TableId.class))).andReturn(tableConfig).anyTimes();
    expect(environment.tableContext(anyObject(TableId.class))).andReturn(null).anyTimes();
    replay(environment);
    String t1Id = TABLE_ID_MAP.get("t1"), t2Id = TABLE_ID_MAP.get("t2"), t3Id = TABLE_ID_MAP.get("t3");
    state = new TreeMap<>();
    TabletServerId svr = mkts("10.0.0.1", 1234, "0x01020304");
    state.put(svr, status(t1Id, 10, t2Id, 10, t3Id, 10));
    Set<TabletId> migrations = Collections.emptySet();
    List<TabletMigration> migrationsOut = new ArrayList<>();
    TableLoadBalancer tls = new TableLoadBalancer();
    tls.init(environment);
    tls.balance(new BalanceParamsImpl(state, migrations, migrationsOut));
    assertEquals(0, migrationsOut.size());
    state.put(mkts("10.0.0.2", 2345, "0x02030405"), status());
    tls = new TableLoadBalancer();
    tls.init(environment);
    tls.balance(new BalanceParamsImpl(state, migrations, migrationsOut));
    int count = 0;
    Map<TableId, Integer> movedByTable = new HashMap<>();
    movedByTable.put(TableId.of(t1Id), 0);
    movedByTable.put(TableId.of(t2Id), 0);
    movedByTable.put(TableId.of(t3Id), 0);
    for (TabletMigration migration : migrationsOut) {
        if (migration.getOldTabletServer().equals(svr)) {
            count++;
        }
        TableId key = migration.getTablet().getTable();
        movedByTable.put(key, movedByTable.get(key) + 1);
    }
    assertEquals(15, count);
    for (Integer moved : movedByTable.values()) {
        assertEquals(5, moved.intValue());
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TableId(org.apache.accumulo.core.data.TableId) TableInfo(org.apache.accumulo.core.master.thrift.TableInfo) TServerStatusImpl(org.apache.accumulo.core.manager.balancer.TServerStatusImpl) ConfigurationImpl(org.apache.accumulo.core.util.ConfigurationImpl) Text(org.apache.hadoop.io.Text) HashMap(java.util.HashMap) TabletStatistics(org.apache.accumulo.core.spi.balancer.data.TabletStatistics) TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) ArrayList(java.util.ArrayList) TServerStatus(org.apache.accumulo.core.spi.balancer.data.TServerStatus) Map(java.util.Map) EasyMock.replay(org.easymock.EasyMock.replay) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EasyMock.createMock(org.easymock.EasyMock.createMock) BalanceParamsImpl(org.apache.accumulo.core.manager.balancer.BalanceParamsImpl) Property(org.apache.accumulo.core.conf.Property) EasyMock.anyObject(org.easymock.EasyMock.anyObject) TabletStats(org.apache.accumulo.core.tabletserver.thrift.TabletStats) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) Set(java.util.Set) TabletMigration(org.apache.accumulo.core.spi.balancer.data.TabletMigration) EasyMock.expect(org.easymock.EasyMock.expect) TabletId(org.apache.accumulo.core.data.TabletId) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) TabletServerIdImpl(org.apache.accumulo.core.manager.balancer.TabletServerIdImpl) TreeMap(java.util.TreeMap) TabletStatisticsImpl(org.apache.accumulo.core.manager.balancer.TabletStatisticsImpl) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) Collections(java.util.Collections) SortedMap(java.util.SortedMap) 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) TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) TabletId(org.apache.accumulo.core.data.TabletId) ConfigurationImpl(org.apache.accumulo.core.util.ConfigurationImpl) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) Test(org.junit.jupiter.api.Test)

Example 3 with ConfigurationImpl

use of org.apache.accumulo.core.util.ConfigurationImpl 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)

Aggregations

HashMap (java.util.HashMap)3 ConfigurationCopy (org.apache.accumulo.core.conf.ConfigurationCopy)3 TableId (org.apache.accumulo.core.data.TableId)3 ConfigurationImpl (org.apache.accumulo.core.util.ConfigurationImpl)3 ArrayList (java.util.ArrayList)2 TabletId (org.apache.accumulo.core.data.TabletId)2 BalanceParamsImpl (org.apache.accumulo.core.manager.balancer.BalanceParamsImpl)2 TabletMigration (org.apache.accumulo.core.spi.balancer.data.TabletMigration)2 TabletServerId (org.apache.accumulo.core.spi.balancer.data.TabletServerId)2 Test (org.junit.jupiter.api.Test)2 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 Collectors (java.util.stream.Collectors)1 Property (org.apache.accumulo.core.conf.Property)1 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)1