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;
}
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());
}
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());
}
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());
}
}
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"));
}
}
Aggregations