Search in sources :

Example 1 with EntryList

use of org.janusgraph.diskstorage.EntryList in project janusgraph by JanusGraph.

the class LockCleanerRunnableTest method testDeleteSingleLock.

/**
 * Simplest case test of the lock cleaner.
 */
@Test
public void testDeleteSingleLock() throws BackendException {
    Instant now = Instant.ofEpochMilli(1L);
    Entry expiredLockCol = StaticArrayEntry.of(codec.toLockCol(now, defaultLockRid, TimestampProviders.MILLI), BufferUtil.getIntBuffer(0));
    EntryList expiredSingleton = StaticArrayEntryList.of(expiredLockCol);
    now = now.plusMillis(1);
    del = new StandardLockCleanerRunnable(store, kc, tx, codec, now, TimestampProviders.MILLI);
    expect(store.getSlice(eq(ksq), eq(tx))).andReturn(expiredSingleton);
    store.mutate(eq(key), eq(ImmutableList.of()), eq(ImmutableList.of(expiredLockCol.getColumn())), anyObject(StoreTransaction.class));
    ctrl.replay();
    del.run();
}
Also used : StandardLockCleanerRunnable(org.janusgraph.diskstorage.locking.consistentkey.StandardLockCleanerRunnable) Entry(org.janusgraph.diskstorage.Entry) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) Instant(java.time.Instant) EntryList(org.janusgraph.diskstorage.EntryList) Test(org.junit.Test)

Example 2 with EntryList

use of org.janusgraph.diskstorage.EntryList in project janusgraph by JanusGraph.

the class LockCleanerRunnableTest method testDeletionWithExpiredAndValidLocks.

/**
 * Test the cleaner against a set of locks where some locks have timestamps
 * before the cutoff and others have timestamps after the cutoff. One lock
 * has a timestamp equal to the cutoff.
 */
@Test
public void testDeletionWithExpiredAndValidLocks() throws BackendException {
    final int lockCount = 10;
    final int expiredCount = 3;
    assertTrue(expiredCount + 2 <= lockCount);
    final long timeIncremement = 1L;
    final Instant timeStart = Instant.EPOCH;
    final Instant timeCutoff = timeStart.plusMillis(expiredCount * timeIncremement);
    ImmutableList.Builder<Entry> locksBuilder = ImmutableList.builder();
    ImmutableList.Builder<Entry> deletionBuilder = ImmutableList.builder();
    for (int i = 0; i < lockCount; i++) {
        final Instant ts = timeStart.plusMillis(timeIncremement * i);
        Entry lock = StaticArrayEntry.of(codec.toLockCol(ts, defaultLockRid, TimestampProviders.MILLI), BufferUtil.getIntBuffer(0));
        if (ts.isBefore(timeCutoff)) {
            deletionBuilder.add(lock);
        }
        locksBuilder.add(lock);
    }
    EntryList locks = StaticArrayEntryList.of(locksBuilder.build());
    EntryList deletions = StaticArrayEntryList.of(deletionBuilder.build());
    assertTrue(expiredCount == deletions.size());
    del = new StandardLockCleanerRunnable(store, kc, tx, codec, timeCutoff, TimestampProviders.MILLI);
    expect(store.getSlice(eq(ksq), eq(tx))).andReturn(locks);
    store.mutate(eq(key), eq(ImmutableList.of()), eq(columnsOf(deletions)), anyObject(StoreTransaction.class));
    ctrl.replay();
    del.run();
}
Also used : StandardLockCleanerRunnable(org.janusgraph.diskstorage.locking.consistentkey.StandardLockCleanerRunnable) Entry(org.janusgraph.diskstorage.Entry) ImmutableList(com.google.common.collect.ImmutableList) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) Instant(java.time.Instant) EntryList(org.janusgraph.diskstorage.EntryList) Test(org.junit.Test)

Example 3 with EntryList

use of org.janusgraph.diskstorage.EntryList in project janusgraph by JanusGraph.

the class KCVSCacheTest method testSmallCache.

@Test
public void testSmallCache() throws Exception {
    // numCols must be greater than or equal to 10 as it is assummed below
    final int numKeys = 100, numCols = 10;
    final int repeats = 100, clearEvery = 20, numMulti = 10;
    loadStore(numKeys, numCols);
    // Repeatedly read from cache and clear in between
    int calls = 0;
    assertEquals(calls, store.getSliceCalls());
    for (int t = 0; t < repeats; t++) {
        if (t % clearEvery == 0) {
            cache.clearCache();
            calls += numKeys * 2 + 1;
        }
        CacheTransaction tx = getCacheTx();
        for (int i = 1; i <= numKeys; i++) {
            assertEquals(10, cache.getSlice(getQuery(i, 0, numCols + 1).setLimit(10), tx).size());
            assertEquals(3, cache.getSlice(getQuery(i, 2, 5), tx).size());
        }
        // Multi-query
        final List<StaticBuffer> keys = new ArrayList<>();
        for (int i = 10; i < 10 + numMulti; i++) keys.add(BufferUtil.getIntBuffer(i));
        Map<StaticBuffer, EntryList> result = cache.getSlice(keys, getQuery(4, 9), tx);
        assertEquals(keys.size(), result.size());
        for (StaticBuffer key : keys) assertTrue(result.containsKey(key));
        for (EntryList r : result.values()) {
            assertEquals(5, r.size());
        }
        tx.commit();
        assertEquals(calls, store.getSliceCalls());
    }
    store.resetCounter();
    // Check invalidation
    StaticBuffer key = BufferUtil.getIntBuffer(23);
    final List<StaticBuffer> keys = new ArrayList<>();
    keys.add(key);
    keys.add(BufferUtil.getIntBuffer(12));
    keys.add(BufferUtil.getIntBuffer(5));
    // Read
    CacheTransaction tx = getCacheTx();
    assertEquals(numCols, cache.getSlice(new KeySliceQuery(key, getQuery(0, numCols + 1)), tx).size());
    Map<StaticBuffer, EntryList> result = cache.getSlice(keys, getQuery(2, 8), tx);
    assertEquals(keys.size(), result.size());
    assertEquals(6, result.get(key).size());
    // Update
    final List<Entry> deletions = new ArrayList<>(numCols / 2);
    for (int j = 1; j <= numCols; j = j + 2) deletions.add(getEntry(j, j));
    cache.mutateEntries(key, KeyColumnValueStore.NO_ADDITIONS, deletions, tx);
    tx.commit();
    assertEquals(2, store.getSliceCalls());
    // Ensure updates are correctly read
    tx = getCacheTx();
    assertEquals(numCols / 2, cache.getSlice(new KeySliceQuery(key, getQuery(0, numCols + 1)), tx).size());
    result = cache.getSlice(keys, getQuery(2, 8), tx);
    assertEquals(keys.size(), result.size());
    assertEquals(3, result.get(key).size());
    tx.commit();
    assertEquals(4, store.getSliceCalls());
}
Also used : StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Entry(org.janusgraph.diskstorage.Entry) ArrayList(java.util.ArrayList) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) EntryList(org.janusgraph.diskstorage.EntryList) CacheTransaction(org.janusgraph.diskstorage.keycolumnvalue.cache.CacheTransaction) Test(org.junit.Test)

Example 4 with EntryList

use of org.janusgraph.diskstorage.EntryList in project janusgraph by JanusGraph.

the class HadoopScanMapper method map.

@Override
protected void map(StaticBuffer key, Iterable<Entry> values, Context context) throws IOException, InterruptedException {
    EntryArrayList al = EntryArrayList.of(values);
    // KeyFilter check
    if (!keyFilter.test(key)) {
        log.debug("Skipping key {} based on KeyFilter", key);
        return;
    }
    // InitialQuery check (at least one match is required or else the key is ignored)
    EntryList initialQueryMatches = findEntriesMatchingQuery(initialQuery, al);
    if (0 == initialQueryMatches.size()) {
        log.debug("Skipping key {} based on InitialQuery ({}) match failure", key, initialQuery);
        return;
    }
    // Both conditions (KeyFilter && InitialQuery) for invoking process are satisfied
    // Create an entries parameter to be passed into the process method
    Map<SliceQuery, EntryList> matches = new HashMap<>();
    matches.put(initialQuery, initialQueryMatches);
    // Find matches (if any are present) for subsequent queries
    for (SliceQuery sq : subsequentQueries) {
        matches.put(sq, findEntriesMatchingQuery(sq, al));
    }
    // Process
    job.process(key, matches, metrics);
}
Also used : EntryArrayList(org.janusgraph.diskstorage.util.EntryArrayList) EntryList(org.janusgraph.diskstorage.EntryList) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery)

Example 5 with EntryList

use of org.janusgraph.diskstorage.EntryList in project janusgraph by JanusGraph.

the class VertexJobConverter method process.

@Override
public void process(StaticBuffer key, Map<SliceQuery, EntryList> entries, ScanMetrics metrics) {
    long vertexId = getVertexId(key);
    assert entries.get(VERTEX_EXISTS_QUERY) != null;
    if (isGhostVertex(vertexId, entries.get(VERTEX_EXISTS_QUERY))) {
        metrics.incrementCustom(GHOST_VERTEX_COUNT);
        return;
    }
    JanusGraphVertex vertex = tx.getInternalVertex(vertexId);
    Preconditions.checkArgument(vertex instanceof PreloadedVertex, "The bounding transaction is not configured correctly");
    PreloadedVertex v = (PreloadedVertex) vertex;
    v.setAccessCheck(PreloadedVertex.OPENSTAR_CHECK);
    for (Map.Entry<SliceQuery, EntryList> entry : entries.entrySet()) {
        SliceQuery sq = entry.getKey();
        if (sq.equals(VERTEX_EXISTS_QUERY))
            continue;
        EntryList entryList = entry.getValue();
        if (entryList.size() >= sq.getLimit())
            metrics.incrementCustom(TRUNCATED_ENTRY_LISTS);
        v.addToQueryCache(sq.updateLimit(Query.NO_LIMIT), entryList);
    }
    job.process(v, metrics);
}
Also used : PreloadedVertex(org.janusgraph.graphdb.vertices.PreloadedVertex) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) EntryList(org.janusgraph.diskstorage.EntryList) Map(java.util.Map) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery)

Aggregations

EntryList (org.janusgraph.diskstorage.EntryList)18 Map (java.util.Map)4 Entry (org.janusgraph.diskstorage.Entry)4 Test (org.junit.Test)4 Instant (java.time.Instant)3 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)3 SliceQuery (org.janusgraph.diskstorage.keycolumnvalue.SliceQuery)3 StandardLockCleanerRunnable (org.janusgraph.diskstorage.locking.consistentkey.StandardLockCleanerRunnable)3 LongArrayList (com.carrotsearch.hppc.LongArrayList)2 ArrayList (java.util.ArrayList)2 NonBlockingHashMapLong (org.cliffc.high_scale_lib.NonBlockingHashMapLong)2 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)2 KeySliceQuery (org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)2 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)2 CacheTransaction (org.janusgraph.diskstorage.keycolumnvalue.cache.CacheTransaction)2 CacheVertex (org.janusgraph.graphdb.vertices.CacheVertex)2 PreloadedVertex (org.janusgraph.graphdb.vertices.PreloadedVertex)2 ImmutableList (com.google.common.collect.ImmutableList)1 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)1 Column (com.netflix.astyanax.model.Column)1