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