Search in sources :

Example 1 with BalanceParamsImpl

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

the class TabletBalancer method balance.

@Override
public long balance(BalanceParameters params) {
    BalanceParamsImpl bpi = (BalanceParamsImpl) params;
    List<TabletMigration> migrationsOut = new ArrayList<>();
    long result = balance(bpi.thriftCurrentStatus(), bpi.thriftCurrentMigrations(), migrationsOut);
    migrationsOut.forEach(mo -> bpi.addMigration(mo.tablet, mo.oldServer, mo.newServer));
    return result;
}
Also used : BalanceParamsImpl(org.apache.accumulo.core.manager.balancer.BalanceParamsImpl) TabletMigration(org.apache.accumulo.server.master.state.TabletMigration) ArrayList(java.util.ArrayList)

Example 2 with BalanceParamsImpl

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

the class HostRegexTableLoadBalancerTest method testBalanceWithTooManyOutstandingMigrations.

@Test
public void testBalanceWithTooManyOutstandingMigrations() {
    List<TabletMigration> migrationsOut = new ArrayList<>();
    init(DEFAULT_TABLE_PROPERTIES);
    // lets say we already have migrations ongoing for the FOO and BAR table extends (should be 5 of
    // each of them) for a total of 10
    Set<TabletId> migrations = new HashSet<>();
    migrations.addAll(tableTablets.get(FOO.getTableName()));
    migrations.addAll(tableTablets.get(BAR.getTableName()));
    long wait = this.balance(new BalanceParamsImpl(Collections.unmodifiableSortedMap(createCurrent(15)), migrations, migrationsOut));
    assertEquals(20000, wait);
    // no migrations should have occurred as 10 is the maxOutstandingMigrations
    assertEquals(0, migrationsOut.size());
}
Also used : BalanceParamsImpl(org.apache.accumulo.core.manager.balancer.BalanceParamsImpl) TabletMigration(org.apache.accumulo.core.spi.balancer.data.TabletMigration) ArrayList(java.util.ArrayList) TabletId(org.apache.accumulo.core.data.TabletId) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with BalanceParamsImpl

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

the class HostRegexTableLoadBalancerTest method testBalance.

@Test
public void testBalance() {
    init(DEFAULT_TABLE_PROPERTIES);
    Set<TabletId> migrations = new HashSet<>();
    List<TabletMigration> migrationsOut = new ArrayList<>();
    long wait = this.balance(new BalanceParamsImpl(Collections.unmodifiableSortedMap(createCurrent(15)), migrations, migrationsOut));
    assertEquals(20000, wait);
    // should balance four tablets in one of the tables before reaching max
    assertEquals(4, migrationsOut.size());
    // now balance again passing in the new migrations
    for (TabletMigration m : migrationsOut) {
        migrations.add(m.getTablet());
    }
    migrationsOut.clear();
    wait = this.balance(new BalanceParamsImpl(Collections.unmodifiableSortedMap(createCurrent(15)), migrations, migrationsOut));
    assertEquals(20000, wait);
    // should balance four tablets in one of the other tables before reaching max
    assertEquals(4, migrationsOut.size());
    // now balance again passing in the new migrations
    for (TabletMigration m : migrationsOut) {
        migrations.add(m.getTablet());
    }
    migrationsOut.clear();
    wait = this.balance(new BalanceParamsImpl(Collections.unmodifiableSortedMap(createCurrent(15)), migrations, migrationsOut));
    assertEquals(20000, wait);
    // should balance four tablets in one of the other tables before reaching max
    assertEquals(4, migrationsOut.size());
    // now balance again passing in the new migrations
    for (TabletMigration m : migrationsOut) {
        migrations.add(m.getTablet());
    }
    migrationsOut.clear();
    wait = this.balance(new BalanceParamsImpl(Collections.unmodifiableSortedMap(createCurrent(15)), migrations, migrationsOut));
    assertEquals(20000, wait);
    // no more balancing to do
    assertEquals(0, migrationsOut.size());
}
Also used : BalanceParamsImpl(org.apache.accumulo.core.manager.balancer.BalanceParamsImpl) TabletMigration(org.apache.accumulo.core.spi.balancer.data.TabletMigration) ArrayList(java.util.ArrayList) TabletId(org.apache.accumulo.core.data.TabletId) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 4 with BalanceParamsImpl

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

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

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