use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.
the class DefaultLoadBalancerTest method testUnevenAssignment2.
@Test
public void testUnevenAssignment2() {
// make 26 servers
for (char c : "abcdefghijklmnopqrstuvwxyz".toCharArray()) {
String cString = Character.toString(c);
HostAndPort fakeAddress = HostAndPort.fromParts("127.0.0.1", c);
TServerInstance tsi = new TServerInstance(fakeAddress, cString);
FakeTServer fakeTServer = new FakeTServer();
servers.put(tsi, fakeTServer);
}
// put 60 tablets on 25 of them
List<Entry<TServerInstance, FakeTServer>> shortList = new ArrayList<>(servers.entrySet());
Entry<TServerInstance, FakeTServer> shortServer = shortList.remove(0);
int c = 0;
for (int i = 0; i < 60; i++) {
for (Entry<TServerInstance, FakeTServer> entry : shortList) {
entry.getValue().extents.add(makeExtent("t" + c, null, null));
}
}
// put 10 on the that short server:
for (int i = 0; i < 10; i++) {
shortServer.getValue().extents.add(makeExtent("s" + i, null, 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.isEmpty())
break;
for (TabletMigration migration : migrationsOut) {
if (servers.get(migration.oldServer).extents.remove(migration.tablet))
moved++;
last.remove(migration.tablet);
servers.get(migration.newServer).extents.add(migration.tablet);
last.put(migration.tablet, migration.newServer);
}
}
// average is 58, with 2 at 59: we need 48 more moved to the short server
assertEquals(48, moved);
}
use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.
the class TableLoadBalancerTest method test.
@Test
public void test() {
final ServerContext context = createMockContext();
TableConfiguration conf = createMock(TableConfiguration.class);
// Eclipse might show @SuppressWarnings("removal") as unnecessary.
// Eclipse is wrong. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=565271
@SuppressWarnings("removal") Property TABLE_CLASSPATH = Property.TABLE_CLASSPATH;
expect(conf.resolve(Property.TABLE_CLASSLOADER_CONTEXT, TABLE_CLASSPATH)).andReturn(Property.TABLE_CLASSLOADER_CONTEXT).anyTimes();
expect(conf.get(Property.TABLE_CLASSLOADER_CONTEXT)).andReturn("").anyTimes();
expect(context.getTableConfiguration(EasyMock.anyObject())).andReturn(conf).anyTimes();
replay(context, conf);
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(context);
tls.balance(state, migrations, migrationsOut);
assertEquals(0, migrationsOut.size());
state.put(mkts("10.0.0.2", "0x02030405"), status());
tls = new TableLoadBalancer();
tls.init(context);
tls.balance(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.oldServer.equals(svr)) {
count++;
}
TableId key = migration.tablet.tableId();
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.metadata.TServerInstance in project accumulo by apache.
the class TabletLocationStateTest method testGetState_Dead2.
@Test
public void testGetState_Dead2() throws Exception {
Set<TServerInstance> liveServers = new java.util.HashSet<>();
liveServers.add(future);
tls = new TabletLocationState(keyExtent, null, current, last, null, walogs, true);
assertEquals(TabletState.ASSIGNED_TO_DEAD_SERVER, tls.getState(liveServers));
}
use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.
the class TabletLocationStateTest method testGetState_Assigned.
@Test
public void testGetState_Assigned() throws Exception {
Set<TServerInstance> liveServers = new java.util.HashSet<>();
liveServers.add(future);
tls = new TabletLocationState(keyExtent, future, null, last, null, walogs, true);
assertEquals(TabletState.ASSIGNED, tls.getState(liveServers));
}
use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.
the class ManagerMetadataUtil method updateTabletDataFile.
/**
* Update tablet file data from flush. Returns a StoredTabletFile if there are data entries.
*/
public static Optional<StoredTabletFile> updateTabletDataFile(ServerContext context, KeyExtent extent, TabletFile newDatafile, DataFileValue dfv, MetadataTime time, String address, ServiceLock zooLock, Set<String> unusedWalLogs, TServerInstance lastLocation, long flushId) {
TabletMutator tablet = context.getAmple().mutateTablet(extent);
// if there are no entries, the path doesn't get stored in metadata table, only the flush ID
Optional<StoredTabletFile> newFile = Optional.empty();
// if entries are present, write to path to metadata table
if (dfv.getNumEntries() > 0) {
tablet.putFile(newDatafile, dfv);
tablet.putTime(time);
newFile = Optional.of(newDatafile.insert());
TServerInstance self = getTServerInstance(address, zooLock);
tablet.putLocation(self, LocationType.LAST);
// remove the old location
if (lastLocation != null && !lastLocation.equals(self)) {
tablet.deleteLocation(lastLocation, LocationType.LAST);
}
}
tablet.putFlushId(flushId);
unusedWalLogs.forEach(tablet::deleteWal);
tablet.putZooLock(zooLock);
tablet.mutate();
return newFile;
}
Aggregations