use of org.apache.accumulo.core.data.TableId in project accumulo by apache.
the class Compactor method cancel.
@Override
public void cancel(TInfo tinfo, TCredentials credentials, String externalCompactionId) throws TException {
TableId tableId = JOB_HOLDER.getTableId();
try {
NamespaceId nsId = getContext().getNamespaceId(tableId);
if (!security.canCompact(credentials, tableId, nsId)) {
throw new AccumuloSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED).asThriftException();
}
} catch (TableNotFoundException e) {
throw new ThriftTableOperationException(tableId.canonical(), null, TableOperation.COMPACT_CANCEL, TableOperationExceptionType.NOTFOUND, e.getMessage());
}
cancel(externalCompactionId);
}
use of org.apache.accumulo.core.data.TableId in project accumulo by apache.
the class GarbageCollectionAlgorithm method cleanUpDeletedTableDirs.
private void cleanUpDeletedTableDirs(GarbageCollectionEnvironment gce, SortedMap<String, String> candidateMap) throws IOException {
HashSet<TableId> tableIdsWithDeletes = new HashSet<>();
// find the table ids that had dirs deleted
for (String delete : candidateMap.keySet()) {
String[] tokens = delete.split("/");
if (tokens.length == 2) {
// its a directory
TableId tableId = TableId.of(delete.split("/")[0]);
tableIdsWithDeletes.add(tableId);
}
}
Set<TableId> tableIdsInZookeeper = gce.getTableIDs();
tableIdsWithDeletes.removeAll(tableIdsInZookeeper);
for (TableId delTableId : tableIdsWithDeletes) {
gce.deleteTableDirIfEmpty(delTableId);
}
}
use of org.apache.accumulo.core.data.TableId in project accumulo by apache.
the class TableOperationsImpl method compact.
@Override
public void compact(String tableName, CompactionConfig config) throws AccumuloSecurityException, TableNotFoundException, AccumuloException {
EXISTING_TABLE_NAME.validate(tableName);
// Ensure compaction iterators exist on a tabletserver
final String skviName = SortedKeyValueIterator.class.getName();
for (IteratorSetting setting : config.getIterators()) {
String iteratorClass = setting.getIteratorClass();
if (!testClassLoad(tableName, iteratorClass, skviName)) {
throw new AccumuloException("TabletServer could not load iterator class " + iteratorClass);
}
}
ensureStrategyCanLoad(tableName, config);
if (!UserCompactionUtils.isDefault(config.getConfigurer())) {
if (!testClassLoad(tableName, config.getConfigurer().getClassName(), CompactionConfigurer.class.getName())) {
throw new AccumuloException("TabletServer could not load " + CompactionConfigurer.class.getSimpleName() + " class " + config.getConfigurer().getClassName());
}
}
if (!UserCompactionUtils.isDefault(config.getSelector())) {
if (!testClassLoad(tableName, config.getSelector().getClassName(), CompactionSelector.class.getName())) {
throw new AccumuloException("TabletServer could not load " + CompactionSelector.class.getSimpleName() + " class " + config.getSelector().getClassName());
}
}
TableId tableId = context.getTableId(tableName);
Text start = config.getStartRow();
Text end = config.getEndRow();
if (config.getFlush())
_flush(tableId, start, end, true);
List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.canonical().getBytes(UTF_8)), ByteBuffer.wrap(UserCompactionUtils.encode(config)));
Map<String, String> opts = new HashMap<>();
try {
doFateOperation(FateOperation.TABLE_COMPACT, args, opts, tableName, config.getWait());
} catch (TableExistsException | NamespaceExistsException e) {
// should not happen
throw new AssertionError(e);
} catch (NamespaceNotFoundException e) {
throw new TableNotFoundException(null, tableName, "Namespace not found", e);
}
}
use of org.apache.accumulo.core.data.TableId in project accumulo by apache.
the class TableOperationsImpl method summaries.
@Override
public SummaryRetriever summaries(String tableName) {
EXISTING_TABLE_NAME.validate(tableName);
return new SummaryRetriever() {
private Text startRow = null;
private Text endRow = null;
private List<TSummarizerConfiguration> summariesToFetch = Collections.emptyList();
private String summarizerClassRegex;
private boolean flush = false;
@Override
public SummaryRetriever startRow(Text startRow) {
Objects.requireNonNull(startRow);
if (endRow != null) {
Preconditions.checkArgument(startRow.compareTo(endRow) < 0, "Start row must be less than end row : %s >= %s", startRow, endRow);
}
this.startRow = startRow;
return this;
}
@Override
public SummaryRetriever startRow(CharSequence startRow) {
return startRow(new Text(startRow.toString()));
}
@Override
public List<Summary> retrieve() throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
TableId tableId = context.getTableId(tableName);
context.requireNotOffline(tableId, tableName);
TRowRange range = new TRowRange(TextUtil.getByteBuffer(startRow), TextUtil.getByteBuffer(endRow));
TSummaryRequest request = new TSummaryRequest(tableId.canonical(), range, summariesToFetch, summarizerClassRegex);
if (flush) {
_flush(tableId, startRow, endRow, true);
}
TSummaries ret = ServerClient.execute(context, new TabletClientService.Client.Factory(), client -> {
TSummaries tsr = client.startGetSummaries(TraceUtil.traceInfo(), context.rpcCreds(), request);
while (!tsr.finished) {
tsr = client.contiuneGetSummaries(TraceUtil.traceInfo(), tsr.sessionId);
}
return tsr;
});
return new SummaryCollection(ret).getSummaries();
}
@Override
public SummaryRetriever endRow(Text endRow) {
Objects.requireNonNull(endRow);
if (startRow != null) {
Preconditions.checkArgument(startRow.compareTo(endRow) < 0, "Start row must be less than end row : %s >= %s", startRow, endRow);
}
this.endRow = endRow;
return this;
}
@Override
public SummaryRetriever endRow(CharSequence endRow) {
return endRow(new Text(endRow.toString()));
}
@Override
public SummaryRetriever withConfiguration(Collection<SummarizerConfiguration> configs) {
Objects.requireNonNull(configs);
summariesToFetch = configs.stream().map(SummarizerConfigurationUtil::toThrift).collect(Collectors.toList());
return this;
}
@Override
public SummaryRetriever withConfiguration(SummarizerConfiguration... config) {
Objects.requireNonNull(config);
return withConfiguration(Arrays.asList(config));
}
@Override
public SummaryRetriever withMatchingConfiguration(String regex) {
Objects.requireNonNull(regex);
// Do a sanity check here to make sure that regex compiles, instead of having it fail on a
// tserver.
Pattern.compile(regex);
this.summarizerClassRegex = regex;
return this;
}
@Override
public SummaryRetriever flush(boolean b) {
this.flush = b;
return this;
}
};
}
use of org.apache.accumulo.core.data.TableId in project accumulo by apache.
the class TableOperationsImpl method addSplits.
@Override
public void addSplits(String tableName, SortedSet<Text> partitionKeys) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
EXISTING_TABLE_NAME.validate(tableName);
TableId tableId = context.getTableId(tableName);
List<Text> splits = new ArrayList<>(partitionKeys);
// should be sorted because we copied from a sorted set, but that makes
// assumptions about how the copy was done so resort to be sure.
Collections.sort(splits);
CountDownLatch latch = new CountDownLatch(splits.size());
AtomicReference<Exception> exception = new AtomicReference<>(null);
ExecutorService executor = ThreadPools.createFixedThreadPool(16, "addSplits", false);
try {
executor.execute(new SplitTask(new SplitEnv(tableName, tableId, executor, latch, exception), splits));
while (!latch.await(100, MILLISECONDS)) {
if (exception.get() != null) {
executor.shutdownNow();
Throwable excep = exception.get();
// user would only have the stack trace for the background thread.
if (excep instanceof TableNotFoundException) {
TableNotFoundException tnfe = (TableNotFoundException) excep;
throw new TableNotFoundException(tableId.canonical(), tableName, "Table not found by background thread", tnfe);
} else if (excep instanceof TableOfflineException) {
log.debug("TableOfflineException occurred in background thread. Throwing new exception", excep);
throw new TableOfflineException(tableId, tableName);
} else if (excep instanceof AccumuloSecurityException) {
// base == background accumulo security exception
AccumuloSecurityException base = (AccumuloSecurityException) excep;
throw new AccumuloSecurityException(base.getUser(), base.asThriftException().getCode(), base.getTableInfo(), excep);
} else if (excep instanceof AccumuloServerException) {
throw new AccumuloServerException((AccumuloServerException) excep);
} else if (excep instanceof Error) {
throw new Error(excep);
} else {
throw new AccumuloException(excep);
}
}
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
executor.shutdown();
}
}
Aggregations