Search in sources :

Example 1 with ScannerOptions

use of org.apache.accumulo.core.client.impl.ScannerOptions 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)

Example 2 with ScannerOptions

use of org.apache.accumulo.core.client.impl.ScannerOptions in project vertexium by visallo.

the class AccumuloGraphLogger method logStartIterator.

public void logStartIterator(ScannerBase scanner) {
    if (!queryLogger.isTraceEnabled()) {
        return;
    }
    SortedSet<Column> fetchedColumns = null;
    if (scanner instanceof ScannerOptions) {
        fetchedColumns = ((ScannerOptions) scanner).getFetchedColumns();
    }
    String table = null;
    try {
        Field tableField = scanner.getClass().getDeclaredField("table");
        tableField.setAccessible(true);
        Object tableObj = tableField.get(scanner);
        if (tableObj instanceof String) {
            table = (String) tableObj;
        } else {
            table = tableObj.toString();
        }
    } catch (Exception e) {
        queryLogger.trace("Could not get table name from scanner", e);
    }
    if (scanner instanceof BatchScanner) {
        try {
            Field rangesField = scanner.getClass().getDeclaredField("ranges");
            rangesField.setAccessible(true);
            ArrayList<Range> ranges = (ArrayList<Range>) rangesField.get(scanner);
            if (ranges.size() == 0) {
                logStartIterator(table, (Range) null, fetchedColumns);
            } else if (ranges.size() == 1) {
                logStartIterator(table, ranges.iterator().next(), fetchedColumns);
            } else {
                logStartIterator(table, ranges, fetchedColumns);
            }
        } catch (Exception e) {
            queryLogger.trace("Could not get ranges from BatchScanner", e);
        }
    } else if (scanner instanceof Scanner) {
        Range range = ((Scanner) scanner).getRange();
        logStartIterator(table, range, fetchedColumns);
    } else {
        queryLogger.trace("begin accumulo iterator: %s", scanner.getClass().getName());
    }
}
Also used : Field(java.lang.reflect.Field) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Scanner(org.apache.accumulo.core.client.Scanner) Column(org.apache.accumulo.core.data.Column) BatchScanner(org.apache.accumulo.core.client.BatchScanner) ArrayList(java.util.ArrayList) ScannerOptions(org.apache.accumulo.core.client.impl.ScannerOptions) Range(org.apache.accumulo.core.data.Range)

Aggregations

ArrayList (java.util.ArrayList)2 ScannerOptions (org.apache.accumulo.core.client.impl.ScannerOptions)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 BatchScanner (org.apache.accumulo.core.client.BatchScanner)1 Scanner (org.apache.accumulo.core.client.Scanner)1 AccumuloServerException (org.apache.accumulo.core.client.impl.AccumuloServerException)1 ResultReceiver (org.apache.accumulo.core.client.impl.TabletServerBatchReaderIterator.ResultReceiver)1 Column (org.apache.accumulo.core.data.Column)1 Key (org.apache.accumulo.core.data.Key)1 PartialKey (org.apache.accumulo.core.data.PartialKey)1 Range (org.apache.accumulo.core.data.Range)1 Value (org.apache.accumulo.core.data.Value)1 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)1