Search in sources :

Example 1 with Entry

use of com.thinkaurelius.titan.diskstorage.Entry in project titan by thinkaurelius.

the class KCVSCacheTest method testSmallCache.

@Test
public void testSmallCache() throws Exception {
    final int numKeys = 100, numCols = 10;
    final int repeats = 100, clearEvery = 20, numMulti = 10;
    //Assumed below
    assertTrue(numCols >= 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
        List<StaticBuffer> keys = new ArrayList<StaticBuffer>();
        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);
    List<StaticBuffer> keys = new ArrayList<StaticBuffer>();
    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
    List<Entry> dels = new ArrayList<Entry>(numCols / 2);
    for (int j = 1; j <= numCols; j = j + 2) dels.add(getEntry(j, j));
    cache.mutateEntries(key, KeyColumnValueStore.NO_ADDITIONS, dels, 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 : Entry(com.thinkaurelius.titan.diskstorage.Entry) StaticArrayEntry(com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry) ArrayList(java.util.ArrayList) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) EntryList(com.thinkaurelius.titan.diskstorage.EntryList) CacheTransaction(com.thinkaurelius.titan.diskstorage.keycolumnvalue.cache.CacheTransaction) Test(org.junit.Test)

Example 2 with Entry

use of com.thinkaurelius.titan.diskstorage.Entry in project titan by thinkaurelius.

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 timeIncr = 1L;
    final Instant timeStart = Instant.EPOCH;
    final Instant timeCutoff = timeStart.plusMillis(expiredCount * timeIncr);
    ImmutableList.Builder<Entry> locksBuilder = ImmutableList.builder();
    ImmutableList.Builder<Entry> delsBuilder = ImmutableList.builder();
    for (int i = 0; i < lockCount; i++) {
        final Instant ts = timeStart.plusMillis(timeIncr * i);
        Entry lock = StaticArrayEntry.of(codec.toLockCol(ts, defaultLockRid, TimestampProviders.MILLI), BufferUtil.getIntBuffer(0));
        if (ts.isBefore(timeCutoff)) {
            delsBuilder.add(lock);
        }
        locksBuilder.add(lock);
    }
    EntryList locks = StaticArrayEntryList.of(locksBuilder.build());
    EntryList dels = StaticArrayEntryList.of(delsBuilder.build());
    assertTrue(expiredCount == dels.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.<Entry>of()), eq(columnsOf(dels)), anyObject(StoreTransaction.class));
    ctrl.replay();
    del.run();
}
Also used : StandardLockCleanerRunnable(com.thinkaurelius.titan.diskstorage.locking.consistentkey.StandardLockCleanerRunnable) Entry(com.thinkaurelius.titan.diskstorage.Entry) ImmutableList(com.google.common.collect.ImmutableList) StoreTransaction(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction) Instant(java.time.Instant) EntryList(com.thinkaurelius.titan.diskstorage.EntryList) Test(org.junit.Test)

Example 3 with Entry

use of com.thinkaurelius.titan.diskstorage.Entry in project titan by thinkaurelius.

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.<Entry>of()), eq(ImmutableList.<StaticBuffer>of(expiredLockCol.getColumn())), anyObject(StoreTransaction.class));
    ctrl.replay();
    del.run();
}
Also used : StandardLockCleanerRunnable(com.thinkaurelius.titan.diskstorage.locking.consistentkey.StandardLockCleanerRunnable) Entry(com.thinkaurelius.titan.diskstorage.Entry) StoreTransaction(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction) Instant(java.time.Instant) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) EntryList(com.thinkaurelius.titan.diskstorage.EntryList) Test(org.junit.Test)

Example 4 with Entry

use of com.thinkaurelius.titan.diskstorage.Entry in project titan by thinkaurelius.

the class IndexSerializer method query.

/* ################################################
                Querying
    ################################################### */
public List<Object> query(final JointIndexQuery.Subquery query, final BackendTransaction tx) {
    IndexType index = query.getIndex();
    if (index.isCompositeIndex()) {
        MultiKeySliceQuery sq = query.getCompositeQuery();
        List<EntryList> rs = sq.execute(tx);
        List<Object> results = new ArrayList<Object>(rs.get(0).size());
        for (EntryList r : rs) {
            for (java.util.Iterator<Entry> iterator = r.reuseIterator(); iterator.hasNext(); ) {
                Entry entry = iterator.next();
                ReadBuffer entryValue = entry.asReadBuffer();
                entryValue.movePositionTo(entry.getValuePosition());
                switch(index.getElement()) {
                    case VERTEX:
                        results.add(VariableLong.readPositive(entryValue));
                        break;
                    default:
                        results.add(bytebuffer2RelationId(entryValue));
                }
            }
        }
        return results;
    } else {
        List<String> r = tx.indexQuery(((MixedIndexType) index).getBackingIndexName(), query.getMixedQuery());
        List<Object> result = new ArrayList<Object>(r.size());
        for (String id : r) result.add(string2ElementId(id));
        return result;
    }
}
Also used : MultiKeySliceQuery(com.thinkaurelius.titan.graphdb.query.graph.MultiKeySliceQuery) Entry(com.thinkaurelius.titan.diskstorage.Entry) StaticArrayEntry(com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry) java.util(java.util)

Example 5 with Entry

use of com.thinkaurelius.titan.diskstorage.Entry in project titan by thinkaurelius.

the class KCVSConfiguration method toMap.

private Map<String, Object> toMap() {
    Map<String, Object> entries = Maps.newHashMap();
    List<Entry> result = BackendOperation.execute(new BackendOperation.Transactional<List<Entry>>() {

        @Override
        public List<Entry> call(StoreTransaction txh) throws BackendException {
            return store.getSlice(new KeySliceQuery(rowKey, BufferUtil.zeroBuffer(1), BufferUtil.oneBuffer(128)), txh);
        }

        @Override
        public String toString() {
            return "setConfiguration";
        }
    }, txProvider, times, maxOperationWaitTime);
    for (Entry entry : result) {
        String key = staticBuffer2String(entry.getColumnAs(StaticBuffer.STATIC_FACTORY));
        Object value = staticBuffer2Object(entry.getValueAs(StaticBuffer.STATIC_FACTORY), Object.class);
        entries.put(key, value);
    }
    return entries;
}
Also used : Entry(com.thinkaurelius.titan.diskstorage.Entry) StaticArrayEntry(com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry) ArrayList(java.util.ArrayList) List(java.util.List) BackendOperation(com.thinkaurelius.titan.diskstorage.util.BackendOperation) BackendException(com.thinkaurelius.titan.diskstorage.BackendException)

Aggregations

Entry (com.thinkaurelius.titan.diskstorage.Entry)19 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)10 EntryList (com.thinkaurelius.titan.diskstorage.EntryList)5 StaticArrayEntry (com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry)5 ArrayList (java.util.ArrayList)5 ImmutableList (com.google.common.collect.ImmutableList)4 InternalRelationType (com.thinkaurelius.titan.graphdb.internal.InternalRelationType)4 Map (java.util.Map)4 StandardLockCleanerRunnable (com.thinkaurelius.titan.diskstorage.locking.consistentkey.StandardLockCleanerRunnable)3 Test (org.junit.Test)3 BiMap (com.google.common.collect.BiMap)2 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 BackendException (com.thinkaurelius.titan.diskstorage.BackendException)2 BackendTransaction (com.thinkaurelius.titan.diskstorage.BackendTransaction)2 KCVMutation (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KCVMutation)2 StoreTransaction (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction)2 BackendOperation (com.thinkaurelius.titan.diskstorage.util.BackendOperation)2 IndexSerializer (com.thinkaurelius.titan.graphdb.database.IndexSerializer)2 RelationTypeIndexWrapper (com.thinkaurelius.titan.graphdb.database.management.RelationTypeIndexWrapper)2