use of org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException in project accumulo by apache.
the class TableOperationsImpl method getDiskUsage.
@Override
public List<DiskUsage> getDiskUsage(Set<String> tableNames) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
List<TDiskUsage> diskUsages = null;
while (diskUsages == null) {
Pair<String, Client> pair = null;
try {
// this operation may us a lot of memory... its likely that connections to tabletservers
// hosting metadata tablets will be cached, so do not use cached
// connections
pair = ServerClient.getConnection(context, new ClientService.Client.Factory(), false);
diskUsages = pair.getSecond().getDiskUsage(tableNames, context.rpcCreds());
} catch (ThriftTableOperationException e) {
switch(e.getType()) {
case NOTFOUND:
throw new TableNotFoundException(e);
case NAMESPACE_NOTFOUND:
throw new TableNotFoundException(e.getTableName(), new NamespaceNotFoundException(e));
default:
throw new AccumuloException(e.description, e);
}
} catch (ThriftSecurityException e) {
throw new AccumuloSecurityException(e.getUser(), e.getCode());
} catch (TTransportException e) {
// some sort of communication error occurred, retry
if (pair == null) {
log.debug("Disk usage request failed. Pair is null. Retrying request...", e);
} else {
log.debug("Disk usage request failed {}, retrying ... ", pair.getFirst(), e);
}
sleepUninterruptibly(100, MILLISECONDS);
} catch (TException e) {
// may be a TApplicationException which indicates error on the server side
throw new AccumuloException(e);
} finally {
// must always return thrift connection
if (pair != null)
ServerClient.close(pair.getSecond(), context);
}
}
List<DiskUsage> finalUsages = new ArrayList<>();
for (TDiskUsage diskUsage : diskUsages) {
finalUsages.add(new DiskUsage(new TreeSet<>(diskUsage.getTables()), diskUsage.getUsage()));
}
return finalUsages;
}
use of org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException in project accumulo by apache.
the class TableOperationsImpl method _flush.
private void _flush(TableId tableId, Text start, Text end, boolean wait) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
try {
long flushID;
while (true) {
ManagerClientService.Iface client = null;
try {
client = ManagerClient.getConnectionWithRetry(context);
flushID = client.initiateFlush(TraceUtil.traceInfo(), context.rpcCreds(), tableId.canonical());
break;
} catch (TTransportException tte) {
log.debug("Failed to call initiateFlush, retrying ... ", tte);
sleepUninterruptibly(100, MILLISECONDS);
} catch (ThriftNotActiveServiceException e) {
// Let it loop, fetching a new location
log.debug("Contacted a Manager which is no longer active, retrying");
sleepUninterruptibly(100, MILLISECONDS);
} finally {
ManagerClient.close(client, context);
}
}
while (true) {
ManagerClientService.Iface client = null;
try {
client = ManagerClient.getConnectionWithRetry(context);
client.waitForFlush(TraceUtil.traceInfo(), context.rpcCreds(), tableId.canonical(), TextUtil.getByteBuffer(start), TextUtil.getByteBuffer(end), flushID, wait ? Long.MAX_VALUE : 1);
break;
} catch (TTransportException tte) {
log.debug("Failed to call initiateFlush, retrying ... ", tte);
sleepUninterruptibly(100, MILLISECONDS);
} catch (ThriftNotActiveServiceException e) {
// Let it loop, fetching a new location
log.debug("Contacted a Manager which is no longer active, retrying");
sleepUninterruptibly(100, MILLISECONDS);
} finally {
ManagerClient.close(client, context);
}
}
} catch (ThriftSecurityException e) {
switch(e.getCode()) {
case TABLE_DOESNT_EXIST:
throw new TableNotFoundException(tableId.canonical(), null, e.getMessage(), e);
default:
log.debug("flush security exception on table id {}", tableId);
throw new AccumuloSecurityException(e.user, e.code, e);
}
} catch (ThriftTableOperationException e) {
switch(e.getType()) {
case NOTFOUND:
throw new TableNotFoundException(e);
default:
throw new AccumuloException(e.description, e);
}
} catch (Exception e) {
throw new AccumuloException(e);
}
}
use of org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException in project accumulo by apache.
the class TableOperationsImpl method addSplits.
private void addSplits(SplitEnv env, SortedSet<Text> partitionKeys) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, AccumuloServerException {
TabletLocator tabLocator = TabletLocator.getLocator(context, env.tableId);
for (Text split : partitionKeys) {
boolean successful = false;
int attempt = 0;
long locationFailures = 0;
while (!successful) {
if (attempt > 0)
sleepUninterruptibly(100, MILLISECONDS);
attempt++;
TabletLocation tl = tabLocator.locateTablet(context, split, false, false);
if (tl == null) {
context.requireTableExists(env.tableId, env.tableName);
context.requireNotOffline(env.tableId, env.tableName);
continue;
}
HostAndPort address = HostAndPort.fromString(tl.tablet_location);
try {
TabletClientService.Client client = ThriftUtil.getTServerClient(address, context);
try {
OpTimer timer = null;
if (log.isTraceEnabled()) {
log.trace("tid={} Splitting tablet {} on {} at {}", Thread.currentThread().getId(), tl.tablet_extent, address, split);
timer = new OpTimer().start();
}
client.splitTablet(TraceUtil.traceInfo(), context.rpcCreds(), tl.tablet_extent.toThrift(), TextUtil.getByteBuffer(split));
// just split it, might as well invalidate it in the cache
tabLocator.invalidateCache(tl.tablet_extent);
if (timer != null) {
timer.stop();
log.trace("Split tablet in {}", String.format("%.3f secs", timer.scale(SECONDS)));
}
} finally {
ThriftUtil.returnClient(client, context);
}
} catch (TApplicationException tae) {
throw new AccumuloServerException(address.toString(), tae);
} catch (TTransportException e) {
tabLocator.invalidateCache(context, tl.tablet_location);
continue;
} catch (ThriftSecurityException e) {
context.clearTableListCache();
context.requireTableExists(env.tableId, env.tableName);
throw new AccumuloSecurityException(e.user, e.code, e);
} catch (NotServingTabletException e) {
// Do not silently spin when we repeatedly fail to get the location for a tablet
locationFailures++;
if (locationFailures == 5 || locationFailures % 50 == 0) {
log.warn("Having difficulty locating hosting tabletserver for split {} on table {}." + " Seen {} failures.", split, env.tableName, locationFailures);
}
tabLocator.invalidateCache(tl.tablet_extent);
continue;
} catch (TException e) {
tabLocator.invalidateCache(context, tl.tablet_location);
continue;
}
successful = true;
}
}
}
use of org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException in project accumulo by apache.
the class InstanceOperationsImpl method getActiveCompactions.
@Override
public List<ActiveCompaction> getActiveCompactions(String tserver) throws AccumuloException, AccumuloSecurityException {
final var parsedTserver = HostAndPort.fromString(tserver);
Client client = null;
try {
client = getTServerClient(parsedTserver, context);
List<ActiveCompaction> as = new ArrayList<>();
for (var tac : client.getActiveCompactions(TraceUtil.traceInfo(), context.rpcCreds())) {
as.add(new ActiveCompactionImpl(context, tac, parsedTserver, CompactionHost.Type.TSERVER));
}
return as;
} catch (ThriftSecurityException e) {
throw new AccumuloSecurityException(e.user, e.code, e);
} catch (TException e) {
throw new AccumuloException(e);
} finally {
if (client != null)
returnClient(client, context);
}
}
use of org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException in project accumulo by apache.
the class InstanceOperationsImpl method getActiveCompactions.
@Override
public List<ActiveCompaction> getActiveCompactions() throws AccumuloException, AccumuloSecurityException {
Map<String, List<HostAndPort>> compactors = ExternalCompactionUtil.getCompactorAddrs(context);
List<String> tservers = getTabletServers();
int numThreads = Math.max(4, Math.min((tservers.size() + compactors.size()) / 10, 256));
var executorService = ThreadPools.createFixedThreadPool(numThreads, "getactivecompactions", false);
try {
List<Future<List<ActiveCompaction>>> futures = new ArrayList<>();
for (String tserver : tservers) {
futures.add(executorService.submit(() -> getActiveCompactions(tserver)));
}
compactors.values().forEach(compactorList -> {
for (HostAndPort compactorAddr : compactorList) {
Callable<List<ActiveCompaction>> task = () -> ExternalCompactionUtil.getActiveCompaction(compactorAddr, context).stream().map(tac -> new ActiveCompactionImpl(context, tac, compactorAddr, CompactionHost.Type.COMPACTOR)).collect(toList());
futures.add(executorService.submit(task));
}
});
List<ActiveCompaction> ret = new ArrayList<>();
for (Future<List<ActiveCompaction>> future : futures) {
try {
ret.addAll(future.get());
} catch (InterruptedException | ExecutionException e) {
if (e.getCause() instanceof ThriftSecurityException) {
ThriftSecurityException tse = (ThriftSecurityException) e.getCause();
throw new AccumuloSecurityException(tse.user, tse.code, e);
}
throw new AccumuloException(e);
}
}
return ret;
} finally {
executorService.shutdown();
}
}
Aggregations