Search in sources :

Example 1 with OpTimer

use of org.apache.accumulo.core.util.OpTimer in project accumulo by apache.

the class TableOperationsImpl method list.

@Override
public SortedSet<String> list() {
    OpTimer timer = null;
    if (log.isTraceEnabled()) {
        log.trace("tid={} Fetching list of tables...", Thread.currentThread().getId());
        timer = new OpTimer().start();
    }
    TreeSet<String> tableNames = new TreeSet<>(Tables.getNameToIdMap(context.getInstance()).keySet());
    if (timer != null) {
        timer.stop();
        log.trace("tid={} Fetched {} table names in {}", Thread.currentThread().getId(), tableNames.size(), String.format("%.3f secs", timer.scale(TimeUnit.SECONDS)));
    }
    return tableNames;
}
Also used : TreeSet(java.util.TreeSet) OpTimer(org.apache.accumulo.core.util.OpTimer)

Example 2 with OpTimer

use of org.apache.accumulo.core.util.OpTimer in project accumulo by apache.

the class TableOperationsImpl method addSplits.

private void addSplits(String tableName, SortedSet<Text> partitionKeys, Table.ID tableId) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, AccumuloServerException {
    TabletLocator tabLocator = TabletLocator.getLocator(context, tableId);
    for (Text split : partitionKeys) {
        boolean successful = false;
        int attempt = 0;
        long locationFailures = 0;
        while (!successful) {
            if (attempt > 0)
                sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
            attempt++;
            TabletLocation tl = tabLocator.locateTablet(context, split, false, false);
            if (tl == null) {
                if (!Tables.exists(context.getInstance(), tableId))
                    throw new TableNotFoundException(tableId.canonicalID(), tableName, null);
                else if (Tables.getTableState(context.getInstance(), tableId) == TableState.OFFLINE)
                    throw new TableOfflineException(context.getInstance(), tableId.canonicalID());
                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(Tracer.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(TimeUnit.SECONDS)));
                    }
                } finally {
                    ThriftUtil.returnClient(client);
                }
            } catch (TApplicationException tae) {
                throw new AccumuloServerException(address.toString(), tae);
            } catch (TTransportException e) {
                tabLocator.invalidateCache(context.getInstance(), tl.tablet_location);
                continue;
            } catch (ThriftSecurityException e) {
                Tables.clearCache(context.getInstance());
                if (!Tables.exists(context.getInstance(), tableId))
                    throw new TableNotFoundException(tableId.canonicalID(), tableName, null);
                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 (5 == locationFailures || 0 == locationFailures % 50) {
                    log.warn("Having difficulty locating hosting tabletserver for split {} on table {}. Seen {} failures.", split, tableName, locationFailures);
                }
                tabLocator.invalidateCache(tl.tablet_extent);
                continue;
            } catch (TException e) {
                tabLocator.invalidateCache(context.getInstance(), tl.tablet_location);
                continue;
            }
            successful = true;
        }
    }
}
Also used : TException(org.apache.thrift.TException) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) 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.client.impl.thrift.ThriftSecurityException) Constraint(org.apache.accumulo.core.constraints.Constraint) TApplicationException(org.apache.thrift.TApplicationException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) HostAndPort(org.apache.accumulo.core.util.HostAndPort) TabletLocation(org.apache.accumulo.core.client.impl.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 3 with OpTimer

use of org.apache.accumulo.core.util.OpTimer in project accumulo by apache.

the class TabletLocatorImpl method binMutations.

@Override
public <T extends Mutation> void binMutations(ClientContext context, List<T> mutations, Map<String, TabletServerMutations<T>> binnedMutations, List<T> failures) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    OpTimer timer = null;
    if (log.isTraceEnabled()) {
        log.trace("tid={} Binning {} mutations for table {}", Thread.currentThread().getId(), mutations.size(), tableId);
        timer = new OpTimer().start();
    }
    ArrayList<T> notInCache = new ArrayList<>();
    Text row = new Text();
    LockCheckerSession lcSession = new LockCheckerSession();
    rLock.lock();
    try {
        processInvalidated(context, lcSession);
        for (T mutation : mutations) {
            row.set(mutation.getRow());
            TabletLocation tl = locateTabletInCache(row);
            if (tl == null || !addMutation(binnedMutations, mutation, tl, lcSession))
                notInCache.add(mutation);
        }
    } finally {
        rLock.unlock();
    }
    if (notInCache.size() > 0) {
        Collections.sort(notInCache, new Comparator<Mutation>() {

            @Override
            public int compare(Mutation o1, Mutation o2) {
                return WritableComparator.compareBytes(o1.getRow(), 0, o1.getRow().length, o2.getRow(), 0, o2.getRow().length);
            }
        });
        wLock.lock();
        try {
            boolean failed = false;
            for (T mutation : notInCache) {
                if (failed) {
                    // when one table does not return a location, something is probably
                    // screwy, go ahead and fail everything.
                    failures.add(mutation);
                    continue;
                }
                row.set(mutation.getRow());
                TabletLocation tl = _locateTablet(context, row, false, false, false, lcSession);
                if (tl == null || !addMutation(binnedMutations, mutation, tl, lcSession)) {
                    failures.add(mutation);
                    failed = true;
                }
            }
        } finally {
            wLock.unlock();
        }
    }
    if (timer != null) {
        timer.stop();
        log.trace("tid={} Binned {} mutations for table {} to {} tservers in {}", Thread.currentThread().getId(), mutations.size(), tableId, binnedMutations.size(), String.format("%.3f secs", timer.scale(TimeUnit.SECONDS)));
    }
}
Also used : OpTimer(org.apache.accumulo.core.util.OpTimer) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) Mutation(org.apache.accumulo.core.data.Mutation)

Example 4 with OpTimer

use of org.apache.accumulo.core.util.OpTimer in project accumulo by apache.

the class TabletLocatorImpl method locateTablet.

@Override
public TabletLocation locateTablet(ClientContext context, Text row, boolean skipRow, boolean retry) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    OpTimer timer = null;
    if (log.isTraceEnabled()) {
        log.trace("tid={} Locating tablet  table={} row={} skipRow={} retry={}", Thread.currentThread().getId(), tableId, TextUtil.truncate(row), skipRow, retry);
        timer = new OpTimer().start();
    }
    while (true) {
        LockCheckerSession lcSession = new LockCheckerSession();
        TabletLocation tl = _locateTablet(context, row, skipRow, retry, true, lcSession);
        if (retry && tl == null) {
            sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
            if (log.isTraceEnabled())
                log.trace("Failed to locate tablet containing row {} in table {}, will retry...", TextUtil.truncate(row), tableId);
            continue;
        }
        if (timer != null) {
            timer.stop();
            log.trace("tid={} Located tablet {} at {} in {}", Thread.currentThread().getId(), (tl == null ? "null" : tl.tablet_extent), (tl == null ? "null" : tl.tablet_location), String.format("%.3f secs", timer.scale(TimeUnit.SECONDS)));
        }
        return tl;
    }
}
Also used : OpTimer(org.apache.accumulo.core.util.OpTimer)

Example 5 with OpTimer

use of org.apache.accumulo.core.util.OpTimer in project accumulo by apache.

the class TabletServerBatchReaderIterator method doLookup.

static void doLookup(ClientContext context, String server, Map<KeyExtent, List<Range>> requested, Map<KeyExtent, List<Range>> failures, Map<KeyExtent, List<Range>> unscanned, ResultReceiver receiver, List<Column> columns, ScannerOptions options, Authorizations authorizations, TimeoutTracker timeoutTracker) throws IOException, AccumuloSecurityException, AccumuloServerException {
    if (requested.size() == 0) {
        return;
    }
    // copy requested to unscanned map. we will remove ranges as they are scanned in trackScanning()
    for (Entry<KeyExtent, List<Range>> entry : requested.entrySet()) {
        ArrayList<Range> ranges = new ArrayList<>();
        for (Range range : entry.getValue()) {
            ranges.add(new Range(range));
        }
        unscanned.put(new KeyExtent(entry.getKey()), ranges);
    }
    timeoutTracker.startingScan();
    TTransport transport = null;
    try {
        final HostAndPort parsedServer = HostAndPort.fromString(server);
        final TabletClientService.Client client;
        if (timeoutTracker.getTimeOut() < context.getClientTimeoutInMillis())
            client = ThriftUtil.getTServerClient(parsedServer, context, timeoutTracker.getTimeOut());
        else
            client = ThriftUtil.getTServerClient(parsedServer, context);
        try {
            OpTimer timer = null;
            if (log.isTraceEnabled()) {
                log.trace("tid={} Starting multi scan, tserver={}  #tablets={}  #ranges={} ssil={} ssio={}", Thread.currentThread().getId(), server, requested.size(), sumSizes(requested.values()), options.serverSideIteratorList, options.serverSideIteratorOptions);
                timer = new OpTimer().start();
            }
            TabletType ttype = TabletType.type(requested.keySet());
            boolean waitForWrites = !ThriftScanner.serversWaitedForWrites.get(ttype).contains(server);
            Map<TKeyExtent, List<TRange>> thriftTabletRanges = Translator.translate(requested, Translators.KET, new Translator.ListTranslator<>(Translators.RT));
            InitialMultiScan imsr = client.startMultiScan(Tracer.traceInfo(), context.rpcCreds(), thriftTabletRanges, Translator.translate(columns, Translators.CT), options.serverSideIteratorList, options.serverSideIteratorOptions, ByteBufferUtil.toByteBuffers(authorizations.getAuthorizations()), waitForWrites, SamplerConfigurationImpl.toThrift(options.getSamplerConfiguration()), options.batchTimeOut, options.classLoaderContext);
            if (waitForWrites)
                ThriftScanner.serversWaitedForWrites.get(ttype).add(server.toString());
            MultiScanResult scanResult = imsr.result;
            if (timer != null) {
                timer.stop();
                log.trace("tid={} Got 1st multi scan results, #results={} {} in {}", Thread.currentThread().getId(), scanResult.results.size(), (scanResult.more ? "scanID=" + imsr.scanID : ""), String.format("%.3f secs", timer.scale(TimeUnit.SECONDS)));
            }
            ArrayList<Entry<Key, Value>> entries = new ArrayList<>(scanResult.results.size());
            for (TKeyValue kv : scanResult.results) {
                entries.add(new SimpleImmutableEntry<>(new Key(kv.key), new Value(kv.value)));
            }
            if (entries.size() > 0)
                receiver.receive(entries);
            if (entries.size() > 0 || scanResult.fullScans.size() > 0)
                timeoutTracker.madeProgress();
            trackScanning(failures, unscanned, scanResult);
            AtomicLong nextOpid = new AtomicLong();
            while (scanResult.more) {
                timeoutTracker.check();
                if (timer != null) {
                    log.trace("tid={} oid={} Continuing multi scan, scanid={}", Thread.currentThread().getId(), nextOpid.get(), imsr.scanID);
                    timer.reset().start();
                }
                scanResult = client.continueMultiScan(Tracer.traceInfo(), imsr.scanID);
                if (timer != null) {
                    timer.stop();
                    log.trace("tid={} oid={} Got more multi scan results, #results={} {} in {}", Thread.currentThread().getId(), nextOpid.getAndIncrement(), scanResult.results.size(), (scanResult.more ? " scanID=" + imsr.scanID : ""), String.format("%.3f secs", timer.scale(TimeUnit.SECONDS)));
                }
                entries = new ArrayList<>(scanResult.results.size());
                for (TKeyValue kv : scanResult.results) {
                    entries.add(new SimpleImmutableEntry<>(new Key(kv.key), new Value(kv.value)));
                }
                if (entries.size() > 0)
                    receiver.receive(entries);
                if (entries.size() > 0 || scanResult.fullScans.size() > 0)
                    timeoutTracker.madeProgress();
                trackScanning(failures, unscanned, scanResult);
            }
            client.closeMultiScan(Tracer.traceInfo(), imsr.scanID);
        } finally {
            ThriftUtil.returnClient(client);
        }
    } catch (TTransportException e) {
        log.debug("Server : {} msg : {}", server, e.getMessage());
        timeoutTracker.errorOccured(e);
        throw new IOException(e);
    } catch (ThriftSecurityException e) {
        log.debug("Server : {} msg : {}", server, e.getMessage(), e);
        throw new AccumuloSecurityException(e.user, e.code, e);
    } catch (TApplicationException e) {
        log.debug("Server : {} msg : {}", server, e.getMessage(), e);
        throw new AccumuloServerException(server, e);
    } catch (NoSuchScanIDException e) {
        log.debug("Server : {} msg : {}", server, e.getMessage(), e);
        throw new IOException(e);
    } catch (TSampleNotPresentException e) {
        log.debug("Server : " + server + " msg : " + e.getMessage(), e);
        String tableInfo = "?";
        if (e.getExtent() != null) {
            Table.ID tableId = new KeyExtent(e.getExtent()).getTableId();
            tableInfo = Tables.getPrintableTableInfoFromId(context.getInstance(), tableId);
        }
        String message = "Table " + tableInfo + " does not have sampling configured or built";
        throw new SampleNotPresentException(message, e);
    } catch (TException e) {
        log.debug("Server : {} msg : {}", server, e.getMessage(), e);
        timeoutTracker.errorOccured(e);
        throw new IOException(e);
    } finally {
        ThriftTransportPool.getInstance().returnTransport(transport);
    }
}
Also used : TException(org.apache.thrift.TException) ArrayList(java.util.ArrayList) TTransportException(org.apache.thrift.transport.TTransportException) TKeyExtent(org.apache.accumulo.core.data.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) HostAndPort(org.apache.accumulo.core.util.HostAndPort) Entry(java.util.Map.Entry) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) MultiScanResult(org.apache.accumulo.core.data.thrift.MultiScanResult) List(java.util.List) ArrayList(java.util.ArrayList) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TKeyValue(org.apache.accumulo.core.data.thrift.TKeyValue) InitialMultiScan(org.apache.accumulo.core.data.thrift.InitialMultiScan) TKeyExtent(org.apache.accumulo.core.data.thrift.TKeyExtent) IOException(java.io.IOException) TRange(org.apache.accumulo.core.data.thrift.TRange) Range(org.apache.accumulo.core.data.Range) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) NoSuchScanIDException(org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException) TApplicationException(org.apache.thrift.TApplicationException) AtomicLong(java.util.concurrent.atomic.AtomicLong) TSampleNotPresentException(org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) TSampleNotPresentException(org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException) OpTimer(org.apache.accumulo.core.util.OpTimer) TKeyValue(org.apache.accumulo.core.data.thrift.TKeyValue) Value(org.apache.accumulo.core.data.Value) TTransport(org.apache.thrift.transport.TTransport) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) Key(org.apache.accumulo.core.data.Key)

Aggregations

OpTimer (org.apache.accumulo.core.util.OpTimer)17 ArrayList (java.util.ArrayList)5 Key (org.apache.accumulo.core.data.Key)4 Range (org.apache.accumulo.core.data.Range)4 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)3 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)3 Value (org.apache.accumulo.core.data.Value)3 TabletClientService (org.apache.accumulo.core.tabletserver.thrift.TabletClientService)3 HostAndPort (org.apache.accumulo.core.util.HostAndPort)3 Text (org.apache.hadoop.io.Text)3 Entry (java.util.Map.Entry)2 TreeSet (java.util.TreeSet)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 PartialKey (org.apache.accumulo.core.data.PartialKey)2 TKeyValue (org.apache.accumulo.core.data.thrift.TKeyValue)2 NotServingTabletException (org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException)2 TApplicationException (org.apache.thrift.TApplicationException)2 TException (org.apache.thrift.TException)2 TTransportException (org.apache.thrift.transport.TTransportException)2 IOException (java.io.IOException)1