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);
}
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);
}
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);
}
}
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;
}
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());
}
Aggregations