use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.
the class ManagerClientServiceHandler method alterTableProperty.
private void alterTableProperty(TCredentials c, String tableName, String property, String value, TableOperation op) throws ThriftSecurityException, ThriftTableOperationException {
final TableId tableId = ClientServiceHandler.checkTableId(manager.getContext(), tableName, op);
NamespaceId namespaceId = getNamespaceIdFromTableId(op, tableId);
if (!manager.security.canAlterTable(c, tableId, namespaceId))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
try {
if (value == null || value.isEmpty()) {
TablePropUtil.removeTableProperty(manager.getContext(), tableId, property);
} else if (!TablePropUtil.setTableProperty(manager.getContext(), tableId, property, value)) {
throw new Exception("Invalid table property.");
}
} catch (KeeperException.NoNodeException e) {
// race condition... table no longer exists? This call will throw an exception if the table
// was deleted:
ClientServiceHandler.checkTableId(manager.getContext(), tableName, op);
log.info("Error altering table property", e);
throw new ThriftTableOperationException(tableId.canonical(), tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property");
} catch (Exception e) {
log.error("Problem altering table property", e);
throw new ThriftTableOperationException(tableId.canonical(), tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property");
}
}
use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.
the class ManagerClientServiceHandler method waitForFlush.
@Override
public void waitForFlush(TInfo tinfo, TCredentials c, String tableIdStr, ByteBuffer startRowBB, ByteBuffer endRowBB, long flushID, long maxLoops) throws ThriftSecurityException, ThriftTableOperationException {
TableId tableId = TableId.of(tableIdStr);
NamespaceId namespaceId = getNamespaceIdFromTableId(TableOperation.FLUSH, tableId);
if (!manager.security.canFlush(c, tableId, namespaceId))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
Text startRow = ByteBufferUtil.toText(startRowBB);
Text endRow = ByteBufferUtil.toText(endRowBB);
if (endRow != null && startRow != null && startRow.compareTo(endRow) >= 0)
throw new ThriftTableOperationException(tableId.canonical(), null, TableOperation.FLUSH, TableOperationExceptionType.BAD_RANGE, "start row must be less than end row");
Set<TServerInstance> serversToFlush = new HashSet<>(manager.tserverSet.getCurrentServers());
for (long l = 0; l < maxLoops; l++) {
for (TServerInstance instance : serversToFlush) {
try {
final TServerConnection server = manager.tserverSet.getConnection(instance);
if (server != null)
server.flush(manager.managerLock, tableId, ByteBufferUtil.toBytes(startRowBB), ByteBufferUtil.toBytes(endRowBB));
} catch (TException ex) {
Manager.log.error(ex.toString());
}
}
if (tableId.equals(RootTable.ID))
// this code does not properly handle the root tablet. See #798
break;
if (l == maxLoops - 1)
break;
sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
serversToFlush.clear();
try (TabletsMetadata tablets = TabletsMetadata.builder(manager.getContext()).forTable(tableId).overlapping(startRow, endRow).fetch(FLUSH_ID, LOCATION, LOGS, PREV_ROW).build()) {
int tabletsToWaitFor = 0;
int tabletCount = 0;
for (TabletMetadata tablet : tablets) {
int logs = tablet.getLogs().size();
// when tablet is not online and has no logs, there is no reason to wait for it
if ((tablet.hasCurrent() || logs > 0) && tablet.getFlushId().orElse(-1) < flushID) {
tabletsToWaitFor++;
if (tablet.hasCurrent())
serversToFlush.add(tablet.getLocation());
}
tabletCount++;
}
if (tabletsToWaitFor == 0)
break;
if (tabletCount == 0 && !manager.getContext().tableNodeExists(tableId))
throw new ThriftTableOperationException(tableId.canonical(), null, TableOperation.FLUSH, TableOperationExceptionType.NOTFOUND, null);
} catch (TabletDeletedException e) {
Manager.log.debug("Failed to scan {} table to wait for flush {}", MetadataTable.NAME, tableId, e);
}
}
}
use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.
the class ThriftClientHandler method startGetSummaries.
@Override
public TSummaries startGetSummaries(TInfo tinfo, TCredentials credentials, TSummaryRequest request) throws ThriftSecurityException, ThriftTableOperationException, TException {
NamespaceId namespaceId;
TableId tableId = TableId.of(request.getTableId());
try {
namespaceId = server.getContext().getNamespaceId(tableId);
} catch (TableNotFoundException e1) {
throw new ThriftTableOperationException(tableId.canonical(), null, null, TableOperationExceptionType.NOTFOUND, null);
}
if (!security.canGetSummaries(credentials, tableId, namespaceId)) {
throw new AccumuloSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED).asThriftException();
}
ExecutorService es = server.resourceManager.getSummaryPartitionExecutor();
Future<SummaryCollection> future = new Gatherer(server.getContext(), request, context.getTableConfiguration(tableId), context.getCryptoService()).gather(es);
return startSummaryOperation(credentials, future);
}
use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.
the class ListTabletsCommand method populateTables.
/**
* Process the command line for table names using table option, table name pattern, or default to
* current table.
*
* @param cl
* command line
* @param shellState
* shell state
* @return set of table names.
* @throws NamespaceNotFoundException
* if the namespace option is specified and namespace does not exist
*/
private Set<TableInfo> populateTables(final CommandLine cl, final Shell shellState) throws NamespaceNotFoundException {
final TableOperations tableOps = shellState.getAccumuloClient().tableOperations();
var tableIdMap = tableOps.tableIdMap();
Set<TableInfo> tableSet = new TreeSet<>();
if (cl.hasOption(optTablePattern.getOpt())) {
Pattern tablePattern = Pattern.compile(cl.getOptionValue(optTablePattern.getOpt()));
for (String table : tableOps.list()) {
if (tablePattern.matcher(table).matches()) {
TableId id = TableId.of(tableIdMap.get(table));
tableSet.add(new TableInfo(table, id));
}
}
return tableSet;
}
if (cl.hasOption(optNamespace.getOpt())) {
String nsName = cl.getOptionValue(optNamespace.getOpt());
NamespaceId namespaceId = Namespaces.getNamespaceId(shellState.getContext(), nsName);
List<String> tables = Namespaces.getTableNames(shellState.getContext(), namespaceId);
tables.forEach(name -> {
String tableIdString = tableIdMap.get(name);
if (tableIdString != null) {
TableId id = TableId.of(tableIdString);
tableSet.add(new TableInfo(name, id));
} else {
log.warn("Table not found: {}", name);
}
});
return tableSet;
}
if (cl.hasOption(ShellOptions.tableOption)) {
String table = cl.getOptionValue(ShellOptions.tableOption);
String idString = tableIdMap.get(table);
if (idString != null) {
TableId id = TableId.of(idString);
tableSet.add(new TableInfo(table, id));
} else {
log.warn("Table not found: {}", table);
}
return tableSet;
}
// If we didn't get any tables, and we have a table selected, add the current table
String table = shellState.getTableName();
if (!table.isEmpty()) {
TableId id = TableId.of(tableIdMap.get(table));
tableSet.add(new TableInfo(table, id));
return tableSet;
}
return Collections.emptySet();
}
use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.
the class ThriftClientHandler method startScan.
@Override
public InitialScan startScan(TInfo tinfo, TCredentials credentials, TKeyExtent textent, TRange range, List<TColumn> columns, int batchSize, List<IterInfo> ssiList, Map<String, Map<String, String>> ssio, List<ByteBuffer> authorizations, boolean waitForWrites, boolean isolated, long readaheadThreshold, TSamplerConfiguration tSamplerConfig, long batchTimeOut, String contextArg, Map<String, String> executionHints) throws NotServingTabletException, ThriftSecurityException, org.apache.accumulo.core.tabletserver.thrift.TooManyFilesException, TSampleNotPresentException {
TableId tableId = TableId.of(new String(textent.getTable(), UTF_8));
NamespaceId namespaceId;
try {
namespaceId = server.getContext().getNamespaceId(tableId);
} catch (TableNotFoundException e1) {
throw new NotServingTabletException(textent);
}
if (!security.canScan(credentials, tableId, namespaceId, range, columns, ssiList, ssio, authorizations)) {
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
}
if (!security.authenticatedUserHasAuthorizations(credentials, authorizations)) {
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.BAD_AUTHORIZATIONS);
}
final KeyExtent extent = KeyExtent.fromThrift(textent);
// metadata
if (waitForWrites) {
writeTracker.waitForWrites(TabletType.type(extent));
}
Tablet tablet = server.getOnlineTablet(extent);
if (tablet == null) {
throw new NotServingTabletException(textent);
}
HashSet<Column> columnSet = new HashSet<>();
for (TColumn tcolumn : columns) {
columnSet.add(new Column(tcolumn));
}
ScanParameters scanParams = new ScanParameters(batchSize, new Authorizations(authorizations), columnSet, ssiList, ssio, isolated, SamplerConfigurationImpl.fromThrift(tSamplerConfig), batchTimeOut, contextArg);
final SingleScanSession scanSession = new SingleScanSession(credentials, extent, scanParams, readaheadThreshold, executionHints);
scanSession.scanner = tablet.createScanner(new Range(range), scanParams, scanSession.interruptFlag);
long sid = server.sessionManager.createSession(scanSession, true);
ScanResult scanResult;
try {
scanResult = continueScan(tinfo, sid, scanSession);
} catch (NoSuchScanIDException e) {
log.error("The impossible happened", e);
throw new RuntimeException();
} finally {
server.sessionManager.unreserveSession(sid);
}
return new InitialScan(sid, scanResult);
}
Aggregations