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");
}
};
}
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();
}
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));
}
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);
}
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);
}
Aggregations