use of org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery in project janusgraph by JanusGraph.
the class KeyColumnValueStoreTest method testStoreTTL.
@Test
public void testStoreTTL() throws Exception {
KeyColumnValueStoreManager storeManager = manager;
// @see TTLKCVSManager
if (storeManager.getFeatures().hasCellTTL() && !storeManager.getFeatures().hasStoreTTL()) {
storeManager = new TTLKCVSManager(storeManager);
} else if (!storeManager.getFeatures().hasStoreTTL()) {
return;
}
assertTrue(storeManager.getFeatures().hasStoreTTL());
final TimeUnit sec = TimeUnit.SECONDS;
final int storeTTLSeconds = (int) TestGraphConfigs.getTTL(sec);
StoreMetaData.Container opts = new StoreMetaData.Container();
opts.put(StoreMetaData.TTL, storeTTLSeconds);
KeyColumnValueStore storeWithTTL = storeManager.openDatabase("testStore_with_TTL", opts);
populateDBWith100Keys(storeWithTTL);
tx.commit();
tx = startTx();
final StaticBuffer key = KeyColumnValueStoreUtil.longToByteBuffer(2);
StaticBuffer start = KeyColumnValueStoreUtil.stringToByteBuffer("a");
StaticBuffer end = KeyColumnValueStoreUtil.stringToByteBuffer("d");
EntryList results = storeWithTTL.getSlice(new KeySliceQuery(key, new SliceQuery(start, end)), tx);
assertEquals(3, results.size());
Thread.sleep(TimeUnit.MILLISECONDS.convert((long) Math.ceil(storeTTLSeconds * 1.25), sec));
tx.commit();
tx = startTx();
results = storeWithTTL.getSlice(new KeySliceQuery(key, new SliceQuery(start, end)), tx);
// should be empty if TTL was applied properly
assertEquals(0, results.size());
storeWithTTL.close();
}
use of org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery in project janusgraph by JanusGraph.
the class MultiKeySliceQuery method execute.
public List<EntryList> execute(final BackendTransaction tx) {
int total = 0;
final List<EntryList> result = new ArrayList<>(Math.min(getLimit(), queries.size()));
for (KeySliceQuery ksq : queries) {
EntryList next = tx.indexQuery(ksq.updateLimit(getLimit() - total));
result.add(next);
total += next.size();
if (total >= getLimit())
break;
}
return result;
}
use of org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery in project janusgraph by JanusGraph.
the class KCVSConfiguration method toMap.
private Map<String, Object> toMap() {
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);
Map<String, Object> entries = new HashMap<>(result.size());
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;
}
use of org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery in project janusgraph by JanusGraph.
the class BackendTransaction method edgeStoreMultiQuery.
public Map<StaticBuffer, EntryList> edgeStoreMultiQuery(final List<StaticBuffer> keys, final SliceQuery query) {
if (storeFeatures.hasMultiQuery()) {
return executeRead(new Callable<Map<StaticBuffer, EntryList>>() {
@Override
public Map<StaticBuffer, EntryList> call() throws Exception {
return cacheEnabled ? edgeStore.getSlice(keys, query, storeTx) : edgeStore.getSliceNoCache(keys, query, storeTx);
}
@Override
public String toString() {
return "MultiEdgeStoreQuery";
}
});
} else {
final Map<StaticBuffer, EntryList> results = new HashMap<>(keys.size());
if (threadPool == null || keys.size() < MIN_TASKS_TO_PARALLELIZE) {
for (StaticBuffer key : keys) {
results.put(key, edgeStoreQuery(new KeySliceQuery(key, query)));
}
} else {
final CountDownLatch doneSignal = new CountDownLatch(keys.size());
final AtomicInteger failureCount = new AtomicInteger(0);
EntryList[] resultArray = new EntryList[keys.size()];
for (int i = 0; i < keys.size(); i++) {
threadPool.execute(new SliceQueryRunner(new KeySliceQuery(keys.get(i), query), doneSignal, failureCount, resultArray, i));
}
try {
doneSignal.await();
} catch (InterruptedException e) {
throw new JanusGraphException("Interrupted while waiting for multi-query to complete", e);
}
if (failureCount.get() > 0) {
throw new JanusGraphException("Could not successfully complete multi-query. " + failureCount.get() + " individual queries failed.");
}
for (int i = 0; i < keys.size(); i++) {
assert resultArray[i] != null;
results.put(keys.get(i), resultArray[i]);
}
}
return results;
}
}
use of org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery in project janusgraph by JanusGraph.
the class ConsistentKeyLockerTest method recordLockGetSlice.
private void recordLockGetSlice(EntryList returnedEntries) throws BackendException {
final KeySliceQuery ksq = new KeySliceQuery(defaultLockKey, LOCK_COL_START, LOCK_COL_END);
expect(store.getSlice(eq(ksq), eq(defaultTx))).andReturn(returnedEntries);
}
Aggregations