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;
}
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);
}
}
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;
}
}
}
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;
}
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;
}
}
Aggregations