Search in sources :

Example 1 with KeyRangeQuery

use of org.janusgraph.diskstorage.keycolumnvalue.KeyRangeQuery 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 KeyRangeQuery

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

the class CQLStoreTest method testGetKeysWithoutOrderedScan.

@Test
@FeatureFlag(feature = JanusGraphFeature.UnorderedScan)
public void testGetKeysWithoutOrderedScan() throws BackendException, NoSuchFieldException, IllegalAccessException {
    // support unordered scan but not ordered scan
    Field field = StandardStoreFeatures.class.getDeclaredField("orderedScan");
    field.setAccessible(true);
    Field modifiersField = Field.class.getDeclaredField("modifiers");
    modifiersField.setAccessible(true);
    modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
    field.set(manager.getFeatures(), false);
    Exception ex = assertThrows(PermanentBackendException.class, () -> store.getKeys(new KeyRangeQuery(BufferUtil.getLongBuffer(1), BufferUtil.getLongBuffer(1000), BufferUtil.getLongBuffer(1), BufferUtil.getLongBuffer(1000)), tx));
    assertEquals("This operation is only allowed when the byteorderedpartitioner is used.", ex.getMessage());
    assertDoesNotThrow(() -> store.getKeys(new SliceQuery(BufferUtil.zeroBuffer(1), BufferUtil.oneBuffer(4)), tx));
}
Also used : Field(java.lang.reflect.Field) KeyRangeQuery(org.janusgraph.diskstorage.keycolumnvalue.KeyRangeQuery) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) KeyColumnValueStoreTest(org.janusgraph.diskstorage.KeyColumnValueStoreTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Example 3 with KeyRangeQuery

use of org.janusgraph.diskstorage.keycolumnvalue.KeyRangeQuery 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 KeyRangeQuery

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

the class KeyColumnValueStoreTest method testGetKeysWithKeyRange.

@Test
@FeatureFlag(feature = JanusGraphFeature.OrderedScan)
public void testGetKeysWithKeyRange(TestInfo testInfo) throws Exception {
    populateDBWith100Keys();
    tx.commit();
    tx = startTx();
    KeyIterator keyIterator = store.getKeys(new KeyRangeQuery(// key start
    KeyColumnValueStoreUtil.longToByteBuffer(10), // key end
    KeyColumnValueStoreUtil.longToByteBuffer(40), // column start
    new ReadArrayBuffer("b".getBytes()), new ReadArrayBuffer("c".getBytes())), tx);
    examineGetKeysResults(keyIterator, 10, 40);
}
Also used : KeyRangeQuery(org.janusgraph.diskstorage.keycolumnvalue.KeyRangeQuery) KeyIterator(org.janusgraph.diskstorage.keycolumnvalue.KeyIterator) ReadArrayBuffer(org.janusgraph.diskstorage.util.ReadArrayBuffer) Test(org.junit.jupiter.api.Test) JanusGraphBaseStoreFeaturesTest(org.janusgraph.JanusGraphBaseStoreFeaturesTest) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Example 5 with KeyRangeQuery

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

the class KeyColumnValueStoreTest method testGetKeysColumnSlicesOnLowerTriangular.

/**
 * Test {@code getKeys} with columns slice values chosen to trigger
 * potential fencepost bugs.
 * <p>
 * Description of data generated for and queried by this test:
 * <p>
 * Generate a sequence of keys as unsigned integers, starting at zero. Each
 * row has as many columns as the key value. The columns are generated in
 * the same way as the keys. This results in a sort of "lower triangular"
 * data space, with no values above the diagonal.
 *
 * @throws BackendException shouldn't happen
 * @throws IOException      shouldn't happen
 */
@Test
@FeatureFlag(feature = JanusGraphFeature.Scan)
public void testGetKeysColumnSlicesOnLowerTriangular() throws BackendException, IOException {
    // should be greater than or equal to 1
    final int offset = 10;
    // should be greater than or equal to 4
    final int size = 10;
    final int midpoint = size / 2 + offset;
    final int upper = offset + size;
    final int step = 1;
    loadLowerTriangularValues(size, offset);
    boolean executed = false;
    if (manager.getFeatures().hasUnorderedScan()) {
        final Collection<StaticBuffer> expected = new HashSet<>(size);
        for (int start = midpoint; start >= offset - step; start -= step) {
            for (int end = midpoint + 1; end <= upper + step; end += step) {
                Preconditions.checkArgument(start < end);
                // Set column bounds
                StaticBuffer startCol = BufferUtil.getIntBuffer(start);
                StaticBuffer endCol = BufferUtil.getIntBuffer(end);
                SliceQuery sq = new SliceQuery(startCol, endCol);
                // Compute expectation
                expected.clear();
                for (long l = Math.max(start, offset); l < upper; l++) {
                    expected.add(BufferUtil.getLongBuffer(l));
                }
                // Compute actual
                KeyIterator i = store.getKeys(sq, tx);
                Collection<StaticBuffer> actual = Sets.newHashSet(i);
                // Check
                log.debug("Checking bounds [{}, {}) (expect {} keys)", startCol, endCol, expected.size());
                assertEquals(expected, actual);
                i.close();
                executed = true;
            }
        }
    } else if (manager.getFeatures().hasOrderedScan()) {
        final Collection<StaticBuffer> expected = new ArrayList<>(size);
        for (int start = midpoint; start >= offset - step; start -= step) {
            for (int end = midpoint + 1; end <= upper + step; end += step) {
                Preconditions.checkArgument(start < end);
                // Set column bounds
                StaticBuffer startCol = BufferUtil.getIntBuffer(start);
                StaticBuffer endCol = BufferUtil.getIntBuffer(end);
                SliceQuery sq = new SliceQuery(startCol, endCol);
                // Set key bounds
                StaticBuffer keyStart = BufferUtil.getLongBuffer(start);
                StaticBuffer keyEnd = BufferUtil.getLongBuffer(end);
                KeyRangeQuery krq = new KeyRangeQuery(keyStart, keyEnd, sq);
                // Compute expectation
                expected.clear();
                for (long l = Math.max(start, offset); l < Math.min(upper, end); l++) {
                    expected.add(BufferUtil.getLongBuffer(l));
                }
                // Compute actual
                KeyIterator i = store.getKeys(krq, tx);
                Collection<StaticBuffer> actual = Lists.newArrayList(i);
                log.debug("Checking bounds key:[{}, {}) & col:[{}, {}) (expect {} keys)", keyStart, keyEnd, startCol, endCol, expected.size());
                assertEquals(expected, actual);
                i.close();
                executed = true;
            }
        }
    } else {
        throw new UnsupportedOperationException("Illegal store configuration: supportsScan()=true but supportsOrderedScan()=supportsUnorderedScan()=false");
    }
    Preconditions.checkArgument(executed);
}
Also used : KeyRangeQuery(org.janusgraph.diskstorage.keycolumnvalue.KeyRangeQuery) KeyIterator(org.janusgraph.diskstorage.keycolumnvalue.KeyIterator) Collection(java.util.Collection) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) JanusGraphBaseStoreFeaturesTest(org.janusgraph.JanusGraphBaseStoreFeaturesTest) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Aggregations

KeyRangeQuery (org.janusgraph.diskstorage.keycolumnvalue.KeyRangeQuery)6 FeatureFlag (org.janusgraph.testutil.FeatureFlag)5 Test (org.junit.jupiter.api.Test)5 KeyIterator (org.janusgraph.diskstorage.keycolumnvalue.KeyIterator)4 SliceQuery (org.janusgraph.diskstorage.keycolumnvalue.SliceQuery)4 JanusGraphBaseStoreFeaturesTest (org.janusgraph.JanusGraphBaseStoreFeaturesTest)3 Field (java.lang.reflect.Field)2 BackendException (org.janusgraph.diskstorage.BackendException)2 KeyColumnValueStoreTest (org.janusgraph.diskstorage.KeyColumnValueStoreTest)2 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)2 KeySliceQuery (org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 ReadArrayBuffer (org.janusgraph.diskstorage.util.ReadArrayBuffer)1 RecordIterator (org.janusgraph.diskstorage.util.RecordIterator)1