Search in sources :

Example 1 with TableState

use of org.apache.accumulo.core.master.state.tables.TableState in project accumulo by apache.

the class Master method onlineTables.

@Override
public Set<Table.ID> onlineTables() {
    Set<Table.ID> result = new HashSet<>();
    if (getMasterState() != MasterState.NORMAL) {
        if (getMasterState() != MasterState.UNLOAD_METADATA_TABLETS)
            result.add(MetadataTable.ID);
        if (getMasterState() != MasterState.UNLOAD_ROOT_TABLET)
            result.add(RootTable.ID);
        return result;
    }
    TableManager manager = TableManager.getInstance();
    for (Table.ID tableId : Tables.getIdToNameMap(getInstance()).keySet()) {
        TableState state = manager.getTableState(tableId);
        if (state != null) {
            if (state == TableState.ONLINE)
                result.add(tableId);
        }
    }
    return result;
}
Also used : RootTable(org.apache.accumulo.core.metadata.RootTable) Table(org.apache.accumulo.core.client.impl.Table) ReplicationTable(org.apache.accumulo.core.replication.ReplicationTable) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) TableManager(org.apache.accumulo.server.tables.TableManager) HashSet(java.util.HashSet) TableState(org.apache.accumulo.core.master.state.tables.TableState)

Example 2 with TableState

use of org.apache.accumulo.core.master.state.tables.TableState in project accumulo by apache.

the class TabletGroupWatcher method cancelOfflineTableMigrations.

private void cancelOfflineTableMigrations(TabletLocationState tls) {
    TServerInstance dest = this.master.migrations.get(tls.extent);
    TableState tableState = TableManager.getInstance().getTableState(tls.extent.getTableId());
    if (dest != null && tableState == TableState.OFFLINE) {
        this.master.migrations.remove(tls.extent);
    }
}
Also used : TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) TableState(org.apache.accumulo.core.master.state.tables.TableState)

Example 3 with TableState

use of org.apache.accumulo.core.master.state.tables.TableState in project accumulo by apache.

the class TableOperationsImpl method waitForTableStateTransition.

private void waitForTableStateTransition(Table.ID tableId, TableState expectedState) throws AccumuloException, TableNotFoundException, AccumuloSecurityException {
    Text startRow = null;
    Text lastRow = null;
    while (true) {
        if (Tables.getTableState(context.getInstance(), tableId) != expectedState) {
            Tables.clearCache(context.getInstance());
            TableState currentState = Tables.getTableState(context.getInstance(), tableId);
            if (currentState != expectedState) {
                if (!Tables.exists(context.getInstance(), tableId))
                    throw new TableDeletedException(tableId.canonicalID());
                if (currentState == TableState.DELETING)
                    throw new TableNotFoundException(tableId.canonicalID(), "", "Table is being deleted.");
                throw new AccumuloException("Unexpected table state " + tableId + " " + Tables.getTableState(context.getInstance(), tableId) + " != " + expectedState);
            }
        }
        Range range;
        if (startRow == null || lastRow == null)
            range = new KeyExtent(tableId, null, null).toMetadataRange();
        else
            range = new Range(startRow, lastRow);
        String metaTable = MetadataTable.NAME;
        if (tableId.equals(MetadataTable.ID))
            metaTable = RootTable.NAME;
        Scanner scanner = createMetadataScanner(metaTable, range);
        RowIterator rowIter = new RowIterator(scanner);
        KeyExtent lastExtent = null;
        int total = 0;
        int waitFor = 0;
        int holes = 0;
        Text continueRow = null;
        MapCounter<String> serverCounts = new MapCounter<>();
        while (rowIter.hasNext()) {
            Iterator<Entry<Key, Value>> row = rowIter.next();
            total++;
            KeyExtent extent = null;
            String future = null;
            String current = null;
            while (row.hasNext()) {
                Entry<Key, Value> entry = row.next();
                Key key = entry.getKey();
                if (key.getColumnFamily().equals(TabletsSection.FutureLocationColumnFamily.NAME))
                    future = entry.getValue().toString();
                if (key.getColumnFamily().equals(TabletsSection.CurrentLocationColumnFamily.NAME))
                    current = entry.getValue().toString();
                if (TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.hasColumns(key))
                    extent = new KeyExtent(key.getRow(), entry.getValue());
            }
            if ((expectedState == TableState.ONLINE && current == null) || (expectedState == TableState.OFFLINE && (future != null || current != null))) {
                if (continueRow == null)
                    continueRow = extent.getMetadataEntry();
                waitFor++;
                lastRow = extent.getMetadataEntry();
                if (current != null)
                    serverCounts.increment(current, 1);
                if (future != null)
                    serverCounts.increment(future, 1);
            }
            if (!extent.getTableId().equals(tableId)) {
                throw new AccumuloException("Saw unexpected table Id " + tableId + " " + extent);
            }
            if (lastExtent != null && !extent.isPreviousExtent(lastExtent)) {
                holes++;
            }
            lastExtent = extent;
        }
        if (continueRow != null) {
            startRow = continueRow;
        }
        if (holes > 0 || total == 0) {
            startRow = null;
            lastRow = null;
        }
        if (waitFor > 0 || holes > 0 || total == 0) {
            long waitTime;
            long maxPerServer = 0;
            if (serverCounts.size() > 0) {
                maxPerServer = Collections.max(serverCounts.values());
                waitTime = maxPerServer * 10;
            } else
                waitTime = waitFor * 10;
            waitTime = Math.max(100, waitTime);
            waitTime = Math.min(5000, waitTime);
            log.trace("Waiting for {}({}) tablets, startRow = {} lastRow = {}, holes={} sleeping:{}ms", waitFor, maxPerServer, startRow, lastRow, holes, waitTime);
            sleepUninterruptibly(waitTime, TimeUnit.MILLISECONDS);
        } else {
            break;
        }
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) Text(org.apache.hadoop.io.Text) TRowRange(org.apache.accumulo.core.data.thrift.TRowRange) Range(org.apache.accumulo.core.data.Range) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TableDeletedException(org.apache.accumulo.core.client.TableDeletedException) Constraint(org.apache.accumulo.core.constraints.Constraint) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ZipEntry(java.util.zip.ZipEntry) Entry(java.util.Map.Entry) RowIterator(org.apache.accumulo.core.client.RowIterator) MapCounter(org.apache.accumulo.core.util.MapCounter) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) TableState(org.apache.accumulo.core.master.state.tables.TableState)

Example 4 with TableState

use of org.apache.accumulo.core.master.state.tables.TableState in project accumulo by apache.

the class TablesResource method getTables.

/**
 * Generates a list of all the tables
 *
 * @return list with all tables
 */
@GET
public static TableInformationList getTables() {
    TableInformationList tableList = new TableInformationList();
    SortedMap<Table.ID, TableInfo> tableStats = new TreeMap<>();
    if (Monitor.getMmi() != null && Monitor.getMmi().tableMap != null)
        for (Map.Entry<String, TableInfo> te : Monitor.getMmi().tableMap.entrySet()) tableStats.put(Table.ID.of(te.getKey()), te.getValue());
    Map<String, Double> compactingByTable = TableInfoUtil.summarizeTableStats(Monitor.getMmi());
    TableManager tableManager = TableManager.getInstance();
    // Add tables to the list
    for (Map.Entry<String, Table.ID> entry : Tables.getNameToIdMap(HdfsZooInstance.getInstance()).entrySet()) {
        String tableName = entry.getKey();
        Table.ID tableId = entry.getValue();
        TableInfo tableInfo = tableStats.get(tableId);
        TableState tableState = tableManager.getTableState(tableId);
        if (null != tableInfo && !tableState.equals(TableState.OFFLINE)) {
            Double holdTime = compactingByTable.get(tableId.canonicalID());
            if (holdTime == null)
                holdTime = 0.;
            tableList.addTable(new TableInformation(tableName, tableId, tableInfo, holdTime, tableState.name()));
        } else {
            tableList.addTable(new TableInformation(tableName, tableId, tableState.name()));
        }
    }
    return tableList;
}
Also used : MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) RootTable(org.apache.accumulo.core.metadata.RootTable) Table(org.apache.accumulo.core.client.impl.Table) TreeMap(java.util.TreeMap) TableManager(org.apache.accumulo.server.tables.TableManager) TableInfo(org.apache.accumulo.core.master.thrift.TableInfo) ALPHA_NUM_REGEX_TABLE_ID(org.apache.accumulo.monitor.util.ParameterValidator.ALPHA_NUM_REGEX_TABLE_ID) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) TableState(org.apache.accumulo.core.master.state.tables.TableState) GET(javax.ws.rs.GET)

Example 5 with TableState

use of org.apache.accumulo.core.master.state.tables.TableState in project accumulo by apache.

the class TableManager method updateTableStateCache.

public TableState updateTableStateCache(Table.ID tableId) {
    synchronized (tableStateCache) {
        TableState tState = TableState.UNKNOWN;
        byte[] data = zooStateCache.get(ZooUtil.getRoot(instance) + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_STATE);
        if (data != null) {
            String sState = new String(data, UTF_8);
            try {
                tState = TableState.valueOf(sState);
            } catch (IllegalArgumentException e) {
                log.error("Unrecognized state for table with tableId={}: {}", tableId, sState);
            }
            tableStateCache.put(tableId, tState);
        }
        return tState;
    }
}
Also used : TableState(org.apache.accumulo.core.master.state.tables.TableState)

Aggregations

TableState (org.apache.accumulo.core.master.state.tables.TableState)10 Table (org.apache.accumulo.core.client.impl.Table)5 MetadataTable (org.apache.accumulo.core.metadata.MetadataTable)5 RootTable (org.apache.accumulo.core.metadata.RootTable)4 TableManager (org.apache.accumulo.server.tables.TableManager)3 Scanner (org.apache.accumulo.core.client.Scanner)2 Key (org.apache.accumulo.core.data.Key)2 Value (org.apache.accumulo.core.data.Value)2 ReplicationTable (org.apache.accumulo.core.replication.ReplicationTable)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 ZipEntry (java.util.zip.ZipEntry)1 GET (javax.ws.rs.GET)1 ClientOnRequiredTable (org.apache.accumulo.core.cli.ClientOnRequiredTable)1