use of org.apache.accumulo.core.tabletserver.thrift.TabletStats in project accumulo by apache.
the class HostRegexTableLoadBalancerReconfigurationTest method getOnlineTabletsForTable.
@Override
public List<TabletStats> getOnlineTabletsForTable(TServerInstance tserver, Table.ID tableId) throws ThriftSecurityException, TException {
List<TabletStats> tablets = new ArrayList<>();
// Report assignment information
for (Entry<KeyExtent, TServerInstance> e : this.assignments.entrySet()) {
if (e.getValue().equals(tserver) && e.getKey().getTableId().equals(tableId)) {
TabletStats ts = new TabletStats();
ts.setExtent(e.getKey().toThrift());
tablets.add(ts);
}
}
return tablets;
}
use of org.apache.accumulo.core.tabletserver.thrift.TabletStats in project accumulo by apache.
the class HostRegexTableLoadBalancerTest method getOnlineTabletsForTable.
@Override
public List<TabletStats> getOnlineTabletsForTable(TServerInstance tserver, Table.ID tableId) throws TException {
// Report incorrect information so that balance will create an assignment
List<TabletStats> tablets = new ArrayList<>();
if (tableId.equals(BAR.getId()) && tserver.host().equals("192.168.0.1")) {
// Report that we have a bar tablet on this server
TKeyExtent tke = new TKeyExtent();
tke.setTable(BAR.getId().getUtf8());
tke.setEndRow("11".getBytes());
tke.setPrevEndRow("10".getBytes());
TabletStats ts = new TabletStats();
ts.setExtent(tke);
tablets.add(ts);
} else if (tableId.equals(FOO.getId()) && tserver.host().equals("192.168.0.6")) {
// Report that we have a foo tablet on this server
TKeyExtent tke = new TKeyExtent();
tke.setTable(FOO.getId().getUtf8());
tke.setEndRow("1".getBytes());
tke.setPrevEndRow("0".getBytes());
TabletStats ts = new TabletStats();
ts.setExtent(tke);
tablets.add(ts);
}
return tablets;
}
use of org.apache.accumulo.core.tabletserver.thrift.TabletStats in project accumulo by apache.
the class TableLoadBalancerTest method generateFakeTablets.
static List<TabletStats> generateFakeTablets(TServerInstance tserver, Table.ID tableId) {
List<TabletStats> result = new ArrayList<>();
TabletServerStatus tableInfo = state.get(tserver);
// generate some fake tablets
for (int i = 0; i < tableInfo.tableMap.get(tableId.canonicalID()).onlineTablets; i++) {
TabletStats stats = new TabletStats();
stats.extent = new KeyExtent(tableId, new Text(tserver.host() + String.format("%03d", i + 1)), new Text(tserver.host() + String.format("%03d", i))).toThrift();
result.add(stats);
}
return result;
}
use of org.apache.accumulo.core.tabletserver.thrift.TabletStats in project accumulo by apache.
the class ChaoticLoadBalancer method balance.
@Override
public long balance(SortedMap<TServerInstance, TabletServerStatus> current, Set<KeyExtent> migrations, List<TabletMigration> migrationsOut) {
Map<TServerInstance, Long> numTablets = new HashMap<>();
List<TServerInstance> underCapacityTServer = new ArrayList<>();
if (!migrations.isEmpty()) {
outstandingMigrations.migrations = migrations;
constraintNotMet(outstandingMigrations);
return 100;
}
resetBalancerErrors();
boolean moveMetadata = r.nextInt(4) == 0;
long totalTablets = 0;
for (Entry<TServerInstance, TabletServerStatus> e : current.entrySet()) {
long tabletCount = 0;
for (TableInfo ti : e.getValue().getTableMap().values()) {
tabletCount += ti.tablets;
}
numTablets.put(e.getKey(), tabletCount);
underCapacityTServer.add(e.getKey());
totalTablets += tabletCount;
}
// totalTablets is fuzzy due to asynchronicity of the stats
// *1.2 to handle fuzziness, and prevent locking for 'perfect' balancing scenarios
long avg = (long) Math.ceil(((double) totalTablets) / current.size() * 1.2);
for (Entry<TServerInstance, TabletServerStatus> e : current.entrySet()) {
for (String tableId : e.getValue().getTableMap().keySet()) {
Table.ID id = Table.ID.of(tableId);
if (!moveMetadata && MetadataTable.ID.equals(id))
continue;
try {
for (TabletStats ts : getOnlineTabletsForTable(e.getKey(), id)) {
KeyExtent ke = new KeyExtent(ts.extent);
int index = r.nextInt(underCapacityTServer.size());
TServerInstance dest = underCapacityTServer.get(index);
if (dest.equals(e.getKey()))
continue;
migrationsOut.add(new TabletMigration(ke, e.getKey(), dest));
if (numTablets.put(dest, numTablets.get(dest) + 1) > avg)
underCapacityTServer.remove(index);
if (numTablets.put(e.getKey(), numTablets.get(e.getKey()) - 1) <= avg && !underCapacityTServer.contains(e.getKey()))
underCapacityTServer.add(e.getKey());
// We can get some craziness with only 1 tserver, so lets make sure there's always an option!
if (underCapacityTServer.isEmpty())
underCapacityTServer.addAll(numTablets.keySet());
}
} catch (ThriftSecurityException e1) {
// Shouldn't happen, but carry on if it does
log.debug("Encountered ThriftSecurityException. This should not happen. Carrying on anyway.", e1);
} catch (TException e1) {
// Shouldn't happen, but carry on if it does
log.debug("Encountered TException. This should not happen. Carrying on anyway.", e1);
}
}
}
return 100;
}
use of org.apache.accumulo.core.tabletserver.thrift.TabletStats in project accumulo by apache.
the class DefaultLoadBalancer method selectTablet.
static KeyExtent selectTablet(TServerInstance tserver, Map<KeyExtent, TabletStats> extents) {
if (extents.size() == 0)
return null;
KeyExtent mostRecentlySplit = null;
long splitTime = 0;
for (Entry<KeyExtent, TabletStats> entry : extents.entrySet()) if (entry.getValue().splitCreationTime >= splitTime) {
splitTime = entry.getValue().splitCreationTime;
mostRecentlySplit = entry.getKey();
}
return mostRecentlySplit;
}
Aggregations