use of org.apache.accumulo.core.manager.balancer.TabletServerIdImpl in project accumulo by apache.
the class SimpleLoadBalancer method getAssignment.
public TabletServerId getAssignment(SortedMap<TabletServerId, TServerStatus> locations, TabletServerId last) {
if (locations.isEmpty())
return null;
if (last != null) {
// Maintain locality
String fakeSessionID = " ";
TabletServerId simple = new TabletServerIdImpl(last.getHost(), last.getPort(), fakeSessionID);
Iterator<TabletServerId> find = locations.tailMap(simple).keySet().iterator();
if (find.hasNext()) {
TabletServerId current = find.next();
if (current.getHost().equals(last.getHost()))
return current;
}
}
// in the current list.
if (assignments == null || !assignments.hasNext())
assignments = randomize(locations.keySet()).iterator();
TabletServerId result = assignments.next();
if (!locations.containsKey(result)) {
assignments = null;
return randomize(locations.keySet()).iterator().next();
}
return result;
}
use of org.apache.accumulo.core.manager.balancer.TabletServerIdImpl in project accumulo by apache.
the class GroupBalancer method getAssignments.
@Override
public void getAssignments(AssignmentParameters params) {
if (params.currentStatus().isEmpty()) {
return;
}
Function<TabletId, String> partitioner = getPartitioner();
List<ComparablePair<String, TabletId>> tabletsByGroup = new ArrayList<>();
for (Entry<TabletId, TabletServerId> entry : params.unassignedTablets().entrySet()) {
TabletServerId last = entry.getValue();
if (last != null) {
// Maintain locality
String fakeSessionID = " ";
TabletServerId simple = new TabletServerIdImpl(last.getHost(), last.getPort(), fakeSessionID);
Iterator<TabletServerId> find = params.currentStatus().tailMap(simple).keySet().iterator();
if (find.hasNext()) {
TabletServerId tserver = find.next();
if (tserver.getHost().equals(last.getHost())) {
params.addAssignment(entry.getKey(), tserver);
continue;
}
}
}
tabletsByGroup.add(new ComparablePair<>(partitioner.apply(entry.getKey()), entry.getKey()));
}
Collections.sort(tabletsByGroup);
Iterator<TabletServerId> tserverIter = Iterators.cycle(params.currentStatus().keySet());
for (ComparablePair<String, TabletId> pair : tabletsByGroup) {
TabletId tabletId = pair.getSecond();
params.addAssignment(tabletId, tserverIter.next());
}
}
use of org.apache.accumulo.core.manager.balancer.TabletServerIdImpl in project accumulo by apache.
the class SimpleLoadBalancerTest method testUnevenAssignment2.
@Test
public void testUnevenAssignment2() {
// make 26 servers
for (char c : "abcdefghijklmnopqrstuvwxyz".toCharArray()) {
TabletServerId tsid = new TabletServerIdImpl("127.0.0.1", c, Character.toString(c));
FakeTServer fakeTServer = new FakeTServer();
servers.put(tsid, fakeTServer);
}
// put 60 tablets on 25 of them
List<Entry<TabletServerId, FakeTServer>> shortList = new ArrayList<>(servers.entrySet());
Entry<TabletServerId, FakeTServer> shortServer = shortList.remove(0);
int c = 0;
for (int i = 0; i < 60; i++) {
for (Entry<TabletServerId, FakeTServer> entry : shortList) {
entry.getValue().tablets.add(makeTablet("t" + c, null, null));
}
}
// put 10 on the that short server:
for (int i = 0; i < 10; i++) {
shortServer.getValue().tablets.add(makeTablet("s" + i, null, null));
}
TestSimpleLoadBalancer balancer = new TestSimpleLoadBalancer();
Set<TabletId> migrations = Collections.emptySet();
int moved = 0;
// balance until we can't balance no more!
while (true) {
List<TabletMigration> migrationsOut = new ArrayList<>();
balancer.balance(new BalanceParamsImpl(getAssignments(servers), migrations, migrationsOut));
if (migrationsOut.isEmpty())
break;
for (TabletMigration migration : migrationsOut) {
if (servers.get(migration.getOldTabletServer()).tablets.remove(migration.getTablet()))
moved++;
last.remove(migration.getTablet());
servers.get(migration.getNewTabletServer()).tablets.add(migration.getTablet());
last.put(migration.getTablet(), migration.getNewTabletServer());
}
}
// 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.manager.balancer.TabletServerIdImpl in project accumulo by apache.
the class SimpleLoadBalancerTest method testUnevenAssignment.
@Test
public void testUnevenAssignment() {
for (char c : "abcdefghijklmnopqrstuvwxyz".toCharArray()) {
String cString = Character.toString(c);
TabletServerId tsid = new TabletServerIdImpl("127.0.0.1", c, cString);
FakeTServer fakeTServer = new FakeTServer();
servers.put(tsid, fakeTServer);
fakeTServer.tablets.add(makeTablet(cString, null, null));
}
// Put more tablets on one server, but not more than the number of servers
Entry<TabletServerId, FakeTServer> first = servers.entrySet().iterator().next();
first.getValue().tablets.add(makeTablet("newTable", "a", null));
first.getValue().tablets.add(makeTablet("newTable", "b", "a"));
first.getValue().tablets.add(makeTablet("newTable", "c", "b"));
first.getValue().tablets.add(makeTablet("newTable", "d", "c"));
first.getValue().tablets.add(makeTablet("newTable", "e", "d"));
first.getValue().tablets.add(makeTablet("newTable", "f", "e"));
first.getValue().tablets.add(makeTablet("newTable", "g", "f"));
first.getValue().tablets.add(makeTablet("newTable", "h", "g"));
first.getValue().tablets.add(makeTablet("newTable", "i", null));
TestSimpleLoadBalancer balancer = new TestSimpleLoadBalancer();
Set<TabletId> migrations = Collections.emptySet();
int moved = 0;
// balance until we can't balance no more!
while (true) {
List<TabletMigration> migrationsOut = new ArrayList<>();
balancer.balance(new BalanceParamsImpl(getAssignments(servers), migrations, migrationsOut));
if (migrationsOut.isEmpty())
break;
for (TabletMigration migration : migrationsOut) {
if (servers.get(migration.getOldTabletServer()).tablets.remove(migration.getTablet()))
moved++;
servers.get(migration.getNewTabletServer()).tablets.add(migration.getTablet());
}
}
assertEquals(8, moved);
}
Aggregations