Search in sources :

Example 6 with KeySliceQuery

use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery in project titan by thinkaurelius.

the class ExpirationStoreCache method multiQuery.

@Override
public List<List<Entry>> multiQuery(List<StaticBuffer> keys, SliceQuery query, BackendTransaction tx) {
    List<Entry>[] results = (List<Entry>[]) new List[keys.size()];
    List<StaticBuffer> remainingKeys = new ArrayList<StaticBuffer>(keys.size());
    KeySliceQuery[] ksqs = new KeySliceQuery[keys.size()];
    for (int i = 0; i < keys.size(); i++) {
        StaticBuffer key = keys.get(i);
        ksqs[i] = new KeySliceQuery(key, query);
        List<Entry> result = null;
        if (!isExpired(ksqs[i]))
            result = cache.getIfPresent(ksqs[i]);
        else
            ksqs[i] = null;
        if (result != null)
            results[i] = result;
        else
            remainingKeys.add(key);
    }
    List<List<Entry>> subresults = tx.edgeStoreMultiQuery(remainingKeys, query);
    int pos = 0;
    for (int i = 0; i < results.length; i++) {
        if (results[i] != null)
            continue;
        assert pos < subresults.size();
        List<Entry> subresult = subresults.get(pos);
        assert subresult != null;
        results[i] = subresult;
        if (ksqs[i] != null)
            cache.put(ksqs[i], subresult);
        pos++;
    }
    assert pos == subresults.size();
    return Arrays.asList(results);
}
Also used : Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) KeySliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)

Example 7 with KeySliceQuery

use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery in project titan by thinkaurelius.

the class ConsistentKeyLockerTest method recordExceptionalLockGetSlice.

private void recordExceptionalLockGetSlice(Throwable t) throws StorageException {
    final StaticBuffer lower = ByteBufferUtil.zeroBuffer(9);
    final StaticBuffer upper = ByteBufferUtil.oneBuffer(9);
    final KeySliceQuery ksq = new KeySliceQuery(defaultLockKey, lower, upper);
    expect(store.getSlice(eq(ksq), eq(defaultTx))).andThrow(t);
}
Also used : StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) KeySliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)

Example 8 with KeySliceQuery

use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery in project titan by thinkaurelius.

the class StandardLockCleanerRunnable method runWithExceptions.

private void runWithExceptions() throws BackendException {
    StaticBuffer lockKey = serializer.toLockKey(target.getKey(), target.getColumn());
    // TODO reduce LOCK_COL_END based on cutoff
    List<Entry> locks = store.getSlice(new KeySliceQuery(lockKey, LOCK_COL_START, LOCK_COL_END), tx);
    ImmutableList.Builder<StaticBuffer> b = ImmutableList.builder();
    for (Entry lc : locks) {
        TimestampRid tr = serializer.fromLockColumn(lc.getColumn(), times);
        if (tr.getTimestamp().isBefore(cutoff)) {
            log.info("Deleting expired lock on {} by rid {} with timestamp {} (before or at cutoff {})", new Object[] { target, tr.getRid(), tr.getTimestamp(), cutoff });
            b.add(lc.getColumn());
        } else {
            log.debug("Ignoring lock on {} by rid {} with timestamp {} (timestamp is after cutoff {})", new Object[] { target, tr.getRid(), tr.getTimestamp(), cutoff });
        }
    }
    List<StaticBuffer> dels = b.build();
    if (!dels.isEmpty()) {
        store.mutate(lockKey, ImmutableList.<Entry>of(), dels, tx);
        log.info("Deleted {} expired locks (before or at cutoff {})", dels.size(), cutoff);
    }
}
Also used : Entry(com.thinkaurelius.titan.diskstorage.Entry) ImmutableList(com.google.common.collect.ImmutableList) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) KeySliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)

Example 9 with KeySliceQuery

use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery in project titan by thinkaurelius.

the class ConsistentKeyIDAuthority method getCurrentID.

private long getCurrentID(final StaticBuffer partitionKey) throws BackendException {
    List<Entry> blocks = BackendOperation.execute(new BackendOperation.Transactional<List<Entry>>() {

        @Override
        public List<Entry> call(StoreTransaction txh) throws BackendException {
            return idStore.getSlice(new KeySliceQuery(partitionKey, LOWER_SLICE, UPPER_SLICE).setLimit(5), txh);
        }
    }, this, times);
    if (blocks == null)
        throw new TemporaryBackendException("Could not read from storage");
    long latest = BASE_ID;
    for (Entry e : blocks) {
        long counterVal = getBlockValue(e);
        if (latest < counterVal) {
            latest = counterVal;
        }
    }
    return latest;
}
Also used : StoreTransaction(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction) ArrayList(java.util.ArrayList) List(java.util.List) KeySliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)

Example 10 with KeySliceQuery

use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery in project titan by thinkaurelius.

the class ExpirationCacheTest method testGracePeriod.

private void testGracePeriod(Duration graceWait) throws Exception {
    final int minCleanupTriggerCalls = 5;
    final int numKeys = 100, numCols = 10;
    loadStore(numKeys, numCols);
    //Replace cache with proper times
    cache = getCache(store, Duration.ofDays(200), graceWait);
    StaticBuffer key = BufferUtil.getIntBuffer(81);
    List<StaticBuffer> keys = new ArrayList<StaticBuffer>();
    keys.add(key);
    keys.add(BufferUtil.getIntBuffer(37));
    keys.add(BufferUtil.getIntBuffer(2));
    SliceQuery query = getQuery(2, 8);
    verifyResults(key, keys, query, 6);
    //If we modify through cache store...
    CacheTransaction tx = getCacheTx();
    cache.mutateEntries(key, KeyColumnValueStore.NO_ADDITIONS, Lists.newArrayList(getEntry(4, 4)), tx);
    tx.commit();
    Instant utime = times.getTime();
    store.resetCounter();
    //...invalidation should happen and the result set is updated immediately
    verifyResults(key, keys, query, 5);
    assertEquals(2, store.getSliceCalls());
    //however, the key is expired and hence repeated calls need to go through to the store
    verifyResults(key, keys, query, 5);
    assertEquals(4, store.getSliceCalls());
    //however, when we sleep past the grace wait time and trigger a cleanup...
    times.sleepPast(utime.plus(graceWait));
    for (int t = 0; t < minCleanupTriggerCalls; t++) {
        assertEquals(5, cache.getSlice(new KeySliceQuery(key, query), tx).size());
        times.sleepFor(Duration.ofMillis(5));
    }
    //...the cache should cache results again
    store.resetCounter();
    verifyResults(key, keys, query, 5);
    assertEquals(0, store.getSliceCalls());
    verifyResults(key, keys, query, 5);
    assertEquals(0, store.getSliceCalls());
}
Also used : Instant(java.time.Instant) ArrayList(java.util.ArrayList) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) CacheTransaction(com.thinkaurelius.titan.diskstorage.keycolumnvalue.cache.CacheTransaction) KeySliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery) SliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery) KeySliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)

Aggregations

KeySliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)13 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)6 ArrayList (java.util.ArrayList)4 EntryList (com.thinkaurelius.titan.diskstorage.EntryList)2 Entry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry)2 StoreTransaction (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction)2 CacheTransaction (com.thinkaurelius.titan.diskstorage.keycolumnvalue.cache.CacheTransaction)2 KeyColumn (com.thinkaurelius.titan.diskstorage.util.KeyColumn)2 StaticArrayEntry (com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry)2 List (java.util.List)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Entry (com.thinkaurelius.titan.diskstorage.Entry)1 KCVMutation (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KCVMutation)1 SliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)1 StaticBufferEntry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry)1 TemporaryLockingException (com.thinkaurelius.titan.diskstorage.locking.TemporaryLockingException)1 IDPoolExhaustedException (com.thinkaurelius.titan.graphdb.database.idassigner.IDPoolExhaustedException)1 InternalType (com.thinkaurelius.titan.graphdb.internal.InternalType)1