Search in sources :

Example 1 with SliceQuery

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;
    }
}
Also used : SliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)

Example 2 with SliceQuery

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);
}
Also used : SliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)

Example 3 with SliceQuery

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);
}
Also used : StoreTransaction(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction) 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)

Example 4 with SliceQuery

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();
        }
    }
}
Also used : RelationTypeIndexWrapper(com.thinkaurelius.titan.graphdb.database.management.RelationTypeIndexWrapper) InternalRelationType(com.thinkaurelius.titan.graphdb.internal.InternalRelationType) Direction(org.apache.tinkerpop.gremlin.structure.Direction) StandardTitanTx(com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx) SliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery) QueryContainer(com.thinkaurelius.titan.graphdb.olap.QueryContainer)

Example 5 with SliceQuery

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;
}
Also used : EntryList(com.thinkaurelius.titan.diskstorage.EntryList) Map(java.util.Map) HashMap(java.util.HashMap) SliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)

Aggregations

SliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)22 EntryList (com.thinkaurelius.titan.diskstorage.EntryList)6 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)6 Interval (com.thinkaurelius.titan.util.datastructures.Interval)5 EdgeSerializer (com.thinkaurelius.titan.graphdb.database.EdgeSerializer)3 CacheVertex (com.thinkaurelius.titan.graphdb.vertices.CacheVertex)3 PointInterval (com.thinkaurelius.titan.util.datastructures.PointInterval)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Direction (org.apache.tinkerpop.gremlin.structure.Direction)3 LongArrayList (com.carrotsearch.hppc.LongArrayList)2 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)2 KeySliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)2 CacheTransaction (com.thinkaurelius.titan.diskstorage.keycolumnvalue.cache.CacheTransaction)2 ScanMetrics (com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.ScanMetrics)2 InternalVertex (com.thinkaurelius.titan.graphdb.internal.InternalVertex)2 ImplicitKey (com.thinkaurelius.titan.graphdb.types.system.ImplicitKey)2 RangeInterval (com.thinkaurelius.titan.util.datastructures.RangeInterval)2 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1