Search in sources :

Example 11 with PropertyKey

use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.

the class TitanGraphIterativeBenchmark method loadData.

public void loadData(final int numVertices, final int numThreads) throws Exception {
    makeKey("w", Integer.class);
    PropertyKey time = makeKey("t", Long.class);
    ((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("l")).sortKey(time).make();
    finishSchema();
    final int maxQueue = 1000;
    final int verticesPerTask = 1000;
    final int maxWeight = 10;
    final int maxTime = 10000;
    BlockingQueue<Runnable> tasks = new ArrayBlockingQueue<Runnable>(maxQueue);
    ExecutorService exe = Executors.newFixedThreadPool(numThreads);
    for (int i = 0; i < numVertices / verticesPerTask; i++) {
        while (tasks.size() >= maxQueue) Thread.sleep(maxQueue);
        assert tasks.size() < maxQueue;
        exe.submit(new Runnable() {

            @Override
            public void run() {
                TitanTransaction tx = graph.newTransaction();
                TitanVertex[] vs = new TitanVertex[verticesPerTask];
                for (int j = 0; j < verticesPerTask; j++) {
                    vs[j] = tx.addVertex();
                    vs[j].property(VertexProperty.Cardinality.single, "w", random.nextInt(maxWeight));
                }
                for (int j = 0; j < verticesPerTask * 10; j++) {
                    TitanEdge e = vs[random.nextInt(verticesPerTask)].addEdge("l", vs[random.nextInt(verticesPerTask)]);
                    e.property("t", random.nextInt(maxTime));
                }
                System.out.print(".");
                tx.commit();
            }
        });
    }
    exe.shutdown();
    exe.awaitTermination(numVertices / 1000, TimeUnit.SECONDS);
    if (!exe.isTerminated())
        System.err.println("Could not load data in time");
    System.out.println("Loaded " + numVertices + "vertices");
}
Also used : TitanTransaction(com.thinkaurelius.titan.core.TitanTransaction) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) TitanEdge(com.thinkaurelius.titan.core.TitanEdge)

Example 12 with PropertyKey

use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.

the class TitanGraphPerformanceMemoryTest method testTransactionalMemory.

@Test
public void testTransactionalMemory() throws Exception {
    makeVertexIndexedUniqueKey("uid", Long.class);
    makeKey("name", String.class);
    PropertyKey time = makeKey("time", Integer.class);
    mgmt.makeEdgeLabel("friend").signature(time).directed().make();
    finishSchema();
    final Random random = new Random();
    final int rounds = 100;
    final int commitSize = 1500;
    final AtomicInteger uidCounter = new AtomicInteger(0);
    Thread[] writeThreads = new Thread[4];
    long start = System.currentTimeMillis();
    for (int t = 0; t < writeThreads.length; t++) {
        writeThreads[t] = new Thread(new Runnable() {

            @Override
            public void run() {
                for (int r = 0; r < rounds; r++) {
                    TitanTransaction tx = graph.newTransaction();
                    TitanVertex previous = null;
                    for (int c = 0; c < commitSize; c++) {
                        TitanVertex v = tx.addVertex();
                        long uid = uidCounter.incrementAndGet();
                        v.property(VertexProperty.Cardinality.single, "uid", uid);
                        v.property(VertexProperty.Cardinality.single, "name", "user" + uid);
                        if (previous != null) {
                            v.addEdge("friend", previous, "time", Math.abs(random.nextInt()));
                        }
                        previous = v;
                    }
                    tx.commit();
                }
            }
        });
        writeThreads[t].start();
    }
    for (int t = 0; t < writeThreads.length; t++) {
        writeThreads[t].join();
    }
    System.out.println("Write time for " + (rounds * commitSize * writeThreads.length) + " vertices & edges: " + (System.currentTimeMillis() - start));
    final int maxUID = uidCounter.get();
    final int trials = 1000;
    final String fixedName = "john";
    Thread[] readThreads = new Thread[Runtime.getRuntime().availableProcessors() * 2];
    start = System.currentTimeMillis();
    for (int t = 0; t < readThreads.length; t++) {
        readThreads[t] = new Thread(new Runnable() {

            @Override
            public void run() {
                TitanTransaction tx = graph.newTransaction();
                long ruid = random.nextInt(maxUID) + 1;
                getVertex(tx, "uid", ruid).property(VertexProperty.Cardinality.single, "name", fixedName);
                for (int t = 1; t <= trials; t++) {
                    TitanVertex v = getVertex(tx, "uid", random.nextInt(maxUID) + 1);
                    assertCount(2, v.properties());
                    int count = 0;
                    for (TitanEdge e : v.query().direction(Direction.BOTH).edges()) {
                        count++;
                        assertTrue(e.<Integer>value("time") >= 0);
                    }
                    assertTrue(count <= 2);
                //                        if (t%(trials/10)==0) System.out.println(t);
                }
                assertEquals(fixedName, getVertex(tx, "uid", ruid).value("name"));
                tx.commit();
            }
        });
        readThreads[t].start();
    }
    for (int t = 0; t < readThreads.length; t++) {
        readThreads[t].join();
    }
    System.out.println("Read time for " + (trials * readThreads.length) + " vertex lookups: " + (System.currentTimeMillis() - start));
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) TitanTransaction(com.thinkaurelius.titan.core.TitanTransaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) TitanEdge(com.thinkaurelius.titan.core.TitanEdge) Test(org.junit.Test)

Example 13 with PropertyKey

use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.

the class TitanGraphTest method testTinkerPopOptimizationStrategies.

@Test
public void testTinkerPopOptimizationStrategies() {
    PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SINGLE).dataType(Integer.class).make();
    PropertyKey weight = mgmt.makePropertyKey("weight").cardinality(Cardinality.SINGLE).dataType(Integer.class).make();
    mgmt.buildIndex("byId", Vertex.class).addKey(id).buildCompositeIndex();
    mgmt.buildIndex("byWeight", Vertex.class).addKey(weight).buildCompositeIndex();
    mgmt.buildIndex("byIdWeight", Vertex.class).addKey(id).addKey(weight).buildCompositeIndex();
    EdgeLabel knows = mgmt.makeEdgeLabel("knows").make();
    mgmt.buildEdgeIndex(knows, "byWeightDecr", Direction.OUT, decr, weight);
    mgmt.buildEdgeIndex(knows, "byWeightIncr", Direction.OUT, incr, weight);
    PropertyKey names = mgmt.makePropertyKey("names").cardinality(Cardinality.LIST).dataType(String.class).make();
    mgmt.buildPropertyIndex(names, "namesByWeight", decr, weight);
    finishSchema();
    int numV = 100;
    TitanVertex[] vs = new TitanVertex[numV];
    for (int i = 0; i < numV; i++) {
        vs[i] = graph.addVertex("id", i, "weight", i % 5);
    }
    int superV = 10;
    int sid = -1;
    TitanVertex[] sv = new TitanVertex[superV];
    for (int i = 0; i < superV; i++) {
        sv[i] = graph.addVertex("id", sid);
        for (int j = 0; j < numV; j++) {
            sv[i].addEdge("knows", vs[j], "weight", j % 5);
            sv[i].property(VertexProperty.Cardinality.list, "names", "n" + j, "weight", j % 5);
        }
    }
    Traversal t;
    TraversalMetrics metrics;
    GraphTraversalSource gts = graph.traversal();
    //Edge
    assertNumStep(numV / 5, 1, gts.V(sv[0]).outE("knows").has("weight", 1), TitanVertexStep.class);
    assertNumStep(numV, 1, gts.V(sv[0]).outE("knows"), TitanVertexStep.class);
    assertNumStep(numV, 1, gts.V(sv[0]).out("knows"), TitanVertexStep.class);
    assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").limit(10)), TitanVertexStep.class);
    assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").range(10, 20)), LocalStep.class);
    assertNumStep(numV, 2, gts.V(sv[0]).outE("knows").order().by("weight", decr), TitanVertexStep.class, OrderGlobalStep.class);
    assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").order().by("weight", decr).limit(10)), TitanVertexStep.class);
    assertNumStep(numV / 5, 2, gts.V(sv[0]).outE("knows").has("weight", 1).order().by("weight", incr), TitanVertexStep.class, OrderGlobalStep.class);
    assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").has("weight", 1).order().by("weight", incr).limit(10)), TitanVertexStep.class);
    assertNumStep(5, 1, gts.V(sv[0]).local(__.outE("knows").has("weight", 1).has("weight", 1).order().by("weight", incr).range(10, 15)), LocalStep.class);
    assertNumStep(1, 1, gts.V(sv[0]).outE("knows").filter(__.inV().is(vs[50])), TitanVertexStep.class);
    assertNumStep(1, 1, gts.V(sv[0]).outE("knows").filter(__.otherV().is(vs[50])), TitanVertexStep.class);
    assertNumStep(1, 1, gts.V(sv[0]).bothE("knows").filter(__.otherV().is(vs[50])), TitanVertexStep.class);
    assertNumStep(1, 2, gts.V(sv[0]).bothE("knows").filter(__.inV().is(vs[50])), TitanVertexStep.class, TraversalFilterStep.class);
    //Property
    assertNumStep(numV / 5, 1, gts.V(sv[0]).properties("names").has("weight", 1), TitanPropertiesStep.class);
    assertNumStep(numV, 1, gts.V(sv[0]).properties("names"), TitanPropertiesStep.class);
    assertNumStep(10, 1, gts.V(sv[0]).local(__.properties("names").order().by("weight", decr).limit(10)), TitanPropertiesStep.class);
    assertNumStep(numV, 2, gts.V(sv[0]).outE("knows").values("weight"), TitanVertexStep.class, TitanPropertiesStep.class);
    //Global graph queries
    assertNumStep(1, 1, gts.V().has("id", numV / 5), TitanGraphStep.class);
    assertNumStep(1, 1, gts.V().has("id", numV / 5).has("weight", (numV / 5) % 5), TitanGraphStep.class);
    assertNumStep(numV / 5, 1, gts.V().has("weight", 1), TitanGraphStep.class);
    assertNumStep(10, 1, gts.V().has("weight", 1).range(0, 10), TitanGraphStep.class);
    assertNumStep(superV, 1, gts.V().has("id", sid), TitanGraphStep.class);
    //Ensure that as steps don't interfere
    assertNumStep(1, 1, gts.V().has("id", numV / 5).as("x"), TitanGraphStep.class);
    assertNumStep(1, 1, gts.V().has("id", numV / 5).has("weight", (numV / 5) % 5).as("x"), TitanGraphStep.class);
    assertNumStep(superV * (numV / 5), 2, gts.V().has("id", sid).outE("knows").has("weight", 1), TitanGraphStep.class, TitanVertexStep.class);
    assertNumStep(superV * (numV / 5 * 2), 2, gts.V().has("id", sid).outE("knows").has("weight", P.gte(1)).has("weight", P.lt(3)), TitanGraphStep.class, TitanVertexStep.class);
    assertNumStep(superV * (numV / 5 * 2), 2, gts.V().has("id", sid).outE("knows").has("weight", P.between(1, 3)), TitanGraphStep.class, TitanVertexStep.class);
    assertNumStep(superV * 10, 2, gts.V().has("id", sid).local(__.outE("knows").has("weight", P.gte(1)).has("weight", P.lt(3)).limit(10)), TitanGraphStep.class, TitanVertexStep.class);
    assertNumStep(superV * 10, 2, gts.V().has("id", sid).local(__.outE("knows").has("weight", P.between(1, 3)).order().by("weight", decr).limit(10)), TitanGraphStep.class, TitanVertexStep.class);
    clopen(option(USE_MULTIQUERY), true);
    gts = graph.traversal();
    assertNumStep(superV * (numV / 5), 2, gts.V().has("id", sid).outE("knows").has("weight", 1), TitanGraphStep.class, TitanVertexStep.class);
    assertNumStep(superV * (numV / 5 * 2), 2, gts.V().has("id", sid).outE("knows").has("weight", P.between(1, 3)), TitanGraphStep.class, TitanVertexStep.class);
    assertNumStep(superV * 10, 2, gts.V().has("id", sid).local(__.outE("knows").has("weight", P.gte(1)).has("weight", P.lt(3)).limit(10)), TitanGraphStep.class, TitanVertexStep.class);
    assertNumStep(superV * 10, 2, gts.V().has("id", sid).local(__.outE("knows").has("weight", P.between(1, 3)).order().by("weight", decr).limit(10)), TitanGraphStep.class, TitanVertexStep.class);
    assertNumStep(superV * numV, 2, gts.V().has("id", sid).values("names"), TitanGraphStep.class, TitanPropertiesStep.class);
    //Verify traversal metrics when all reads are from cache (i.e. no backend queries)
    t = gts.V().has("id", sid).local(__.outE("knows").has("weight", P.between(1, 3)).order().by("weight", decr).limit(10)).profile();
    assertCount(superV * 10, t);
    metrics = (TraversalMetrics) t.asAdmin().getSideEffects().get("~metrics").get();
    verifyMetrics(metrics.getMetrics(0), true, false);
    verifyMetrics(metrics.getMetrics(1), true, true);
    //Verify that properties also use multi query
    t = gts.V().has("id", sid).values("names").profile();
    assertCount(superV * numV, t);
    metrics = (TraversalMetrics) t.asAdmin().getSideEffects().get("~metrics").get();
    verifyMetrics(metrics.getMetrics(0), true, false);
    verifyMetrics(metrics.getMetrics(1), true, true);
    clopen(option(USE_MULTIQUERY), true);
    gts = graph.traversal();
    //Verify traversal metrics when having to read from backend [same query as above]
    t = gts.V().has("id", sid).local(__.outE("knows").has("weight", P.gte(1)).has("weight", P.lt(3)).order().by("weight", decr).limit(10)).profile();
    assertCount(superV * 10, t);
    metrics = (TraversalMetrics) t.asAdmin().getSideEffects().get("~metrics").get();
    //        System.out.println(metrics);
    verifyMetrics(metrics.getMetrics(0), false, false);
    verifyMetrics(metrics.getMetrics(1), false, true);
    //Verify that properties also use multi query [same query as above]
    t = gts.V().has("id", sid).values("names").profile();
    assertCount(superV * numV, t);
    metrics = (TraversalMetrics) t.asAdmin().getSideEffects().get("~metrics").get();
    //        System.out.println(metrics);
    verifyMetrics(metrics.getMetrics(0), false, false);
    verifyMetrics(metrics.getMetrics(1), false, true);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) EdgeLabel(com.thinkaurelius.titan.core.EdgeLabel) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) TraversalMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics) Test(org.junit.Test)

Example 14 with PropertyKey

use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.

the class TitanGraphTest method evaluateQuery.

public static void evaluateQuery(TitanGraphQuery query, ElementCategory resultType, int expectedResults, boolean[] subQuerySpecs, Map<PropertyKey, Order> orderMap, String... intersectingIndexes) {
    if (intersectingIndexes == null)
        intersectingIndexes = new String[0];
    SimpleQueryProfiler profiler = new SimpleQueryProfiler();
    ((GraphCentricQueryBuilder) query).profiler(profiler);
    Iterable<? extends TitanElement> result;
    switch(resultType) {
        case PROPERTY:
            result = query.properties();
            break;
        case EDGE:
            result = query.edges();
            break;
        case VERTEX:
            result = query.vertices();
            break;
        default:
            throw new AssertionError();
    }
    OrderList orders = profiler.getAnnotation(QueryProfiler.ORDERS_ANNOTATION);
    //Check elements and that they are returned in the correct order
    int no = 0;
    TitanElement previous = null;
    for (TitanElement e : result) {
        assertNotNull(e);
        no++;
        if (previous != null && !orders.isEmpty()) {
            assertTrue(orders.compare(previous, e) <= 0);
        }
        previous = e;
    }
    assertEquals(expectedResults, no);
    //Check OrderList of query
    assertNotNull(orders);
    assertEquals(orderMap.size(), orders.size());
    for (int i = 0; i < orders.size(); i++) {
        assertEquals(orderMap.get(orders.getKey(i)), orders.getOrder(i));
    }
    for (PropertyKey key : orderMap.keySet()) assertTrue(orders.containsKey(key));
    //Check subqueries
    SimpleQueryProfiler subp = Iterables.getOnlyElement(Iterables.filter(profiler, p -> !p.getGroupName().equals(QueryProfiler.OPTIMIZATION)));
    if (subQuerySpecs.length == 2) {
        //0=>fitted, 1=>ordered
        assertEquals(subQuerySpecs[0], (Boolean) subp.getAnnotation(QueryProfiler.FITTED_ANNOTATION));
        assertEquals(subQuerySpecs[1], (Boolean) subp.getAnnotation(QueryProfiler.ORDERED_ANNOTATION));
    }
    Set<String> indexNames = new HashSet<>();
    int indexQueries = 0;
    boolean fullscan = false;
    for (SimpleQueryProfiler indexp : subp) {
        if (indexp.getAnnotation(QueryProfiler.FULLSCAN_ANNOTATION) != null) {
            fullscan = true;
        } else {
            indexNames.add(indexp.getAnnotation(QueryProfiler.INDEX_ANNOTATION));
            indexQueries++;
        }
    }
    if (indexQueries > 0)
        assertFalse(fullscan);
    if (fullscan)
        assertTrue(intersectingIndexes.length == 0);
    assertEquals(intersectingIndexes.length, indexQueries);
    assertEquals(Sets.newHashSet(intersectingIndexes), indexNames);
}
Also used : BrittleTests(com.thinkaurelius.titan.testcategory.BrittleTests) StandardTitanTx(com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx) Arrays(java.util.Arrays) EdgeSerializer(com.thinkaurelius.titan.graphdb.database.EdgeSerializer) GraphOfTheGodsFactory(com.thinkaurelius.titan.example.GraphOfTheGodsFactory) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) BasicVertexCentricQueryBuilder(com.thinkaurelius.titan.graphdb.query.vertex.BasicVertexCentricQueryBuilder) TransactionId(com.thinkaurelius.titan.core.log.TransactionId) Change(com.thinkaurelius.titan.core.log.Change) BaseVertexLabel(com.thinkaurelius.titan.graphdb.types.system.BaseVertexLabel) EdgeLabel(com.thinkaurelius.titan.core.EdgeLabel) Cardinality.single(org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality.single) Duration(java.time.Duration) Map(java.util.Map) ManagementUtil(com.thinkaurelius.titan.core.util.ManagementUtil) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) Metrics(org.apache.tinkerpop.gremlin.process.traversal.util.Metrics) EnumSet(java.util.EnumSet) InternalRelationType(com.thinkaurelius.titan.graphdb.internal.InternalRelationType) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) ChangeState(com.thinkaurelius.titan.core.log.ChangeState) SimpleQueryProfiler(com.thinkaurelius.titan.graphdb.query.profile.SimpleQueryProfiler) ConfigOption(com.thinkaurelius.titan.diskstorage.configuration.ConfigOption) KCVSLog(com.thinkaurelius.titan.diskstorage.log.kcvs.KCVSLog) SpecialInt(com.thinkaurelius.titan.graphdb.serializer.SpecialInt) EnumMap(java.util.EnumMap) Order.decr(org.apache.tinkerpop.gremlin.process.traversal.Order.decr) Set(java.util.Set) ConsistencyModifier(com.thinkaurelius.titan.core.schema.ConsistencyModifier) ImplicitKey(com.thinkaurelius.titan.graphdb.types.system.ImplicitKey) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Mapping(com.thinkaurelius.titan.core.schema.Mapping) Category(org.junit.experimental.categories.Category) StandardEdgeLabelMaker(com.thinkaurelius.titan.graphdb.types.StandardEdgeLabelMaker) CountDownLatch(java.util.concurrent.CountDownLatch) IndexRemoveJob(com.thinkaurelius.titan.graphdb.olap.job.IndexRemoveJob) TitanGraphStep(com.thinkaurelius.titan.graphdb.tinkerpop.optimize.TitanGraphStep) IndexRepairJob(com.thinkaurelius.titan.graphdb.olap.job.IndexRepairJob) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Iterables(com.google.common.collect.Iterables) StartStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.StartStep) TitanVertexQuery(com.thinkaurelius.titan.core.TitanVertexQuery) Message(com.thinkaurelius.titan.diskstorage.log.Message) Cardinality(com.thinkaurelius.titan.core.Cardinality) LogProcessorFramework(com.thinkaurelius.titan.core.log.LogProcessorFramework) QueryProfiler(com.thinkaurelius.titan.graphdb.query.profile.QueryProfiler) ArrayList(java.util.ArrayList) OrderList(com.thinkaurelius.titan.graphdb.internal.OrderList) LogTxMeta(com.thinkaurelius.titan.graphdb.database.log.LogTxMeta) Lists(com.google.common.collect.Lists) GraphDatabaseConfiguration(com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration) LogTxStatus(com.thinkaurelius.titan.graphdb.database.log.LogTxStatus) GraphStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.GraphStep) TitanAssert(com.thinkaurelius.titan.testutil.TitanAssert) MessageReader(com.thinkaurelius.titan.diskstorage.log.MessageReader) PropertyKeyDefinition(com.thinkaurelius.titan.graphdb.schema.PropertyKeyDefinition) TransactionRecovery(com.thinkaurelius.titan.core.log.TransactionRecovery) VertexLabelDefinition(com.thinkaurelius.titan.graphdb.schema.VertexLabelDefinition) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) Test(org.junit.Test) T(org.apache.tinkerpop.gremlin.structure.T) TitanManagement(com.thinkaurelius.titan.core.schema.TitanManagement) ExecutionException(java.util.concurrent.ExecutionException) Direction(org.apache.tinkerpop.gremlin.structure.Direction) ChronoUnit(java.time.temporal.ChronoUnit) Cmp(com.thinkaurelius.titan.core.attribute.Cmp) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) TransactionLogHeader(com.thinkaurelius.titan.graphdb.database.log.TransactionLogHeader) Preconditions(com.google.common.base.Preconditions) TraversalMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics) Assert(org.junit.Assert) Geoshape(com.thinkaurelius.titan.core.attribute.Geoshape) TitanVertexStep(com.thinkaurelius.titan.graphdb.tinkerpop.optimize.TitanVertexStep) TitanSchemaType(com.thinkaurelius.titan.core.schema.TitanSchemaType) Multiplicity(com.thinkaurelius.titan.core.Multiplicity) LoggerFactory(org.slf4j.LoggerFactory) SchemaStatus(com.thinkaurelius.titan.core.schema.SchemaStatus) Order(com.thinkaurelius.titan.graphdb.internal.Order) Random(java.util.Random) Order.incr(org.apache.tinkerpop.gremlin.process.traversal.Order.incr) RelationCategory(com.thinkaurelius.titan.graphdb.internal.RelationCategory) SpecialIntSerializer(com.thinkaurelius.titan.graphdb.serializer.SpecialIntSerializer) SchemaViolationException(com.thinkaurelius.titan.core.SchemaViolationException) TitanFactory(com.thinkaurelius.titan.core.TitanFactory) ChangeProcessor(com.thinkaurelius.titan.core.log.ChangeProcessor) VertexLabel(com.thinkaurelius.titan.core.VertexLabel) ElementCategory(com.thinkaurelius.titan.graphdb.internal.ElementCategory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TimestampProvider(com.thinkaurelius.titan.diskstorage.util.time.TimestampProvider) P(org.apache.tinkerpop.gremlin.process.traversal.P) RelationIdentifier(com.thinkaurelius.titan.graphdb.relations.RelationIdentifier) TitanPropertiesStep(com.thinkaurelius.titan.graphdb.tinkerpop.optimize.TitanPropertiesStep) ImmutableMap(com.google.common.collect.ImmutableMap) BackendException(com.thinkaurelius.titan.diskstorage.BackendException) Serializer(com.thinkaurelius.titan.graphdb.database.serialize.Serializer) TitanConfigurationException(com.thinkaurelius.titan.core.TitanConfigurationException) SchemaAction(com.thinkaurelius.titan.core.schema.SchemaAction) Instant(java.time.Instant) TitanCleanup(com.thinkaurelius.titan.core.util.TitanCleanup) Sets(com.google.common.collect.Sets) List(java.util.List) LocalStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep) TitanVertexProperty(com.thinkaurelius.titan.core.TitanVertexProperty) TitanTransaction(com.thinkaurelius.titan.core.TitanTransaction) TitanElement(com.thinkaurelius.titan.core.TitanElement) RelationType(com.thinkaurelius.titan.core.RelationType) StandardTransactionLogProcessor(com.thinkaurelius.titan.graphdb.log.StandardTransactionLogProcessor) StandardTitanGraph(com.thinkaurelius.titan.graphdb.database.StandardTitanGraph) TitanGraph(com.thinkaurelius.titan.core.TitanGraph) EdgeLabelDefinition(com.thinkaurelius.titan.graphdb.schema.EdgeLabelDefinition) WriteConfiguration(com.thinkaurelius.titan.diskstorage.configuration.WriteConfiguration) Log(com.thinkaurelius.titan.diskstorage.log.Log) GraphCentricQueryBuilder(com.thinkaurelius.titan.graphdb.query.graph.GraphCentricQueryBuilder) TitanException(com.thinkaurelius.titan.core.TitanException) ManagementSystem(com.thinkaurelius.titan.graphdb.database.management.ManagementSystem) StandardPropertyKeyMaker(com.thinkaurelius.titan.graphdb.types.StandardPropertyKeyMaker) Iterators(com.google.common.collect.Iterators) OrderGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep) HashSet(java.util.HashSet) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) ImmutableList(com.google.common.collect.ImmutableList) RelationTypeIndex(com.thinkaurelius.titan.core.schema.RelationTypeIndex) TitanEdge(com.thinkaurelius.titan.core.TitanEdge) VertexList(com.thinkaurelius.titan.core.VertexList) Edge(org.apache.tinkerpop.gremlin.structure.Edge) SchemaContainer(com.thinkaurelius.titan.graphdb.schema.SchemaContainer) Contain(com.thinkaurelius.titan.core.attribute.Contain) TitanGraphQuery(com.thinkaurelius.titan.core.TitanGraphQuery) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) TestGraphConfigs(com.thinkaurelius.titan.testutil.TestGraphConfigs) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) TimeUnit(java.util.concurrent.TimeUnit) ReadMarker(com.thinkaurelius.titan.diskstorage.log.ReadMarker) ConfigElement(com.thinkaurelius.titan.diskstorage.configuration.ConfigElement) ScanMetrics(com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.ScanMetrics) TraversalFilterStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep) GraphCentricQueryBuilder(com.thinkaurelius.titan.graphdb.query.graph.GraphCentricQueryBuilder) SimpleQueryProfiler(com.thinkaurelius.titan.graphdb.query.profile.SimpleQueryProfiler) TitanElement(com.thinkaurelius.titan.core.TitanElement) OrderList(com.thinkaurelius.titan.graphdb.internal.OrderList) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) HashSet(java.util.HashSet)

Example 15 with PropertyKey

use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.

the class TitanGraphTest method testVertexTTLWithCompositeIndex.

@Test
public void testVertexTTLWithCompositeIndex() throws Exception {
    if (!features.hasCellTTL()) {
        return;
    }
    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
    PropertyKey time = mgmt.makePropertyKey("time").dataType(Long.class).make();
    TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex();
    TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(time).buildCompositeIndex();
    VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
    mgmt.setTTL(label1, Duration.ofSeconds(1));
    assertEquals(Duration.ZERO, mgmt.getTTL(name));
    assertEquals(Duration.ZERO, mgmt.getTTL(time));
    assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1));
    mgmt.commit();
    TitanVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "time", System.currentTimeMillis());
    tx.commit();
    Object id = v1.id();
    v1 = getV(graph, id);
    assertNotNull(v1);
    assertNotEmpty(graph.query().has("name", "some event").vertices());
    Thread.sleep(1001);
    graph.tx().rollback();
    v1 = getV(graph, id);
    assertNull(v1);
    assertEmpty(graph.query().has("name", "some event").vertices());
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) BaseVertexLabel(com.thinkaurelius.titan.graphdb.types.system.BaseVertexLabel) VertexLabel(com.thinkaurelius.titan.core.VertexLabel) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test)

Aggregations

PropertyKey (com.thinkaurelius.titan.core.PropertyKey)79 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)49 Test (org.junit.Test)49 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)21 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)20 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)18 Edge (org.apache.tinkerpop.gremlin.structure.Edge)15 TitanEdge (com.thinkaurelius.titan.core.TitanEdge)14 TitanTransaction (com.thinkaurelius.titan.core.TitanTransaction)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 AtlasPropertyKey (org.apache.atlas.repository.graphdb.AtlasPropertyKey)12 TitanVertexProperty (com.thinkaurelius.titan.core.TitanVertexProperty)11 VertexLabel (com.thinkaurelius.titan.core.VertexLabel)11 TitanManagement (com.thinkaurelius.titan.core.schema.TitanManagement)11 BaseVertexLabel (com.thinkaurelius.titan.graphdb.types.system.BaseVertexLabel)8 VertexProperty (org.apache.tinkerpop.gremlin.structure.VertexProperty)8 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)7 TitanException (com.thinkaurelius.titan.core.TitanException)6 HashSet (java.util.HashSet)6 Instant (java.time.Instant)5