use of org.apache.accumulo.core.master.state.tables.TableState in project accumulo by apache.
the class Master method displayUnassigned.
// The number of unassigned tablets that should be assigned: displayed on the monitor page
int displayUnassigned() {
int result = 0;
switch(getMasterState()) {
case NORMAL:
// Count offline tablets for online tables
for (TabletGroupWatcher watcher : watchers) {
TableManager manager = TableManager.getInstance();
for (Entry<Table.ID, TableCounts> entry : watcher.getStats().entrySet()) {
Table.ID tableId = entry.getKey();
TableCounts counts = entry.getValue();
TableState tableState = manager.getTableState(tableId);
if (tableState != null && tableState.equals(TableState.ONLINE)) {
result += counts.unassigned() + counts.assignedToDeadServers() + counts.assigned() + counts.suspended();
}
}
}
break;
case SAFE_MODE:
// Count offline tablets for the metadata table
for (TabletGroupWatcher watcher : watchers) {
TableCounts counts = watcher.getStats(MetadataTable.ID);
result += counts.unassigned() + counts.suspended();
}
break;
case UNLOAD_METADATA_TABLETS:
case UNLOAD_ROOT_TABLET:
for (TabletGroupWatcher watcher : watchers) {
TableCounts counts = watcher.getStats(MetadataTable.ID);
result += counts.unassigned() + counts.suspended();
}
break;
default:
break;
}
return result;
}
use of org.apache.accumulo.core.master.state.tables.TableState in project accumulo by apache.
the class ChangeTableState method call.
@Override
public Repo<Master> call(long tid, Master env) throws Exception {
TableState ts = TableState.ONLINE;
if (top == TableOperation.OFFLINE)
ts = TableState.OFFLINE;
TableManager.getInstance().transitionTableState(tableId, ts);
Utils.unreserveNamespace(namespaceId, tid, false);
Utils.unreserveTable(tableId, tid, true);
LoggerFactory.getLogger(ChangeTableState.class).debug("Changed table state {} {}", tableId, ts);
env.getEventCoordinator().event("Set table state of %s to %s", tableId, ts);
return null;
}
use of org.apache.accumulo.core.master.state.tables.TableState in project accumulo by apache.
the class RandomizeVolumes method randomize.
public static int randomize(Connector c, String tableName) throws IOException, AccumuloSecurityException, AccumuloException, TableNotFoundException {
final VolumeManager vm = VolumeManagerImpl.get();
if (vm.getVolumes().size() < 2) {
log.error("There are not enough volumes configured");
return 1;
}
String tblStr = c.tableOperations().tableIdMap().get(tableName);
if (null == tblStr) {
log.error("Could not determine the table ID for table {}", tableName);
return 2;
}
Table.ID tableId = Table.ID.of(tblStr);
TableState tableState = TableManager.getInstance().getTableState(tableId);
if (TableState.OFFLINE != tableState) {
log.info("Taking {} offline", tableName);
c.tableOperations().offline(tableName, true);
log.info("{} offline", tableName);
}
SimpleThreadPool pool = new SimpleThreadPool(50, "directory maker");
log.info("Rewriting entries for {}", tableName);
Scanner scanner = c.createScanner(MetadataTable.NAME, Authorizations.EMPTY);
DIRECTORY_COLUMN.fetch(scanner);
scanner.setRange(TabletsSection.getRange(tableId));
BatchWriter writer = c.createBatchWriter(MetadataTable.NAME, null);
int count = 0;
for (Entry<Key, Value> entry : scanner) {
String oldLocation = entry.getValue().toString();
String directory;
if (oldLocation.contains(":")) {
String[] parts = oldLocation.split(Path.SEPARATOR);
Table.ID tableIdEntry = Table.ID.of(parts[parts.length - 2]);
if (!tableIdEntry.equals(tableId)) {
log.error("Unexpected table id found: {}, expected {}; skipping", tableIdEntry, tableId);
continue;
}
directory = parts[parts.length - 1];
} else {
directory = oldLocation.substring(Path.SEPARATOR.length());
}
Key key = entry.getKey();
Mutation m = new Mutation(key.getRow());
VolumeChooserEnvironment chooserEnv = new VolumeChooserEnvironment(tableId);
final String newLocation = vm.choose(chooserEnv, ServerConstants.getBaseUris()) + Path.SEPARATOR + ServerConstants.TABLE_DIR + Path.SEPARATOR + tableId + Path.SEPARATOR + directory;
m.put(key.getColumnFamily(), key.getColumnQualifier(), new Value(newLocation.getBytes(UTF_8)));
if (log.isTraceEnabled()) {
log.trace("Replacing {} with {}", oldLocation, newLocation);
}
writer.addMutation(m);
pool.submit(new Runnable() {
@Override
public void run() {
try {
vm.mkdirs(new Path(newLocation));
} catch (IOException ex) {
// nevermind
}
}
});
count++;
}
writer.close();
pool.shutdown();
while (!pool.isTerminated()) {
log.trace("Waiting for mkdir() calls to finish");
try {
pool.awaitTermination(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
log.info("Updated {} entries for table {}", count, tableName);
if (TableState.OFFLINE != tableState) {
c.tableOperations().online(tableName, true);
log.info("table {} back online", tableName);
}
return 0;
}
use of org.apache.accumulo.core.master.state.tables.TableState in project accumulo by apache.
the class TableChangeStateIT 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 {
Table.ID tableId = Tables.getTableId(connector.getInstance(), tableName);
TableState tstate = Tables.getTableState(connector.getInstance(), tableId);
log.trace("tableName: '{}': tableId {}, current state: {}", tableName, tableId, tstate);
return tstate;
}
use of org.apache.accumulo.core.master.state.tables.TableState in project accumulo by apache.
the class TableOperationsImpl method online.
@Override
public void online(String tableName, boolean wait) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
checkArgument(tableName != null, "tableName is null");
Table.ID tableId = Tables.getTableId(context.getInstance(), tableName);
/**
* ACCUMULO-4574 if table is already online return without executing fate operation.
*/
TableState expectedState = Tables.getTableState(context.getInstance(), tableId, true);
if (expectedState == TableState.ONLINE) {
if (wait)
waitForTableStateTransition(tableId, TableState.ONLINE);
return;
}
List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getUtf8()));
Map<String, String> opts = new HashMap<>();
try {
doTableFateOperation(tableName, TableNotFoundException.class, FateOperation.TABLE_ONLINE, args, opts);
} catch (TableExistsException e) {
// should not happen
throw new AssertionError(e);
}
if (wait)
waitForTableStateTransition(tableId, TableState.ONLINE);
}
Aggregations