use of org.apache.accumulo.core.spi.balancer.data.TabletServerId 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.spi.balancer.data.TabletServerId in project accumulo by apache.
the class HostRegexTableLoadBalancerReconfigurationTest method getOnlineTabletsForTable.
@Override
public List<TabletStatistics> getOnlineTabletsForTable(TabletServerId tserver, TableId tableId) {
List<TabletStatistics> tablets = new ArrayList<>();
// Report assignment information
for (Entry<TabletId, TabletServerId> e : this.assignments.entrySet()) {
if (e.getValue().equals(tserver) && e.getKey().getTable().equals(tableId)) {
TabletStats ts = new TabletStats();
TabletId tid = e.getKey();
ts.setExtent(new KeyExtent(tid.getTable(), tid.getEndRow(), tid.getPrevEndRow()).toThrift());
tablets.add(new TabletStatisticsImpl(ts));
}
}
return tablets;
}
use of org.apache.accumulo.core.spi.balancer.data.TabletServerId in project accumulo by apache.
the class SimpleLoadBalancerTest method assignTablets.
private void assignTablets(List<TabletId> metadataTable, Map<TabletServerId, FakeTServer> servers, SortedMap<TabletServerId, TServerStatus> status, TestSimpleLoadBalancer balancer) {
// Assign tablets
for (TabletId tabletId : metadataTable) {
TabletServerId assignment = balancer.getAssignment(status, last.get(tabletId));
assertNotNull(assignment);
assertFalse(servers.get(assignment).tablets.contains(tabletId));
servers.get(assignment).tablets.add(tabletId);
last.put(tabletId, assignment);
}
}
use of org.apache.accumulo.core.spi.balancer.data.TabletServerId 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.spi.balancer.data.TabletServerId 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