Search in sources :

Example 36 with StandardJanusGraph

use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.

the class ConfiguredGraphFactoryTest method graphConfigurationShouldBeWhatWeExpectWhenUsingTemplateConfiguration.

@Test
public void graphConfigurationShouldBeWhatWeExpectWhenUsingTemplateConfiguration() throws Exception {
    try {
        final Map<String, Object> map = new HashMap<>();
        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
        ConfiguredGraphFactory.createTemplateConfiguration(new MapConfiguration(map));
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.create("graph1");
        final StandardJanusGraph graph1 = (StandardJanusGraph) ConfiguredGraphFactory.open("graph1");
        assertNotNull(graph);
        assertEquals(graph, graph1);
        assertEquals("graph1", graph.getConfiguration().getConfiguration().get(GRAPH_NAME));
        assertEquals("inmemory", graph.getConfiguration().getConfiguration().get(STORAGE_BACKEND));
    } finally {
        ConfiguredGraphFactory.removeConfiguration("graph1");
        ConfiguredGraphFactory.close("graph1");
    }
}
Also used : HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.Test)

Example 37 with StandardJanusGraph

use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.

the class ConfiguredGraphFactoryTest method ensureCallingGraphCloseResultsInNewGraphReferenceOnNextCallToOpen.

@Test
public void ensureCallingGraphCloseResultsInNewGraphReferenceOnNextCallToOpen() throws Exception {
    try {
        final Map<String, Object> map = new HashMap<>();
        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
        ConfiguredGraphFactory.createTemplateConfiguration(new MapConfiguration(map));
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.create("graph1");
        assertNotNull(graph);
        assertEquals("graph1", graph.getConfiguration().getConfiguration().get(GRAPH_NAME));
        graph.close();
        assertTrue(graph.isClosed());
        final StandardJanusGraph newGraph = (StandardJanusGraph) ConfiguredGraphFactory.open("graph1");
        assertFalse(newGraph.isClosed());
    } finally {
        ConfiguredGraphFactory.removeConfiguration("graph1");
        ConfiguredGraphFactory.close("graph1");
    }
}
Also used : HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.Test)

Example 38 with StandardJanusGraph

use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.

the class JanusGraphLocalQueryOptimizerStrategy method apply.

@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (!traversal.getGraph().isPresent())
        return;
    Graph graph = traversal.getGraph().get();
    // If this is a compute graph then we can't apply local traversal optimisation at this stage.
    StandardJanusGraph janusGraph = graph instanceof StandardJanusGraphTx ? ((StandardJanusGraphTx) graph).getGraph() : (StandardJanusGraph) graph;
    final boolean useMultiQuery = !TraversalHelper.onGraphComputer(traversal) && janusGraph.getConfiguration().useMultiQuery();
    /*
                ====== VERTEX STEP ======
         */
    TraversalHelper.getStepsOfClass(VertexStep.class, traversal).forEach(originalStep -> {
        JanusGraphVertexStep vertexStep = new JanusGraphVertexStep(originalStep);
        TraversalHelper.replaceStep(originalStep, vertexStep, traversal);
        if (JanusGraphTraversalUtil.isEdgeReturnStep(vertexStep)) {
            HasStepFolder.foldInHasContainer(vertexStep, traversal);
        // We cannot fold in orders or ranges since they are not local
        }
        assert JanusGraphTraversalUtil.isEdgeReturnStep(vertexStep) || JanusGraphTraversalUtil.isVertexReturnStep(vertexStep);
        Step nextStep = JanusGraphTraversalUtil.getNextNonIdentityStep(vertexStep);
        if (nextStep instanceof RangeGlobalStep) {
            int limit = QueryUtil.convertLimit(((RangeGlobalStep) nextStep).getHighRange());
            vertexStep.setLimit(QueryUtil.mergeLimits(limit, vertexStep.getLimit()));
        }
        if (useMultiQuery) {
            vertexStep.setUseMultiQuery(true);
        }
    });
    /*
                ====== PROPERTIES STEP ======
         */
    TraversalHelper.getStepsOfClass(PropertiesStep.class, traversal).forEach(originalStep -> {
        JanusGraphPropertiesStep propertiesStep = new JanusGraphPropertiesStep(originalStep);
        TraversalHelper.replaceStep(originalStep, propertiesStep, traversal);
        if (propertiesStep.getReturnType().forProperties()) {
            HasStepFolder.foldInHasContainer(propertiesStep, traversal);
        // We cannot fold in orders or ranges since they are not local
        }
        if (useMultiQuery) {
            propertiesStep.setUseMultiQuery(true);
        }
    });
    /*
                ====== EITHER INSIDE LOCAL ======
         */
    TraversalHelper.getStepsOfClass(LocalStep.class, traversal).forEach(localStep -> {
        Traversal.Admin localTraversal = ((LocalStep<?, ?>) localStep).getLocalChildren().get(0);
        Step localStart = localTraversal.getStartStep();
        if (localStart instanceof VertexStep) {
            JanusGraphVertexStep vertexStep = new JanusGraphVertexStep((VertexStep) localStart);
            TraversalHelper.replaceStep(localStart, vertexStep, localTraversal);
            if (JanusGraphTraversalUtil.isEdgeReturnStep(vertexStep)) {
                HasStepFolder.foldInHasContainer(vertexStep, localTraversal);
                HasStepFolder.foldInOrder(vertexStep, localTraversal, traversal, false);
            }
            HasStepFolder.foldInRange(vertexStep, localTraversal);
            unfoldLocalTraversal(traversal, localStep, localTraversal, vertexStep, useMultiQuery);
        }
        if (localStart instanceof PropertiesStep) {
            JanusGraphPropertiesStep propertiesStep = new JanusGraphPropertiesStep((PropertiesStep) localStart);
            TraversalHelper.replaceStep(localStart, propertiesStep, localTraversal);
            if (propertiesStep.getReturnType().forProperties()) {
                HasStepFolder.foldInHasContainer(propertiesStep, localTraversal);
                HasStepFolder.foldInOrder(propertiesStep, localTraversal, traversal, false);
            }
            HasStepFolder.foldInRange(propertiesStep, localTraversal);
            unfoldLocalTraversal(traversal, localStep, localTraversal, propertiesStep, useMultiQuery);
        }
    });
}
Also used : PropertiesStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) PropertiesStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) LocalStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep) RangeGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) LocalStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Graph(org.apache.tinkerpop.gremlin.structure.Graph) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) RangeGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph)

Example 39 with StandardJanusGraph

use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.

the class JanusGraphTest method testIndexUpdateSyncWithMultipleInstances.

@Tag(TestCategory.BRITTLE_TESTS)
@Test
public void testIndexUpdateSyncWithMultipleInstances() throws InterruptedException {
    clopen(option(LOG_SEND_DELAY, MANAGEMENT_LOG), Duration.ofMillis(0), option(KCVSLog.LOG_READ_LAG_TIME, MANAGEMENT_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, MANAGEMENT_LOG), Duration.ofMillis(250));
    StandardJanusGraph graph2 = (StandardJanusGraph) JanusGraphFactory.open(config);
    JanusGraphTransaction tx2;
    mgmt.makePropertyKey("name").dataType(String.class).make();
    finishSchema();
    tx.addVertex("name", "v1");
    newTx();
    evaluateQuery(tx.query().has("name", "v1"), ElementCategory.VERTEX, 1, new boolean[] { false, true });
    tx2 = graph2.newTransaction();
    evaluateQuery(tx2.query().has("name", "v1"), ElementCategory.VERTEX, 1, new boolean[] { false, true });
    // Leave tx2 open to delay acknowledgement
    mgmt.buildIndex("theIndex", Vertex.class).addKey(mgmt.getPropertyKey("name")).buildCompositeIndex();
    mgmt.commit();
    JanusGraphTransaction tx3 = graph2.newTransaction();
    tx3.addVertex("name", "v2");
    tx3.commit();
    newTx();
    tx.addVertex("name", "v3");
    tx.commit();
    finishSchema();
    try {
        mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX);
        // Open tx2 should not make this possible
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    finishSchema();
    // Release transaction and wait a little for registration which should make enabling possible
    tx2.commit();
    mgmt.rollback();
    assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "theIndex").status(SchemaStatus.REGISTERED).timeout(TestGraphConfigs.getSchemaConvergenceTime(ChronoUnit.SECONDS), ChronoUnit.SECONDS).call().getSucceeded());
    finishSchema();
    mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX);
    finishSchema();
    tx2 = graph2.newTransaction();
    // Should be added to index but index not yet enabled
    tx2.addVertex("name", "v4");
    tx2.commit();
    newTx();
    evaluateQuery(tx.query().has("name", "v1"), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx.query().has("name", "v2"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx.query().has("name", "v3"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx.query().has("name", "v4"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
    tx2 = graph2.newTransaction();
    evaluateQuery(tx2.query().has("name", "v1"), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx2.query().has("name", "v2"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx2.query().has("name", "v3"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx2.query().has("name", "v4"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
    tx2.commit();
    // Finally test retrieving and closing open instances
    Set<String> openInstances = mgmt.getOpenInstances();
    assertEquals(2, openInstances.size());
    assertTrue(openInstances.contains(graph.getConfiguration().getUniqueGraphId() + "(current)"));
    assertTrue(openInstances.contains(graph2.getConfiguration().getUniqueGraphId()));
    try {
        mgmt.forceCloseInstance(graph.getConfiguration().getUniqueGraphId());
        // Cannot close current instance
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    mgmt.forceCloseInstance(graph2.getConfiguration().getUniqueGraphId());
    graph2.close();
}
Also used : JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 40 with StandardJanusGraph

use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.

the class AbstractConfiguredGraphFactoryTest method shouldOpenGraphUsingConfiguration.

@Test
public void shouldOpenGraphUsingConfiguration() throws Exception {
    final MapConfiguration graphConfig = getGraphConfig();
    final String graphName = graphConfig.getString(GRAPH_NAME.toStringWithoutRoot());
    try {
        ConfiguredGraphFactory.createConfiguration(graphConfig);
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.open(graphName);
        assertNotNull(graph);
    } finally {
        ConfiguredGraphFactory.removeConfiguration(graphName);
        ConfiguredGraphFactory.close(graphName);
    }
}
Also used : MapConfiguration(org.apache.commons.configuration2.MapConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test)

Aggregations

StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)68 Test (org.junit.jupiter.api.Test)38 MapConfiguration (org.apache.commons.configuration2.MapConfiguration)25 CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)18 GraphDatabaseConfigurationBuilder (org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder)18 HashMap (java.util.HashMap)13 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)9 Test (org.junit.Test)9 MapConfiguration (org.apache.commons.configuration.MapConfiguration)8 JanusGraphManager (org.janusgraph.graphdb.management.JanusGraphManager)8 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)6 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)6 PropertyKey (org.janusgraph.core.PropertyKey)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Graph (org.apache.tinkerpop.gremlin.structure.Graph)4 Backend (org.janusgraph.diskstorage.Backend)4 WriteConfiguration (org.janusgraph.diskstorage.configuration.WriteConfiguration)4 TimestampProvider (org.janusgraph.diskstorage.util.time.TimestampProvider)4 StandardJanusGraphTx (org.janusgraph.graphdb.transaction.StandardJanusGraphTx)4 JanusGraph (org.janusgraph.core.JanusGraph)3