Search in sources :

Example 16 with KeySliceQuery

use of org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery in project janusgraph by JanusGraph.

the class KeyColumnValueStoreTest method testStoreTTL.

@Test
public void testStoreTTL() throws Exception {
    KeyColumnValueStoreManager storeManager = manager;
    // @see TTLKCVSManager
    if (storeManager.getFeatures().hasCellTTL() && !storeManager.getFeatures().hasStoreTTL()) {
        storeManager = new TTLKCVSManager(storeManager);
    } else if (!storeManager.getFeatures().hasStoreTTL()) {
        return;
    }
    assertTrue(storeManager.getFeatures().hasStoreTTL());
    final TimeUnit sec = TimeUnit.SECONDS;
    final int storeTTLSeconds = (int) TestGraphConfigs.getTTL(sec);
    StoreMetaData.Container opts = new StoreMetaData.Container();
    opts.put(StoreMetaData.TTL, storeTTLSeconds);
    KeyColumnValueStore storeWithTTL = storeManager.openDatabase("testStore_with_TTL", opts);
    populateDBWith100Keys(storeWithTTL);
    tx.commit();
    tx = startTx();
    final StaticBuffer key = KeyColumnValueStoreUtil.longToByteBuffer(2);
    StaticBuffer start = KeyColumnValueStoreUtil.stringToByteBuffer("a");
    StaticBuffer end = KeyColumnValueStoreUtil.stringToByteBuffer("d");
    EntryList results = storeWithTTL.getSlice(new KeySliceQuery(key, new SliceQuery(start, end)), tx);
    assertEquals(3, results.size());
    Thread.sleep(TimeUnit.MILLISECONDS.convert((long) Math.ceil(storeTTLSeconds * 1.25), sec));
    tx.commit();
    tx = startTx();
    results = storeWithTTL.getSlice(new KeySliceQuery(key, new SliceQuery(start, end)), tx);
    // should be empty if TTL was applied properly
    assertEquals(0, results.size());
    storeWithTTL.close();
}
Also used : KeyColumnValueStore(org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore) TTLKCVSManager(org.janusgraph.diskstorage.keycolumnvalue.ttl.TTLKCVSManager) KeyColumnValueStoreManager(org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStoreManager) TimeUnit(java.util.concurrent.TimeUnit) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) Test(org.junit.jupiter.api.Test) JanusGraphBaseStoreFeaturesTest(org.janusgraph.JanusGraphBaseStoreFeaturesTest)

Example 17 with KeySliceQuery

use of org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery in project janusgraph by JanusGraph.

the class MultiKeySliceQuery method execute.

public List<EntryList> execute(final BackendTransaction tx) {
    int total = 0;
    final List<EntryList> result = new ArrayList<>(Math.min(getLimit(), queries.size()));
    for (KeySliceQuery ksq : queries) {
        EntryList next = tx.indexQuery(ksq.updateLimit(getLimit() - total));
        result.add(next);
        total += next.size();
        if (total >= getLimit())
            break;
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) EntryList(org.janusgraph.diskstorage.EntryList) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)

Example 18 with KeySliceQuery

use of org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery in project janusgraph by JanusGraph.

the class KCVSConfiguration method toMap.

private Map<String, Object> toMap() {
    List<Entry> result = BackendOperation.execute(new BackendOperation.Transactional<List<Entry>>() {

        @Override
        public List<Entry> call(StoreTransaction txh) throws BackendException {
            return store.getSlice(new KeySliceQuery(rowKey, BufferUtil.zeroBuffer(1), BufferUtil.oneBuffer(128)), txh);
        }

        @Override
        public String toString() {
            return "setConfiguration";
        }
    }, txProvider, times, maxOperationWaitTime);
    Map<String, Object> entries = new HashMap<>(result.size());
    for (Entry entry : result) {
        String key = staticBuffer2String(entry.getColumnAs(StaticBuffer.STATIC_FACTORY));
        Object value = staticBuffer2Object(entry.getValueAs(StaticBuffer.STATIC_FACTORY), Object.class);
        entries.put(key, value);
    }
    return entries;
}
Also used : HashMap(java.util.HashMap) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) BackendOperation(org.janusgraph.diskstorage.util.BackendOperation) BackendException(org.janusgraph.diskstorage.BackendException) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Entry(org.janusgraph.diskstorage.Entry) ArrayList(java.util.ArrayList) List(java.util.List) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)

Example 19 with KeySliceQuery

use of org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery in project janusgraph by JanusGraph.

the class BackendTransaction method edgeStoreMultiQuery.

public Map<StaticBuffer, EntryList> edgeStoreMultiQuery(final List<StaticBuffer> keys, final SliceQuery query) {
    if (storeFeatures.hasMultiQuery()) {
        return executeRead(new Callable<Map<StaticBuffer, EntryList>>() {

            @Override
            public Map<StaticBuffer, EntryList> call() throws Exception {
                return cacheEnabled ? edgeStore.getSlice(keys, query, storeTx) : edgeStore.getSliceNoCache(keys, query, storeTx);
            }

            @Override
            public String toString() {
                return "MultiEdgeStoreQuery";
            }
        });
    } else {
        final Map<StaticBuffer, EntryList> results = new HashMap<>(keys.size());
        if (threadPool == null || keys.size() < MIN_TASKS_TO_PARALLELIZE) {
            for (StaticBuffer key : keys) {
                results.put(key, edgeStoreQuery(new KeySliceQuery(key, query)));
            }
        } else {
            final CountDownLatch doneSignal = new CountDownLatch(keys.size());
            final AtomicInteger failureCount = new AtomicInteger(0);
            EntryList[] resultArray = new EntryList[keys.size()];
            for (int i = 0; i < keys.size(); i++) {
                threadPool.execute(new SliceQueryRunner(new KeySliceQuery(keys.get(i), query), doneSignal, failureCount, resultArray, i));
            }
            try {
                doneSignal.await();
            } catch (InterruptedException e) {
                throw new JanusGraphException("Interrupted while waiting for multi-query to complete", e);
            }
            if (failureCount.get() > 0) {
                throw new JanusGraphException("Could not successfully complete multi-query. " + failureCount.get() + " individual queries failed.");
            }
            for (int i = 0; i < keys.size(); i++) {
                assert resultArray[i] != null;
                results.put(keys.get(i), resultArray[i]);
            }
        }
        return results;
    }
}
Also used : HashMap(java.util.HashMap) JanusGraphException(org.janusgraph.core.JanusGraphException) CountDownLatch(java.util.concurrent.CountDownLatch) TraversalInterruptedException(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalInterruptedException) TraversalInterruptedException(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalInterruptedException) JanusGraphException(org.janusgraph.core.JanusGraphException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) Map(java.util.Map) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)

Example 20 with KeySliceQuery

use of org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery in project janusgraph by JanusGraph.

the class ConsistentKeyLockerTest method recordLockGetSlice.

private void recordLockGetSlice(EntryList returnedEntries) throws BackendException {
    final KeySliceQuery ksq = new KeySliceQuery(defaultLockKey, LOCK_COL_START, LOCK_COL_END);
    expect(store.getSlice(eq(ksq), eq(defaultTx))).andReturn(returnedEntries);
}
Also used : KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)

Aggregations

KeySliceQuery (org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)35 Test (org.junit.jupiter.api.Test)18 Entry (org.janusgraph.diskstorage.Entry)16 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)15 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)14 ArrayList (java.util.ArrayList)13 EntryList (org.janusgraph.diskstorage.EntryList)13 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)12 HashMap (java.util.HashMap)8 BaseTransactionConfig (org.janusgraph.diskstorage.BaseTransactionConfig)8 BufferPageTest.makeEntry (org.janusgraph.diskstorage.inmemory.BufferPageTest.makeEntry)8 List (java.util.List)5 Map (java.util.Map)5 JanusGraphBaseStoreFeaturesTest (org.janusgraph.JanusGraphBaseStoreFeaturesTest)5 BackendException (org.janusgraph.diskstorage.BackendException)5 BufferPageTest.makeStaticBuffer (org.janusgraph.diskstorage.inmemory.BufferPageTest.makeStaticBuffer)5 KeyColumnValueStore (org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore)5 BackendOperation (org.janusgraph.diskstorage.util.BackendOperation)5 Instant (java.time.Instant)4 Random (java.util.Random)4