Search in sources :

Example 1 with TKey

use of org.apache.accumulo.core.data.thrift.TKey in project accumulo by apache.

the class KeyTest method testThrift.

@Test
public void testThrift() {
    Key k = new Key("r1", "cf2", "cq2", "cv");
    TKey tk = k.toThrift();
    Key k2 = new Key(tk);
    assertEquals(k, k2);
}
Also used : TKey(org.apache.accumulo.core.data.thrift.TKey) TKey(org.apache.accumulo.core.data.thrift.TKey) Test(org.junit.Test)

Example 2 with TKey

use of org.apache.accumulo.core.data.thrift.TKey in project accumulo by apache.

the class Key method decompress.

/**
 * Decompresses a list of key/value pairs received from thrift. Decompression occurs in place, in the list.
 *
 * @param param
 *          list of Thrift key/value pairs
 */
public static void decompress(List<TKeyValue> param) {
    for (int i = 1; i < param.size(); i++) {
        TKey prevKey = param.get(i - 1).key;
        TKey key = param.get(i).key;
        if (key.row == null) {
            key.row = prevKey.row;
        }
        if (key.colFamily == null) {
            key.colFamily = prevKey.colFamily;
        }
        if (key.colQualifier == null) {
            key.colQualifier = prevKey.colQualifier;
        }
        if (key.colVisibility == null) {
            key.colVisibility = prevKey.colVisibility;
        }
    }
}
Also used : TKey(org.apache.accumulo.core.data.thrift.TKey)

Example 3 with TKey

use of org.apache.accumulo.core.data.thrift.TKey in project accumulo by apache.

the class KeyTest method testThrift_Invalid.

@Test(expected = IllegalArgumentException.class)
public void testThrift_Invalid() {
    Key k = new Key("r1", "cf2", "cq2", "cv");
    TKey tk = k.toThrift();
    tk.setRow((byte[]) null);
    new Key(tk);
}
Also used : TKey(org.apache.accumulo.core.data.thrift.TKey) TKey(org.apache.accumulo.core.data.thrift.TKey) Test(org.junit.Test)

Example 4 with TKey

use of org.apache.accumulo.core.data.thrift.TKey in project accumulo by apache.

the class LookupTask method run.

@Override
public void run() {
    MultiScanSession session = (MultiScanSession) server.getSession(scanID);
    String oldThreadName = Thread.currentThread().getName();
    try {
        if (isCancelled() || session == null)
            return;
        TableConfiguration acuTableConf = server.getTableConfiguration(session.threadPoolExtent);
        long maxResultsSize = acuTableConf.getAsBytes(Property.TABLE_SCAN_MAXMEM);
        runState.set(ScanRunState.RUNNING);
        Thread.currentThread().setName("Client: " + session.client + " User: " + session.getUser() + " Start: " + session.startTime + " Table: ");
        long bytesAdded = 0;
        long maxScanTime = 4000;
        long startTime = System.currentTimeMillis();
        List<KVEntry> results = new ArrayList<>();
        Map<KeyExtent, List<Range>> failures = new HashMap<>();
        List<KeyExtent> fullScans = new ArrayList<>();
        KeyExtent partScan = null;
        Key partNextKey = null;
        boolean partNextKeyInclusive = false;
        Iterator<Entry<KeyExtent, List<Range>>> iter = session.queries.entrySet().iterator();
        // check the time so that the read ahead thread is not monopolized
        while (iter.hasNext() && bytesAdded < maxResultsSize && (System.currentTimeMillis() - startTime) < maxScanTime) {
            Entry<KeyExtent, List<Range>> entry = iter.next();
            iter.remove();
            // check that tablet server is serving requested tablet
            Tablet tablet = server.getOnlineTablet(entry.getKey());
            if (tablet == null) {
                failures.put(entry.getKey(), entry.getValue());
                continue;
            }
            Thread.currentThread().setName("Client: " + session.client + " User: " + session.getUser() + " Start: " + session.startTime + " Tablet: " + entry.getKey().toString());
            LookupResult lookupResult;
            try {
                // canceled
                if (isCancelled())
                    interruptFlag.set(true);
                lookupResult = tablet.lookup(entry.getValue(), session.columnSet, session.auths, results, maxResultsSize - bytesAdded, session.ssiList, session.ssio, interruptFlag, session.samplerConfig, session.batchTimeOut, session.context);
                // if the tablet was closed it it possible that the
                // interrupt flag was set.... do not want it set for
                // the next
                // lookup
                interruptFlag.set(false);
            } catch (IOException e) {
                log.warn("lookup failed for tablet " + entry.getKey(), e);
                throw new RuntimeException(e);
            }
            bytesAdded += lookupResult.bytesAdded;
            if (lookupResult.unfinishedRanges.size() > 0) {
                if (lookupResult.closed) {
                    failures.put(entry.getKey(), lookupResult.unfinishedRanges);
                } else {
                    session.queries.put(entry.getKey(), lookupResult.unfinishedRanges);
                    partScan = entry.getKey();
                    partNextKey = lookupResult.unfinishedRanges.get(0).getStartKey();
                    partNextKeyInclusive = lookupResult.unfinishedRanges.get(0).isStartKeyInclusive();
                }
            } else {
                fullScans.add(entry.getKey());
            }
        }
        long finishTime = System.currentTimeMillis();
        session.totalLookupTime += (finishTime - startTime);
        session.numEntries += results.size();
        // convert everything to thrift before adding result
        List<TKeyValue> retResults = new ArrayList<>();
        for (KVEntry entry : results) retResults.add(new TKeyValue(entry.getKey().toThrift(), ByteBuffer.wrap(entry.getValue().get())));
        Map<TKeyExtent, List<TRange>> retFailures = Translator.translate(failures, Translators.KET, new Translator.ListTranslator<>(Translators.RT));
        List<TKeyExtent> retFullScans = Translator.translate(fullScans, Translators.KET);
        TKeyExtent retPartScan = null;
        TKey retPartNextKey = null;
        if (partScan != null) {
            retPartScan = partScan.toThrift();
            retPartNextKey = partNextKey.toThrift();
        }
        // add results to queue
        addResult(new MultiScanResult(retResults, retFailures, retFullScans, retPartScan, retPartNextKey, partNextKeyInclusive, session.queries.size() != 0));
    } catch (IterationInterruptedException iie) {
        if (!isCancelled()) {
            log.warn("Iteration interrupted, when scan not cancelled", iie);
            addResult(iie);
        }
    } catch (SampleNotPresentException e) {
        addResult(e);
    } catch (Throwable e) {
        log.warn("exception while doing multi-scan ", e);
        addResult(e);
    } finally {
        Thread.currentThread().setName(oldThreadName);
        runState.set(ScanRunState.FINISHED);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TKey(org.apache.accumulo.core.data.thrift.TKey) TKeyExtent(org.apache.accumulo.core.data.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) KVEntry(org.apache.accumulo.tserver.tablet.KVEntry) Entry(java.util.Map.Entry) MultiScanResult(org.apache.accumulo.core.data.thrift.MultiScanResult) Translator(org.apache.accumulo.core.client.impl.Translator) IterationInterruptedException(org.apache.accumulo.core.iterators.IterationInterruptedException) ArrayList(java.util.ArrayList) List(java.util.List) Tablet(org.apache.accumulo.tserver.tablet.Tablet) TableConfiguration(org.apache.accumulo.server.conf.TableConfiguration) TKeyValue(org.apache.accumulo.core.data.thrift.TKeyValue) IOException(java.io.IOException) TKeyExtent(org.apache.accumulo.core.data.thrift.TKeyExtent) TRange(org.apache.accumulo.core.data.thrift.TRange) Range(org.apache.accumulo.core.data.Range) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) KVEntry(org.apache.accumulo.tserver.tablet.KVEntry) LookupResult(org.apache.accumulo.tserver.tablet.Tablet.LookupResult) MultiScanSession(org.apache.accumulo.tserver.session.MultiScanSession) Key(org.apache.accumulo.core.data.Key) TKey(org.apache.accumulo.core.data.thrift.TKey)

Example 5 with TKey

use of org.apache.accumulo.core.data.thrift.TKey in project accumulo by apache.

the class Key method compress.

/**
 * Compresses a list of key/value pairs before sending them via thrift.
 *
 * @param param
 *          list of key/value pairs
 * @return list of Thrift key/value pairs
 */
public static List<TKeyValue> compress(List<? extends KeyValue> param) {
    List<TKeyValue> tkvl = Arrays.asList(new TKeyValue[param.size()]);
    if (param.size() > 0)
        tkvl.set(0, new TKeyValue(param.get(0).getKey().toThrift(), ByteBuffer.wrap(param.get(0).getValue().get())));
    for (int i = param.size() - 1; i > 0; i--) {
        Key prevKey = param.get(i - 1).getKey();
        KeyValue kv = param.get(i);
        Key key = kv.getKey();
        TKey newKey = null;
        if (isEqual(prevKey.row, key.row)) {
            newKey = key.toThrift();
            newKey.row = null;
        }
        if (isEqual(prevKey.colFamily, key.colFamily)) {
            if (newKey == null)
                newKey = key.toThrift();
            newKey.colFamily = null;
        }
        if (isEqual(prevKey.colQualifier, key.colQualifier)) {
            if (newKey == null)
                newKey = key.toThrift();
            newKey.colQualifier = null;
        }
        if (isEqual(prevKey.colVisibility, key.colVisibility)) {
            if (newKey == null)
                newKey = key.toThrift();
            newKey.colVisibility = null;
        }
        if (newKey == null)
            newKey = key.toThrift();
        tkvl.set(i, new TKeyValue(newKey, ByteBuffer.wrap(kv.getValue().get())));
    }
    return tkvl;
}
Also used : TKeyValue(org.apache.accumulo.core.data.thrift.TKeyValue) TKeyValue(org.apache.accumulo.core.data.thrift.TKeyValue) TKey(org.apache.accumulo.core.data.thrift.TKey) TKey(org.apache.accumulo.core.data.thrift.TKey)

Aggregations

TKey (org.apache.accumulo.core.data.thrift.TKey)5 TKeyValue (org.apache.accumulo.core.data.thrift.TKeyValue)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 SampleNotPresentException (org.apache.accumulo.core.client.SampleNotPresentException)1 Translator (org.apache.accumulo.core.client.impl.Translator)1 Key (org.apache.accumulo.core.data.Key)1 Range (org.apache.accumulo.core.data.Range)1 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)1 MultiScanResult (org.apache.accumulo.core.data.thrift.MultiScanResult)1 TKeyExtent (org.apache.accumulo.core.data.thrift.TKeyExtent)1 TRange (org.apache.accumulo.core.data.thrift.TRange)1 IterationInterruptedException (org.apache.accumulo.core.iterators.IterationInterruptedException)1 TableConfiguration (org.apache.accumulo.server.conf.TableConfiguration)1 MultiScanSession (org.apache.accumulo.tserver.session.MultiScanSession)1 KVEntry (org.apache.accumulo.tserver.tablet.KVEntry)1