Search in sources :

Example 1 with AccumuloServerException

use of org.apache.accumulo.core.clientImpl.AccumuloServerException in project accumulo by apache.

the class MetadataLocationObtainer method lookupTablets.

@Override
public List<TabletLocation> lookupTablets(ClientContext context, String tserver, Map<KeyExtent, List<Range>> tabletsRanges, TabletLocator parent) throws AccumuloSecurityException, AccumuloException {
    final TreeMap<Key, Value> results = new TreeMap<>();
    ResultReceiver rr = entries -> {
        for (Entry<Key, Value> entry : entries) {
            try {
                results.putAll(WholeRowIterator.decodeRow(entry.getKey(), entry.getValue()));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    };
    ScannerOptions opts = null;
    try (SettableScannerOptions unsetOpts = new SettableScannerOptions()) {
        opts = unsetOpts.setColumns(locCols);
    }
    Map<KeyExtent, List<Range>> unscanned = new HashMap<>();
    Map<KeyExtent, List<Range>> failures = new HashMap<>();
    try {
        TabletServerBatchReaderIterator.doLookup(context, tserver, tabletsRanges, failures, unscanned, rr, columns, opts, Authorizations.EMPTY);
        if (!failures.isEmpty()) {
            // invalidate extents in parents cache
            if (log.isTraceEnabled())
                log.trace("lookupTablets failed for {} extents", failures.size());
            parent.invalidateCache(failures.keySet());
        }
    } catch (IOException e) {
        log.trace("lookupTablets failed server={}", tserver, e);
        parent.invalidateCache(context, tserver);
    } catch (AccumuloServerException e) {
        log.trace("lookupTablets failed server={}", tserver, e);
        throw e;
    }
    return MetadataLocationObtainer.getMetadataLocationEntries(results).getLocations();
}
Also used : TabletServerBatchReaderIterator(org.apache.accumulo.core.clientImpl.TabletServerBatchReaderIterator) SortedSet(java.util.SortedSet) TabletLocation(org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation) LoggerFactory(org.slf4j.LoggerFactory) Text(org.apache.hadoop.io.Text) HashMap(java.util.HashMap) ResultReceiver(org.apache.accumulo.core.clientImpl.TabletServerBatchReaderIterator.ResultReceiver) IterInfo(org.apache.accumulo.core.dataImpl.thrift.IterInfo) FutureLocationColumnFamily(org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.FutureLocationColumnFamily) TextUtil(org.apache.accumulo.core.util.TextUtil) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) TabletLocator(org.apache.accumulo.core.clientImpl.TabletLocator) CurrentLocationColumnFamily(org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily) Map(java.util.Map) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Key(org.apache.accumulo.core.data.Key) Value(org.apache.accumulo.core.data.Value) ScannerOptions(org.apache.accumulo.core.clientImpl.ScannerOptions) ThriftScanner(org.apache.accumulo.core.clientImpl.ThriftScanner) Logger(org.slf4j.Logger) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) Column(org.apache.accumulo.core.data.Column) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) IOException(java.io.IOException) Constants(org.apache.accumulo.core.Constants) Authorizations(org.apache.accumulo.core.security.Authorizations) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Range(org.apache.accumulo.core.data.Range) AccumuloServerException(org.apache.accumulo.core.clientImpl.AccumuloServerException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) List(java.util.List) TabletLocationObtainer(org.apache.accumulo.core.clientImpl.TabletLocatorImpl.TabletLocationObtainer) OpTimer(org.apache.accumulo.core.util.OpTimer) TreeMap(java.util.TreeMap) Entry(java.util.Map.Entry) TabletLocations(org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocations) TabletColumnFamily(org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.TabletColumnFamily) PartialKey(org.apache.accumulo.core.data.PartialKey) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) SortedMap(java.util.SortedMap) WholeRowIterator(org.apache.accumulo.core.iterators.user.WholeRowIterator) HashMap(java.util.HashMap) IOException(java.io.IOException) TreeMap(java.util.TreeMap) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) AccumuloServerException(org.apache.accumulo.core.clientImpl.AccumuloServerException) Entry(java.util.Map.Entry) Value(org.apache.accumulo.core.data.Value) ArrayList(java.util.ArrayList) List(java.util.List) ScannerOptions(org.apache.accumulo.core.clientImpl.ScannerOptions) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey) ResultReceiver(org.apache.accumulo.core.clientImpl.TabletServerBatchReaderIterator.ResultReceiver)

Example 2 with AccumuloServerException

use of org.apache.accumulo.core.clientImpl.AccumuloServerException in project accumulo by apache.

the class MetadataLocationObtainer method lookupTablet.

@Override
public TabletLocations lookupTablet(ClientContext context, TabletLocation src, Text row, Text stopRow, TabletLocator parent) throws AccumuloSecurityException, AccumuloException {
    try {
        OpTimer timer = null;
        if (log.isTraceEnabled()) {
            log.trace("tid={} Looking up in {} row={} extent={} tserver={}", Thread.currentThread().getId(), src.tablet_extent.tableId(), TextUtil.truncate(row), src.tablet_extent, src.tablet_location);
            timer = new OpTimer().start();
        }
        Range range = new Range(row, true, stopRow, true);
        TreeMap<Key, Value> encodedResults = new TreeMap<>();
        TreeMap<Key, Value> results = new TreeMap<>();
        // Use the whole row iterator so that a partial mutations is not read. The code that extracts
        // locations for tablets does a sanity check to ensure there is
        // only one location. Reading a partial mutation could make it appear there are multiple
        // locations when there are not.
        List<IterInfo> serverSideIteratorList = new ArrayList<>();
        serverSideIteratorList.add(new IterInfo(10000, WholeRowIterator.class.getName(), "WRI"));
        Map<String, Map<String, String>> serverSideIteratorOptions = Collections.emptyMap();
        boolean more = ThriftScanner.getBatchFromServer(context, range, src.tablet_extent, src.tablet_location, encodedResults, locCols, serverSideIteratorList, serverSideIteratorOptions, Constants.SCAN_BATCH_SIZE, Authorizations.EMPTY, 0L, null);
        decodeRows(encodedResults, results);
        if (more && results.size() == 1) {
            range = new Range(results.lastKey().followingKey(PartialKey.ROW_COLFAM_COLQUAL_COLVIS_TIME), true, new Key(stopRow).followingKey(PartialKey.ROW), false);
            encodedResults.clear();
            more = ThriftScanner.getBatchFromServer(context, range, src.tablet_extent, src.tablet_location, encodedResults, locCols, serverSideIteratorList, serverSideIteratorOptions, Constants.SCAN_BATCH_SIZE, Authorizations.EMPTY, 0L, null);
            decodeRows(encodedResults, results);
        }
        if (timer != null) {
            timer.stop();
            log.trace("tid={} Got {} results from {} in {}", Thread.currentThread().getId(), results.size(), src.tablet_extent, String.format("%.3f secs", timer.scale(SECONDS)));
        }
        return MetadataLocationObtainer.getMetadataLocationEntries(results);
    } catch (AccumuloServerException ase) {
        if (log.isTraceEnabled())
            log.trace("{} lookup failed, {} server side exception", src.tablet_extent.tableId(), src.tablet_location);
        throw ase;
    } catch (AccumuloException e) {
        if (log.isTraceEnabled())
            log.trace("{} lookup failed", src.tablet_extent.tableId(), e);
        parent.invalidateCache(context, src.tablet_location);
    }
    return null;
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) ArrayList(java.util.ArrayList) Range(org.apache.accumulo.core.data.Range) TreeMap(java.util.TreeMap) IterInfo(org.apache.accumulo.core.dataImpl.thrift.IterInfo) AccumuloServerException(org.apache.accumulo.core.clientImpl.AccumuloServerException) OpTimer(org.apache.accumulo.core.util.OpTimer) Value(org.apache.accumulo.core.data.Value) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 AccumuloException (org.apache.accumulo.core.client.AccumuloException)2 AccumuloServerException (org.apache.accumulo.core.clientImpl.AccumuloServerException)2 Key (org.apache.accumulo.core.data.Key)2 PartialKey (org.apache.accumulo.core.data.PartialKey)2 Range (org.apache.accumulo.core.data.Range)2 Value (org.apache.accumulo.core.data.Value)2 IterInfo (org.apache.accumulo.core.dataImpl.thrift.IterInfo)2 OpTimer (org.apache.accumulo.core.util.OpTimer)2 IOException (java.io.IOException)1 Collections (java.util.Collections)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 SECONDS (java.util.concurrent.TimeUnit.SECONDS)1