use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery in project titan by thinkaurelius.
the class SimpleScanJob method workerIterationStart.
@Override
public void workerIterationStart(Configuration config, Configuration graphConfig, ScanMetrics metrics) {
assertNotNull(config);
metrics.incrementCustom(SETUP_COUNT);
if (config.has(HEX_QUERIES)) {
String[] queryStrings = config.get(HEX_QUERIES).split(":");
List<SliceQuery> queries = new LinkedList<>();
for (String qString : queryStrings) {
String[] queryTokens = qString.split("/");
StaticBuffer start = StaticArrayBuffer.of(Hex.hexToBytes(queryTokens[0]));
StaticBuffer end = StaticArrayBuffer.of(Hex.hexToBytes(queryTokens[1]));
SliceQuery query = new SliceQuery(start, end);
int limit = Integer.valueOf(queryTokens[2]);
if (0 <= limit) {
query.setLimit(limit);
}
queries.add(query);
}
qs = queries;
}
if (config.has(KEY_FILTER_ID_MODULUS)) {
final long mod = config.get(KEY_FILTER_ID_MODULUS);
final long modVal;
if (config.has(KEY_FILTER_ID_MODULAR_VALUE)) {
modVal = config.get(KEY_FILTER_ID_MODULAR_VALUE);
} else {
modVal = 0;
}
keyFilter = k -> KeyValueStoreUtil.getID(k) % mod == modVal;
}
}
use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery in project titan by thinkaurelius.
the class SimpleScanJob method encodeQueries.
private static String encodeQueries(List<SliceQuery> queries) {
List<String> queryStrings = new ArrayList<>(queries.size());
for (SliceQuery query : queries) {
String start = Hex.bytesToHex(query.getSliceStart().as(StaticBuffer.ARRAY_FACTORY));
String end = Hex.bytesToHex(query.getSliceEnd().as(StaticBuffer.ARRAY_FACTORY));
final int limit;
if (query.hasLimit()) {
limit = query.getLimit();
} else {
limit = -1;
}
queryStrings.add(String.format("%s/%s/%d", start, end, limit));
}
return Joiner.on(":").join(queryStrings);
}
use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery in project titan by thinkaurelius.
the class ExpirationCacheTest method testExpiration.
private void testExpiration(Duration expirationTime) throws Exception {
final int numKeys = 100, numCols = 10;
loadStore(numKeys, numCols);
//Replace cache with proper times
cache = getCache(store, expirationTime, Duration.ZERO);
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);
//Modify store directly
StoreTransaction txs = getStoreTx();
store.mutate(key, KeyColumnValueStore.NO_ADDITIONS, Lists.newArrayList(BufferUtil.getIntBuffer(5)), txs);
txs.commit();
Instant utime = times.getTime();
//Should still see cached results
verifyResults(key, keys, query, 6);
//Sleep half way through expiration time
times.sleepPast(utime.plus(expirationTime.dividedBy(2)));
verifyResults(key, keys, query, 6);
//Sleep past expiration time...
times.sleepPast(utime.plus(expirationTime));
//...and just a little bit longer
times.sleepFor(Duration.ofMillis(5));
//Now the results should be different
verifyResults(key, keys, query, 5);
//If we modify through cache store...
CacheTransaction tx = getCacheTx();
cache.mutateEntries(key, KeyColumnValueStore.NO_ADDITIONS, Lists.newArrayList(getEntry(4, 4)), tx);
tx.commit();
store.resetCounter();
//...invalidation should happen and the result set is updated immediately
verifyResults(key, keys, query, 4);
}
use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery in project titan by thinkaurelius.
the class IndexRemoveJob method getQueries.
@Override
public List<SliceQuery> getQueries() {
if (isGlobalGraphIndex()) {
//Everything
return ImmutableList.of(new SliceQuery(BufferUtil.zeroBuffer(1), BufferUtil.oneBuffer(128)));
} else {
RelationTypeIndexWrapper wrapper = (RelationTypeIndexWrapper) index;
InternalRelationType wrappedType = wrapper.getWrappedType();
Direction direction = null;
for (Direction dir : Direction.values()) if (wrappedType.isUnidirected(dir))
direction = dir;
assert direction != null;
StandardTitanTx tx = (StandardTitanTx) graph.get().buildTransaction().readOnly().start();
try {
QueryContainer qc = new QueryContainer(tx);
qc.addQuery().type(wrappedType).direction(direction).relations();
return qc.getSliceQueries();
} finally {
tx.rollback();
}
}
}
use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery in project titan by thinkaurelius.
the class CacheVertex method loadRelations.
@Override
public EntryList loadRelations(final SliceQuery query, final Retriever<SliceQuery, EntryList> lookup) {
if (isNew())
return EntryList.EMPTY_LIST;
EntryList result;
synchronized (queryCache) {
result = queryCache.get(query);
}
if (result == null) {
//First check for super
Map.Entry<SliceQuery, EntryList> superset = getSuperResultSet(query);
if (superset == null) {
result = lookup.get(query);
} else {
result = query.getSubset(superset.getKey(), superset.getValue());
}
addToQueryCache(query, result);
}
return result;
}
Aggregations