Search in sources :

Example 41 with ThriftSecurityException

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;
}
Also used : TException(org.apache.thrift.TException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ClientService(org.apache.accumulo.core.clientImpl.thrift.ClientService) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) ManagerClientService(org.apache.accumulo.core.manager.thrift.ManagerClientService) ArrayList(java.util.ArrayList) LoggerFactory(org.slf4j.LoggerFactory) TTransportException(org.apache.thrift.transport.TTransportException) TDiskUsage(org.apache.accumulo.core.clientImpl.thrift.TDiskUsage) DiskUsage(org.apache.accumulo.core.client.admin.DiskUsage) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TreeSet(java.util.TreeSet) TDiskUsage(org.apache.accumulo.core.clientImpl.thrift.TDiskUsage) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Client(org.apache.accumulo.core.clientImpl.thrift.ClientService.Client)

Example 42 with ThriftSecurityException

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);
    }
}
Also used : ManagerClientService(org.apache.accumulo.core.manager.thrift.ManagerClientService) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ThriftNotActiveServiceException(org.apache.accumulo.core.clientImpl.thrift.ThriftNotActiveServiceException) TTransportException(org.apache.thrift.transport.TTransportException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TException(org.apache.thrift.TException) IOException(java.io.IOException) TTransportException(org.apache.thrift.transport.TTransportException) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) FileNotFoundException(java.io.FileNotFoundException) ThriftNotActiveServiceException(org.apache.accumulo.core.clientImpl.thrift.ThriftNotActiveServiceException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TApplicationException(org.apache.thrift.TApplicationException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException)

Example 43 with ThriftSecurityException

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;
        }
    }
}
Also used : TException(org.apache.thrift.TException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) TTransportException(org.apache.thrift.transport.TTransportException) Text(org.apache.hadoop.io.Text) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) Constraint(org.apache.accumulo.core.data.constraints.Constraint) TApplicationException(org.apache.thrift.TApplicationException) HostAndPort(org.apache.accumulo.core.util.HostAndPort) TabletLocation(org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation) OpTimer(org.apache.accumulo.core.util.OpTimer) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService)

Example 44 with ThriftSecurityException

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);
    }
}
Also used : ActiveCompaction(org.apache.accumulo.core.client.admin.ActiveCompaction) TException(org.apache.thrift.TException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ArrayList(java.util.ArrayList) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ThriftUtil.returnClient(org.apache.accumulo.core.rpc.ThriftUtil.returnClient) ThriftUtil.createClient(org.apache.accumulo.core.rpc.ThriftUtil.createClient) ThriftUtil.getTServerClient(org.apache.accumulo.core.rpc.ThriftUtil.getTServerClient) Client(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)

Example 45 with ThriftSecurityException

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();
    }
}
Also used : ActiveCompaction(org.apache.accumulo.core.client.admin.ActiveCompaction) ActiveScan(org.apache.accumulo.core.client.admin.ActiveScan) ExternalCompactionUtil(org.apache.accumulo.core.util.compaction.ExternalCompactionUtil) CompactionHost(org.apache.accumulo.core.client.admin.ActiveCompaction.CompactionHost) HostAndPort(org.apache.accumulo.core.util.HostAndPort) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache) InstanceOperations(org.apache.accumulo.core.client.admin.InstanceOperations) LoggerFactory(org.slf4j.LoggerFactory) Callable(java.util.concurrent.Callable) ThriftUtil.returnClient(org.apache.accumulo.core.rpc.ThriftUtil.returnClient) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ArrayList(java.util.ArrayList) LocalityGroupUtil(org.apache.accumulo.core.util.LocalityGroupUtil) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Future(java.util.concurrent.Future) TTransport(org.apache.thrift.transport.TTransport) Map(java.util.Map) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ThriftUtil.createTransport(org.apache.accumulo.core.rpc.ThriftUtil.createTransport) ThriftUtil.createClient(org.apache.accumulo.core.rpc.ThriftUtil.createClient) InstanceId(org.apache.accumulo.core.data.InstanceId) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) AddressUtil(org.apache.accumulo.core.util.AddressUtil) LocalityGroupConfigurationError(org.apache.accumulo.core.util.LocalityGroupUtil.LocalityGroupConfigurationError) TException(org.apache.thrift.TException) ThreadPools(org.apache.accumulo.core.util.threads.ThreadPools) Constants(org.apache.accumulo.core.Constants) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ThriftUtil.getTServerClient(org.apache.accumulo.core.rpc.ThriftUtil.getTServerClient) ConfigurationType(org.apache.accumulo.core.clientImpl.thrift.ConfigurationType) ExecutionException(java.util.concurrent.ExecutionException) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ActiveCompaction(org.apache.accumulo.core.client.admin.ActiveCompaction) DeprecatedPropertyUtil(org.apache.accumulo.core.conf.DeprecatedPropertyUtil) TraceUtil(org.apache.accumulo.core.trace.TraceUtil) Collections(java.util.Collections) Client(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ArrayList(java.util.ArrayList) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) HostAndPort(org.apache.accumulo.core.util.HostAndPort) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ThriftSecurityException (org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)61 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)33 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)28 TException (org.apache.thrift.TException)25 ThriftTableOperationException (org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException)20 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)14 AccumuloException (org.apache.accumulo.core.client.AccumuloException)14 TableId (org.apache.accumulo.core.data.TableId)14 TKeyExtent (org.apache.accumulo.core.dataImpl.thrift.TKeyExtent)14 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)13 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)13 NamespaceId (org.apache.accumulo.core.data.NamespaceId)11 Tablet (org.apache.accumulo.tserver.tablet.Tablet)10 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)10 HashSet (java.util.HashSet)9 NotServingTabletException (org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException)9 TabletClientService (org.apache.accumulo.core.tabletserver.thrift.TabletClientService)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8