use of org.apache.accumulo.server.master.state.TabletMigration in project accumulo by apache.
the class HostRegexTableLoadBalancerTest method testOutOfBoundsTablets.
@Test
public void testOutOfBoundsTablets() {
init(new AccumuloServerContext(instance, factory));
// Wait to trigger the out of bounds check which will call our version of getOnlineTabletsForTable
UtilWaitThread.sleep(11000);
Set<KeyExtent> migrations = new HashSet<>();
List<TabletMigration> migrationsOut = new ArrayList<>();
this.balance(createCurrent(15), migrations, migrationsOut);
Assert.assertEquals(2, migrationsOut.size());
}
use of org.apache.accumulo.server.master.state.TabletMigration in project accumulo by apache.
the class TableLoadBalancerTest method test.
@Test
public void test() throws Exception {
final Instance inst = EasyMock.createMock(Instance.class);
EasyMock.expect(inst.getInstanceID()).andReturn(UUID.nameUUIDFromBytes(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }).toString()).anyTimes();
EasyMock.expect(inst.getZooKeepers()).andReturn("10.0.0.1:1234").anyTimes();
EasyMock.expect(inst.getZooKeepersSessionTimeOut()).andReturn(30_000).anyTimes();
EasyMock.replay(inst);
ServerConfigurationFactory confFactory = new ServerConfigurationFactory(inst) {
@Override
public TableConfiguration getTableConfiguration(Table.ID tableId) {
// create a dummy namespaceConfiguration to satisfy requireNonNull in TableConfiguration constructor
NamespaceConfiguration dummyConf = new NamespaceConfiguration(null, inst, null);
return new TableConfiguration(inst, tableId, dummyConf) {
@Override
public String get(Property property) {
// fake the get table configuration so the test doesn't try to look in zookeeper for per-table classpath stuff
return DefaultConfiguration.getInstance().get(property);
}
};
}
};
String t1Id = TABLE_ID_MAP.get("t1"), t2Id = TABLE_ID_MAP.get("t2"), t3Id = TABLE_ID_MAP.get("t3");
state = new TreeMap<>();
TServerInstance svr = mkts("10.0.0.1", "0x01020304");
state.put(svr, status(t1Id, 10, t2Id, 10, t3Id, 10));
Set<KeyExtent> migrations = Collections.emptySet();
List<TabletMigration> migrationsOut = new ArrayList<>();
TableLoadBalancer tls = new TableLoadBalancer();
tls.init(new AccumuloServerContext(inst, confFactory));
tls.balance(state, migrations, migrationsOut);
Assert.assertEquals(0, migrationsOut.size());
state.put(mkts("10.0.0.2", "0x02030405"), status());
tls = new TableLoadBalancer();
tls.init(new AccumuloServerContext(inst, confFactory));
tls.balance(state, migrations, migrationsOut);
int count = 0;
Map<Table.ID, Integer> movedByTable = new HashMap<>();
movedByTable.put(Table.ID.of(t1Id), 0);
movedByTable.put(Table.ID.of(t2Id), 0);
movedByTable.put(Table.ID.of(t3Id), 0);
for (TabletMigration migration : migrationsOut) {
if (migration.oldServer.equals(svr))
count++;
Table.ID key = migration.tablet.getTableId();
movedByTable.put(key, movedByTable.get(key) + 1);
}
Assert.assertEquals(15, count);
for (Integer moved : movedByTable.values()) {
Assert.assertEquals(5, moved.intValue());
}
}
use of org.apache.accumulo.server.master.state.TabletMigration in project accumulo by apache.
the class ChaoticLoadBalancerTest method testUnevenAssignment.
@Test
public void testUnevenAssignment() {
servers.clear();
for (char c : "abcdefghijklmnopqrstuvwxyz".toCharArray()) {
String cString = Character.toString(c);
HostAndPort fakeAddress = HostAndPort.fromParts("127.0.0.1", c);
String fakeInstance = cString;
TServerInstance tsi = new TServerInstance(fakeAddress, fakeInstance);
FakeTServer fakeTServer = new FakeTServer();
servers.put(tsi, fakeTServer);
fakeTServer.extents.add(makeExtent(cString, null, null));
}
// Put more tablets on one server, but not more than the number of servers
Entry<TServerInstance, FakeTServer> first = servers.entrySet().iterator().next();
first.getValue().extents.add(makeExtent("newTable", "a", null));
first.getValue().extents.add(makeExtent("newTable", "b", "a"));
first.getValue().extents.add(makeExtent("newTable", "c", "b"));
first.getValue().extents.add(makeExtent("newTable", "d", "c"));
first.getValue().extents.add(makeExtent("newTable", "e", "d"));
first.getValue().extents.add(makeExtent("newTable", "f", "e"));
first.getValue().extents.add(makeExtent("newTable", "g", "f"));
first.getValue().extents.add(makeExtent("newTable", "h", "g"));
first.getValue().extents.add(makeExtent("newTable", "i", null));
TestChaoticLoadBalancer balancer = new TestChaoticLoadBalancer();
Set<KeyExtent> migrations = Collections.emptySet();
// Just want to make sure it gets some migrations, randomness prevents guarantee of a defined amount, or even expected amount
List<TabletMigration> migrationsOut = new ArrayList<>();
while (migrationsOut.size() != 0) {
balancer.balance(getAssignments(servers), migrations, migrationsOut);
}
}
use of org.apache.accumulo.server.master.state.TabletMigration in project accumulo by apache.
the class DefaultLoadBalancerTest method testUnevenAssignment.
@Test
public void testUnevenAssignment() {
for (char c : "abcdefghijklmnopqrstuvwxyz".toCharArray()) {
String cString = Character.toString(c);
HostAndPort fakeAddress = HostAndPort.fromParts("127.0.0.1", c);
String fakeInstance = cString;
TServerInstance tsi = new TServerInstance(fakeAddress, fakeInstance);
FakeTServer fakeTServer = new FakeTServer();
servers.put(tsi, fakeTServer);
fakeTServer.extents.add(makeExtent(cString, null, null));
}
// Put more tablets on one server, but not more than the number of servers
Entry<TServerInstance, FakeTServer> first = servers.entrySet().iterator().next();
first.getValue().extents.add(makeExtent("newTable", "a", null));
first.getValue().extents.add(makeExtent("newTable", "b", "a"));
first.getValue().extents.add(makeExtent("newTable", "c", "b"));
first.getValue().extents.add(makeExtent("newTable", "d", "c"));
first.getValue().extents.add(makeExtent("newTable", "e", "d"));
first.getValue().extents.add(makeExtent("newTable", "f", "e"));
first.getValue().extents.add(makeExtent("newTable", "g", "f"));
first.getValue().extents.add(makeExtent("newTable", "h", "g"));
first.getValue().extents.add(makeExtent("newTable", "i", null));
TestDefaultLoadBalancer balancer = new TestDefaultLoadBalancer();
Set<KeyExtent> migrations = Collections.emptySet();
int moved = 0;
// balance until we can't balance no more!
while (true) {
List<TabletMigration> migrationsOut = new ArrayList<>();
balancer.balance(getAssignments(servers), migrations, migrationsOut);
if (migrationsOut.size() == 0)
break;
for (TabletMigration migration : migrationsOut) {
if (servers.get(migration.oldServer).extents.remove(migration.tablet))
moved++;
servers.get(migration.newServer).extents.add(migration.tablet);
}
}
assertEquals(8, moved);
}
Aggregations