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