Search in sources :

Example 26 with KeySliceQuery

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

the class KeyColumnValueStoreTest method compareStores.

// @Test
public void compareStores() throws BackendException {
    final int keys = 1000, columns = 2000;
    final boolean normalMode = true;
    final String[][] values = new String[keys * 2][];
    for (int i = 0; i < keys * 2; i++) {
        if (i % 2 == 0) {
            if (normalMode) {
                values[i] = new String[columns + 4];
            } else {
                values[i] = new String[4];
            }
        } else {
            if (normalMode) {
                values[i] = new String[0];
            } else {
                values[i] = new String[columns];
            }
        }
        for (int j = 0; j < values[i].length; j++) {
            values[i][j] = RandomGenerator.randomString(30, 35);
        }
    }
    log.debug("Loading values: " + keys + "x" + columns);
    long time = System.currentTimeMillis();
    loadValues(values);
    clopen();
    System.out.println("Loading time (ms): " + (System.currentTimeMillis() - time));
    // print(values);
    Random r = new Random();
    int trials = 500;
    log.debug("Reading values: " + trials + " trials");
    for (int i = 0; i < 10; i++) {
        time = System.currentTimeMillis();
        for (int t = 0; t < trials; t++) {
            int key = r.nextInt(keys) * 2;
            assertEquals(2, store.getSlice(new KeySliceQuery(KeyValueStoreUtil.getBuffer(key), KeyValueStoreUtil.getBuffer(2002), KeyValueStoreUtil.getBuffer(2004)), tx).size());
        }
        System.out.println("Reading time (ms): " + (System.currentTimeMillis() - time));
    }
}
Also used : Random(java.util.Random) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)

Example 27 with KeySliceQuery

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

the class KeyColumnValueStoreTest method storeAndRetrievePerformance.

@Test
public void storeAndRetrievePerformance() throws BackendException {
    int multiplier = 4;
    int keys = 50 * multiplier, columns = 200;
    String[][] values = KeyValueStoreUtil.generateData(keys, columns);
    log.debug("Loading values: " + keys + "x" + columns);
    long time = System.currentTimeMillis();
    loadValues(values);
    clopen();
    System.out.println("Loading time (ms): " + (System.currentTimeMillis() - time));
    // print(values);
    Random r = new Random();
    int trials = 500 * multiplier;
    int delta = 10;
    log.debug("Reading values: " + trials + " trials");
    for (int i = 0; i < 1; i++) {
        time = System.currentTimeMillis();
        for (int t = 0; t < trials; t++) {
            int key = r.nextInt(keys);
            int start = r.nextInt(columns - delta);
            store.getSlice(new KeySliceQuery(KeyValueStoreUtil.getBuffer(key), KeyValueStoreUtil.getBuffer(start), KeyValueStoreUtil.getBuffer(start + delta)), tx);
        }
        // multiQuery version
        // List<StaticBuffer> keyList = new ArrayList<StaticBuffer>();
        // for (int t = 0; t < trials; t++) keyList.add(KeyValueStoreUtil.getBuffer(r.nextInt(keys)));
        // int start = r.nextInt(columns - delta);
        // store.getSlice(keyList, new SliceQuery(KeyValueStoreUtil.getBuffer(start), KeyValueStoreUtil.getBuffer(start + delta)), tx);
        System.out.println("Reading time (ms): " + (System.currentTimeMillis() - time));
    }
}
Also used : Random(java.util.Random) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) Test(org.junit.jupiter.api.Test) JanusGraphBaseStoreFeaturesTest(org.janusgraph.JanusGraphBaseStoreFeaturesTest)

Example 28 with KeySliceQuery

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

the class KeyColumnValueStoreTest method getSliceRespectsAllBoundsInclusionArguments.

@Test
public void getSliceRespectsAllBoundsInclusionArguments() throws Exception {
    // Test case where endColumn=startColumn+1
    StaticBuffer key = KeyColumnValueStoreUtil.longToByteBuffer(0);
    StaticBuffer columnBeforeStart = KeyColumnValueStoreUtil.longToByteBuffer(776);
    StaticBuffer columnStart = KeyColumnValueStoreUtil.longToByteBuffer(777);
    StaticBuffer columnEnd = KeyColumnValueStoreUtil.longToByteBuffer(778);
    StaticBuffer columnAfterEnd = KeyColumnValueStoreUtil.longToByteBuffer(779);
    // First insert four test Entries
    List<Entry> entries = Arrays.asList(StaticArrayEntry.of(columnBeforeStart, columnBeforeStart), StaticArrayEntry.of(columnStart, columnStart), StaticArrayEntry.of(columnEnd, columnEnd), StaticArrayEntry.of(columnAfterEnd, columnAfterEnd));
    store.mutate(key, entries, KeyColumnValueStore.NO_DELETIONS, tx);
    tx.commit();
    // getSlice() with only start inclusive
    tx = startTx();
    List<Entry> result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd), tx);
    assertEquals(1, result.size());
    assertEquals(777, KeyColumnValueStoreUtil.bufferToLong(result.get(0).getColumn()));
}
Also used : StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) Test(org.junit.jupiter.api.Test) JanusGraphBaseStoreFeaturesTest(org.janusgraph.JanusGraphBaseStoreFeaturesTest)

Example 29 with KeySliceQuery

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

the class KeyColumnValueStoreTest method getSliceRespectsColumnLimit.

@Test
public void getSliceRespectsColumnLimit() throws Exception {
    StaticBuffer key = KeyColumnValueStoreUtil.longToByteBuffer(0);
    final int cols = 1024;
    final List<Entry> entries = new LinkedList<>();
    for (int i = 0; i < cols; i++) {
        StaticBuffer col = KeyColumnValueStoreUtil.longToByteBuffer(i);
        entries.add(StaticArrayEntry.of(col, col));
    }
    store.mutate(key, entries, KeyColumnValueStore.NO_DELETIONS, tx);
    tx.commit();
    tx = startTx();
    /*
         * When limit is greater than or equal to the matching column count ,
         * all matching columns must be returned.
         */
    StaticBuffer columnStart = KeyColumnValueStoreUtil.longToByteBuffer(0);
    StaticBuffer columnEnd = KeyColumnValueStoreUtil.longToByteBuffer(cols);
    List<Entry> result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(cols), tx);
    assertEquals(cols, result.size());
    for (int i = 0; i < result.size(); i++) {
        Entry src = entries.get(i);
        Entry dst = result.get(i);
        if (!src.equals(dst)) {
            int x = 1;
        }
    }
    assertEquals(entries, result);
    result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(cols + 10), tx);
    assertEquals(cols, result.size());
    assertEquals(entries, result);
    /*
         * When limit is less the matching column count, the columns up to the
         * limit (ordered byte-wise) must be returned.
         */
    result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(cols - 1), tx);
    assertEquals(cols - 1, result.size());
    entries.remove(entries.size() - 1);
    assertEquals(entries, result);
    result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(1), tx);
    assertEquals(1, result.size());
    final List<Entry> firstEntrySingleton = Collections.singletonList(entries.get(0));
    assertEquals(firstEntrySingleton, result);
}
Also used : StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) LinkedList(java.util.LinkedList) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) Test(org.junit.jupiter.api.Test) JanusGraphBaseStoreFeaturesTest(org.janusgraph.JanusGraphBaseStoreFeaturesTest)

Example 30 with KeySliceQuery

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

the class KeyColumnValueStoreTest method testTtl.

@Tag(TestCategory.BRITTLE_TESTS)
@Test
@FeatureFlag(feature = JanusGraphFeature.CellTtl)
public void testTtl() throws Exception {
    StaticBuffer key = KeyColumnValueStoreUtil.longToByteBuffer(0);
    int[] ttls = new int[] { 0, 1, 2 };
    final List<Entry> additions = new LinkedList<>();
    for (int i = 0; i < ttls.length; i++) {
        StaticBuffer col = KeyColumnValueStoreUtil.longToByteBuffer(i);
        StaticArrayEntry entry = (StaticArrayEntry) StaticArrayEntry.of(col, col);
        entry.setMetaData(EntryMetaData.TTL, ttls[i]);
        additions.add(entry);
    }
    store.mutate(key, additions, KeyColumnValueStore.NO_DELETIONS, tx);
    tx.commit();
    // commitTime starts just after the commit, so we won't check for expiration too early
    long commitTime = System.currentTimeMillis();
    tx = startTx();
    StaticBuffer columnStart = KeyColumnValueStoreUtil.longToByteBuffer(0);
    StaticBuffer columnEnd = KeyColumnValueStoreUtil.longToByteBuffer(ttls.length);
    List<Entry> result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(ttls.length), tx);
    assertEquals(ttls.length, result.size());
    // wait for one cell to expire
    Thread.sleep(commitTime + 1001 - System.currentTimeMillis());
    // cells immediately expire upon TTL, even before rollback()
    result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(ttls.length), tx);
    assertEquals(ttls.length - 1, result.size());
    tx.rollback();
    result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(ttls.length), tx);
    assertEquals(ttls.length - 1, result.size());
    Thread.sleep(commitTime + 2001 - System.currentTimeMillis());
    tx.rollback();
    result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(ttls.length), tx);
    assertEquals(ttls.length - 2, result.size());
    // cell 0 doesn't expire due to TTL of 0 (infinite)
    Thread.sleep(commitTime + 4001 - System.currentTimeMillis());
    tx.rollback();
    result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(ttls.length), tx);
    assertEquals(ttls.length - 2, result.size());
}
Also used : StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) LinkedList(java.util.LinkedList) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) Test(org.junit.jupiter.api.Test) JanusGraphBaseStoreFeaturesTest(org.janusgraph.JanusGraphBaseStoreFeaturesTest) FeatureFlag(org.janusgraph.testutil.FeatureFlag) Tag(org.junit.jupiter.api.Tag)

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