Search in sources :

Example 1 with ResultReceiver

use of org.apache.accumulo.core.client.impl.TabletServerBatchReaderIterator.ResultReceiver 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 = new ResultReceiver() {

        @Override
        public void receive(List<Entry<Key, Value>> 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.size() > 0) {
            // 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.getInstance(), tserver);
    } catch (AccumuloServerException e) {
        log.trace("lookupTablets failed server={}", tserver, e);
        throw e;
    }
    return MetadataLocationObtainer.getMetadataLocationEntries(results).getLocations();
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) TreeMap(java.util.TreeMap) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) AccumuloServerException(org.apache.accumulo.core.client.impl.AccumuloServerException) Value(org.apache.accumulo.core.data.Value) ArrayList(java.util.ArrayList) List(java.util.List) ScannerOptions(org.apache.accumulo.core.client.impl.ScannerOptions) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey) ResultReceiver(org.apache.accumulo.core.client.impl.TabletServerBatchReaderIterator.ResultReceiver)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 AccumuloServerException (org.apache.accumulo.core.client.impl.AccumuloServerException)1 ScannerOptions (org.apache.accumulo.core.client.impl.ScannerOptions)1 ResultReceiver (org.apache.accumulo.core.client.impl.TabletServerBatchReaderIterator.ResultReceiver)1 Key (org.apache.accumulo.core.data.Key)1 PartialKey (org.apache.accumulo.core.data.PartialKey)1 Value (org.apache.accumulo.core.data.Value)1 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)1