Search in sources :

Example 6 with TableState

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

the class TableManager method updateTableStateCache.

public TableState updateTableStateCache(TableId tableId) {
    synchronized (tableStateCache) {
        TableState tState = TableState.UNKNOWN;
        byte[] data = zooStateCache.get(zkRoot + 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.manager.state.tables.TableState)

Example 7 with TableState

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

the class TableOperationsImpl method waitForTableStateTransition.

private void waitForTableStateTransition(TableId tableId, TableState expectedState) throws AccumuloException, TableNotFoundException {
    Text startRow = null;
    Text lastRow = null;
    while (true) {
        if (context.getTableState(tableId) != expectedState) {
            context.clearTableListCache();
            TableState currentState = context.getTableState(tableId);
            if (currentState != expectedState) {
                context.requireNotDeleted(tableId);
                if (currentState == TableState.DELETING)
                    throw new TableNotFoundException(tableId.canonical(), "", TABLE_DELETED_MSG);
                throw new AccumuloException("Unexpected table state " + tableId + " " + currentState + " != " + expectedState);
            }
        }
        Range range;
        if (startRow == null || lastRow == null)
            range = new KeyExtent(tableId, null, null).toMetaRange();
        else
            range = new Range(startRow, lastRow);
        TabletsMetadata tablets = TabletsMetadata.builder(context).scanMetadataTable().overRange(range).fetch(LOCATION, PREV_ROW).build();
        KeyExtent lastExtent = null;
        int total = 0;
        int waitFor = 0;
        int holes = 0;
        Text continueRow = null;
        MapCounter<String> serverCounts = new MapCounter<>();
        for (TabletMetadata tablet : tablets) {
            total++;
            Location loc = tablet.getLocation();
            if ((expectedState == TableState.ONLINE && (loc == null || loc.getType() == LocationType.FUTURE)) || (expectedState == TableState.OFFLINE && loc != null)) {
                if (continueRow == null)
                    continueRow = tablet.getExtent().toMetaRow();
                waitFor++;
                lastRow = tablet.getExtent().toMetaRow();
                if (loc != null) {
                    serverCounts.increment(loc.getHostPortSession(), 1);
                }
            }
            if (!tablet.getExtent().tableId().equals(tableId)) {
                throw new AccumuloException("Saw unexpected table Id " + tableId + " " + tablet.getExtent());
            }
            if (lastExtent != null && !tablet.getExtent().isPreviousExtent(lastExtent)) {
                holes++;
            }
            lastExtent = tablet.getExtent();
        }
        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 = serverCounts.max();
                waitTime = maxPerServer * 10;
            } else
                waitTime = waitFor * 10L;
            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, MILLISECONDS);
        } else {
            break;
        }
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) TRowRange(org.apache.accumulo.core.dataImpl.thrift.TRowRange) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) Constraint(org.apache.accumulo.core.data.constraints.Constraint) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TabletsMetadata(org.apache.accumulo.core.metadata.schema.TabletsMetadata) MapCounter(org.apache.accumulo.core.util.MapCounter) TabletMetadata(org.apache.accumulo.core.metadata.schema.TabletMetadata) TableState(org.apache.accumulo.core.manager.state.tables.TableState) Location(org.apache.accumulo.core.metadata.schema.TabletMetadata.Location) TabletLocation(org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation)

Example 8 with TableState

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

the class Manager method onlineTables.

@Override
public Set<TableId> onlineTables() {
    Set<TableId> result = new HashSet<>();
    if (getManagerState() != ManagerState.NORMAL) {
        if (getManagerState() != ManagerState.UNLOAD_METADATA_TABLETS) {
            result.add(MetadataTable.ID);
        }
        if (getManagerState() != ManagerState.UNLOAD_ROOT_TABLET) {
            result.add(RootTable.ID);
        }
        return result;
    }
    ServerContext context = getContext();
    TableManager manager = context.getTableManager();
    for (TableId tableId : context.getTableIdToNameMap().keySet()) {
        TableState state = manager.getTableState(tableId);
        if ((state != null) && (state == TableState.ONLINE)) {
            result.add(tableId);
        }
    }
    return result;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) ServerContext(org.apache.accumulo.server.ServerContext) TableManager(org.apache.accumulo.server.tables.TableManager) HashSet(java.util.HashSet) TableState(org.apache.accumulo.core.manager.state.tables.TableState)

Example 9 with TableState

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

the class TablesResource method getTables.

public static TableInformationList getTables(Monitor monitor) {
    TableInformationList tableList = new TableInformationList();
    ManagerMonitorInfo mmi = monitor.getMmi();
    if (mmi == null) {
        return tableList;
    }
    SortedMap<TableId, TableInfo> tableStats = new TreeMap<>();
    if (mmi.tableMap != null) {
        for (Map.Entry<String, TableInfo> te : mmi.tableMap.entrySet()) {
            tableStats.put(TableId.of(te.getKey()), te.getValue());
        }
    }
    Map<String, Double> compactingByTable = TableInfoUtil.summarizeTableStats(mmi);
    TableManager tableManager = monitor.getContext().getTableManager();
    // Add tables to the list
    for (Map.Entry<String, TableId> entry : monitor.getContext().getTableNameToIdMap().entrySet()) {
        String tableName = entry.getKey();
        TableId tableId = entry.getValue();
        TableInfo tableInfo = tableStats.get(tableId);
        TableState tableState = tableManager.getTableState(tableId);
        if (tableInfo != null && tableState != TableState.OFFLINE) {
            Double holdTime = compactingByTable.get(tableId.canonical());
            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 : TableId(org.apache.accumulo.core.data.TableId) TreeMap(java.util.TreeMap) ManagerMonitorInfo(org.apache.accumulo.core.manager.thrift.ManagerMonitorInfo) TableManager(org.apache.accumulo.server.tables.TableManager) TableInfo(org.apache.accumulo.core.master.thrift.TableInfo) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) TableState(org.apache.accumulo.core.manager.state.tables.TableState)

Example 10 with TableState

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

the class FateConcurrencyIT method getTableState.

/**
 * Returns the current table state (ONLINE, OFFLINE,...) of named table.
 *
 * @param tableName
 *          the table name
 * @return the current table state
 * @throws TableNotFoundException
 *           if table does not exist
 */
private TableState getTableState(String tableName) throws TableNotFoundException {
    TableId tableId = context.getTableId(tableName);
    TableState tstate = context.getTableState(tableId);
    log.trace("tableName: '{}': tableId {}, current state: {}", tableName, tableId, tstate);
    return tstate;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TableState(org.apache.accumulo.core.manager.state.tables.TableState)

Aggregations

TableState (org.apache.accumulo.core.manager.state.tables.TableState)10 TableId (org.apache.accumulo.core.data.TableId)4 TableManager (org.apache.accumulo.server.tables.TableManager)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 ClientContext (org.apache.accumulo.core.clientImpl.ClientContext)1 TabletLocation (org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation)1 Range (org.apache.accumulo.core.data.Range)1 Constraint (org.apache.accumulo.core.data.constraints.Constraint)1 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)1 TRowRange (org.apache.accumulo.core.dataImpl.thrift.TRowRange)1 ManagerMonitorInfo (org.apache.accumulo.core.manager.thrift.ManagerMonitorInfo)1 TableInfo (org.apache.accumulo.core.master.thrift.TableInfo)1 TServerInstance (org.apache.accumulo.core.metadata.TServerInstance)1 TabletMetadata (org.apache.accumulo.core.metadata.schema.TabletMetadata)1