Search in sources :

Example 1 with TabletStats

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;
}
Also used : TabletStats(org.apache.accumulo.core.tabletserver.thrift.TabletStats) ArrayList(java.util.ArrayList) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance)

Example 2 with TabletStats

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;
}
Also used : TabletStats(org.apache.accumulo.core.tabletserver.thrift.TabletStats) ArrayList(java.util.ArrayList) TKeyExtent(org.apache.accumulo.core.data.thrift.TKeyExtent)

Example 3 with TabletStats

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;
}
Also used : TabletStats(org.apache.accumulo.core.tabletserver.thrift.TabletStats) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus)

Example 4 with TabletStats

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;
}
Also used : TException(org.apache.thrift.TException) Table(org.apache.accumulo.core.client.impl.Table) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) TabletMigration(org.apache.accumulo.server.master.state.TabletMigration) HashMap(java.util.HashMap) TabletStats(org.apache.accumulo.core.tabletserver.thrift.TabletStats) ArrayList(java.util.ArrayList) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) TableInfo(org.apache.accumulo.core.master.thrift.TableInfo) TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus)

Example 5 with TabletStats

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;
}
Also used : TabletStats(org.apache.accumulo.core.tabletserver.thrift.TabletStats) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent)

Aggregations

TabletStats (org.apache.accumulo.core.tabletserver.thrift.TabletStats)9 ArrayList (java.util.ArrayList)8 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)7 Table (org.apache.accumulo.core.client.impl.Table)4 TabletServerStatus (org.apache.accumulo.core.master.thrift.TabletServerStatus)4 TServerInstance (org.apache.accumulo.server.master.state.TServerInstance)3 TabletMigration (org.apache.accumulo.server.master.state.TabletMigration)3 TableInfo (org.apache.accumulo.core.master.thrift.TableInfo)2 TException (org.apache.thrift.TException)2 MessageDigest (java.security.MessageDigest)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 TableOperations (org.apache.accumulo.core.client.admin.TableOperations)1 ClientContext (org.apache.accumulo.core.client.impl.ClientContext)1 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)1