Search in sources :

Example 1 with KeyIterator

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

the class StandardJanusGraph method getVertexIDs.

public RecordIterator<Long> getVertexIDs(final BackendTransaction tx) {
    Preconditions.checkArgument(backend.getStoreFeatures().hasOrderedScan() || backend.getStoreFeatures().hasUnorderedScan(), "The configured storage backend does not support global graph operations - use Faunus instead");
    final KeyIterator keyIterator;
    if (backend.getStoreFeatures().hasUnorderedScan()) {
        keyIterator = tx.edgeStoreKeys(vertexExistenceQuery);
    } else {
        keyIterator = tx.edgeStoreKeys(new KeyRangeQuery(IDHandler.MIN_KEY, IDHandler.MAX_KEY, vertexExistenceQuery));
    }
    return new RecordIterator<Long>() {

        @Override
        public boolean hasNext() {
            return keyIterator.hasNext();
        }

        @Override
        public Long next() {
            return idManager.getKeyID(keyIterator.next());
        }

        @Override
        public void close() throws IOException {
            keyIterator.close();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Removal not supported");
        }
    };
}
Also used : RecordIterator(org.janusgraph.diskstorage.util.RecordIterator) KeyRangeQuery(org.janusgraph.diskstorage.keycolumnvalue.KeyRangeQuery) KeyIterator(org.janusgraph.diskstorage.keycolumnvalue.KeyIterator)

Example 2 with KeyIterator

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

the class JanusGraphIterativeBenchmark method testDataSequential.

@RepeatedTest(10)
public void testDataSequential() throws Exception {
    loadData(200000, 2);
    close();
    KeyColumnValueStoreManager manager = openStorageManager();
    KeyColumnValueStore store = manager.openDatabase(Backend.EDGESTORE_NAME);
    SliceQuery query = new SliceQuery(BufferUtil.zeroBuffer(8), BufferUtil.oneBuffer(8));
    query.setLimit(2);
    Stopwatch watch = Stopwatch.createStarted();
    StoreTransaction txh = manager.beginTransaction(StandardBaseTransactionConfig.of(TimestampProviders.MILLI));
    KeyIterator iterator = store.getKeys(query, txh);
    int numV = 0;
    while (iterator.hasNext()) {
        iterator.next();
        RecordIterator<Entry> entries = iterator.getEntries();
        assertEquals(2, Iterators.size(entries));
        numV++;
    }
    iterator.close();
    txh.commit();
    System.out.println("Time taken: " + watch.elapsed(TimeUnit.MILLISECONDS));
    System.out.println("Num Vertices: " + numV);
    store.close();
    manager.close();
}
Also used : Entry(org.janusgraph.diskstorage.Entry) KeyColumnValueStore(org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore) KeyIterator(org.janusgraph.diskstorage.keycolumnvalue.KeyIterator) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) KeyColumnValueStoreManager(org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStoreManager) Stopwatch(com.google.common.base.Stopwatch) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 3 with KeyIterator

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

the class KeyColumnValueStoreTest method testOrderedGetKeysRespectsKeyLimit.

/**
 * Verify that
 * {@link KeyColumnValueStore#getKeys(KeyRangeQuery, StoreTransaction)}
 * treats the lower key bound as inclusive and the upper key bound as
 * exclusive. Verify that keys less than the start and greater than or equal
 * to the end containing matching columns are not returned.
 *
 * @throws BackendException
 */
@Test
@FeatureFlag(feature = JanusGraphFeature.OrderedScan)
public void testOrderedGetKeysRespectsKeyLimit(TestInfo testInfo) throws BackendException {
    Preconditions.checkState(4 <= numKeys && 4 <= numColumns);
    final long minKey = KeyValueStoreUtil.idOffset + 1;
    final long maxKey = KeyValueStoreUtil.idOffset + numKeys - 2;
    final long expectedKeyCount = maxKey - minKey;
    String[][] values = generateValues();
    loadValues(values);
    final SliceQuery columnSlice = new SliceQuery(BufferUtil.zeroBuffer(8), BufferUtil.oneBuffer(8)).setLimit(1);
    KeyIterator keys;
    keys = store.getKeys(new KeyRangeQuery(BufferUtil.getLongBuffer(minKey), BufferUtil.getLongBuffer(maxKey), columnSlice), tx);
    assertEquals(expectedKeyCount, KeyValueStoreUtil.count(keys));
    clopen();
    keys = store.getKeys(new KeyRangeQuery(BufferUtil.getLongBuffer(minKey), BufferUtil.getLongBuffer(maxKey), columnSlice), tx);
    assertEquals(expectedKeyCount, KeyValueStoreUtil.count(keys));
}
Also used : KeyRangeQuery(org.janusgraph.diskstorage.keycolumnvalue.KeyRangeQuery) KeyIterator(org.janusgraph.diskstorage.keycolumnvalue.KeyIterator) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) Test(org.junit.jupiter.api.Test) JanusGraphBaseStoreFeaturesTest(org.janusgraph.JanusGraphBaseStoreFeaturesTest) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Example 4 with KeyIterator

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

the class KeyColumnValueStoreTest method testGetKeysWithSliceQuery.

@Test
@FeatureFlag(feature = JanusGraphFeature.UnorderedScan)
public void testGetKeysWithSliceQuery(TestInfo testInfo) throws Exception {
    populateDBWith100Keys();
    tx.commit();
    tx = startTx();
    KeyIterator keyIterator = store.getKeys(new SliceQuery(new ReadArrayBuffer("b".getBytes()), new ReadArrayBuffer("c".getBytes())), tx);
    examineGetKeysResults(keyIterator, 0, 100);
}
Also used : KeyIterator(org.janusgraph.diskstorage.keycolumnvalue.KeyIterator) ReadArrayBuffer(org.janusgraph.diskstorage.util.ReadArrayBuffer) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) Test(org.junit.jupiter.api.Test) JanusGraphBaseStoreFeaturesTest(org.janusgraph.JanusGraphBaseStoreFeaturesTest) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Example 5 with KeyIterator

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

the class KeyColumnValueStoreTest method scanTest.

/**
 * Loads a block of data where keys are longs on [idOffset, idOffset +
 * numKeys) and the columns are longs on [idOffset, idOffset + numColumns).
 * {@code idOffset} is {@link KeyValueStoreUtil#idOffset}. Note that
 * identical columns appear on every key. The loaded values are randomly
 * generated strings converted to bytes.
 * <p>
 * Calls the store's supported {@code getKeys} method depending on whether
 * it supports ordered or unordered scan. This logic is delegated to
 * {@link KCVSUtil#getKeys(KeyColumnValueStore, StoreFeatures, int, int, StoreTransaction)}
 * . That method uses all-zero and all-one buffers for the key and column
 * limits and retrieves every key.
 * <p>
 * This method does nothing and returns immediately if the store supports no
 * scans.
 */
@Test
@FeatureFlag(feature = JanusGraphFeature.Scan)
public void scanTest() throws BackendException {
    String[][] values = generateValues();
    loadValues(values);
    KeyIterator iterator0 = KCVSUtil.getKeys(store, storeFeatures(), 8, 4, tx);
    verifyIterator(iterator0, numKeys);
    clopen();
    KeyIterator iterator1 = KCVSUtil.getKeys(store, storeFeatures(), 8, 4, tx);
    KeyIterator iterator2 = KCVSUtil.getKeys(store, storeFeatures(), 8, 4, tx);
    // The idea is to open an iterator without using it
    // to make sure that closing a transaction will clean it up.
    // (important for BerkeleyJE where leaving cursors open causes exceptions)
    @SuppressWarnings("unused") KeyIterator iterator3 = KCVSUtil.getKeys(store, storeFeatures(), 8, 4, tx);
    verifyIterator(iterator1, numKeys);
    verifyIterator(iterator2, numKeys);
}
Also used : KeyIterator(org.janusgraph.diskstorage.keycolumnvalue.KeyIterator) Test(org.junit.jupiter.api.Test) JanusGraphBaseStoreFeaturesTest(org.janusgraph.JanusGraphBaseStoreFeaturesTest) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Aggregations

KeyIterator (org.janusgraph.diskstorage.keycolumnvalue.KeyIterator)7 JanusGraphBaseStoreFeaturesTest (org.janusgraph.JanusGraphBaseStoreFeaturesTest)5 FeatureFlag (org.janusgraph.testutil.FeatureFlag)5 Test (org.junit.jupiter.api.Test)5 KeyRangeQuery (org.janusgraph.diskstorage.keycolumnvalue.KeyRangeQuery)4 SliceQuery (org.janusgraph.diskstorage.keycolumnvalue.SliceQuery)4 KeySliceQuery (org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)3 ReadArrayBuffer (org.janusgraph.diskstorage.util.ReadArrayBuffer)2 Stopwatch (com.google.common.base.Stopwatch)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Entry (org.janusgraph.diskstorage.Entry)1 KeyColumnValueStore (org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore)1 KeyColumnValueStoreManager (org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStoreManager)1 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)1 RecordIterator (org.janusgraph.diskstorage.util.RecordIterator)1 RepeatedTest (org.junit.jupiter.api.RepeatedTest)1