Search in sources :

Example 21 with JanusGraphException

use of org.janusgraph.core.JanusGraphException in project janusgraph by JanusGraph.

the class JanusGraphIndexTest method shouldUpdateIndexFieldsAfterIndexModification.

@RepeatedIfExceptionsTest(repeats = 4, minSuccess = 2)
public void shouldUpdateIndexFieldsAfterIndexModification() throws InterruptedException, ExecutionException {
    clopen(option(FORCE_INDEX_USAGE), true, option(LOG_READ_INTERVAL, MANAGEMENT_LOG), Duration.ofMillis(5000));
    String key1 = "testKey1";
    String key2 = "testKey2";
    String key3 = "testKey3";
    String vertexL = "testVertexLabel";
    String indexName = "mixed";
    PropertyKey p1 = mgmt.makePropertyKey(key1).dataType(Long.class).make();
    PropertyKey p2 = mgmt.makePropertyKey(key2).dataType(Long.class).make();
    mgmt.makeVertexLabel(vertexL).make();
    JanusGraphIndex index = mgmt.buildIndex(indexName, Vertex.class).indexOnly(mgmt.getVertexLabel(vertexL)).addKey(mgmt.getPropertyKey(key1)).addKey(mgmt.getPropertyKey(key2)).buildMixedIndex(INDEX);
    if (index.getIndexStatus(p1) == SchemaStatus.INSTALLED) {
        mgmt.updateIndex(mgmt.getGraphIndex(indexName), SchemaAction.REGISTER_INDEX).get();
        mgmt.updateIndex(mgmt.getGraphIndex(indexName), SchemaAction.ENABLE_INDEX).get();
    } else if (index.getIndexStatus(p1) == SchemaStatus.REGISTERED) {
        mgmt.updateIndex(mgmt.getGraphIndex(indexName), SchemaAction.ENABLE_INDEX).get();
    }
    mgmt.commit();
    JanusGraphVertex vertex = graph.addVertex(vertexL);
    vertex.property(key1, 111L);
    vertex.property(key2, 222L);
    graph.tx().commit();
    // By default ES indexes documents each second. By sleeping here we guarantee that documents are indexed.
    // It is just for testing. A better approach is to use Refresh API.
    Thread.sleep(1500L);
    // we open an implicit transaction and do not commit/rollback it by intention, so that we can ensure
    // adding new property to the index wouldn't cause existing transactions to fail
    assertEquals(1, graph.traversal().V().hasLabel(vertexL).has(key1, 111L).count().next());
    assertEquals(1, graph.traversal().V().hasLabel(vertexL).has(key1, 111L).toList().size());
    JanusGraph graph2 = JanusGraphFactory.open(config);
    assertEquals(1, graph2.traversal().V().hasLabel(vertexL).has(key1, 111L).count().next());
    assertEquals(1, graph2.traversal().V().hasLabel(vertexL).has(key1, 111L).toList().size());
    mgmt = graph.openManagement();
    PropertyKey testKey3 = mgmt.makePropertyKey(key3).dataType(Long.class).make();
    mgmt.addIndexKey(mgmt.getGraphIndex(indexName), testKey3);
    mgmt.commit();
    ManagementSystem.awaitGraphIndexStatus(graph, indexName).status(SchemaStatus.REGISTERED, SchemaStatus.ENABLED).call();
    mgmt = graph.openManagement();
    mgmt.updateIndex(mgmt.getGraphIndex(indexName), SchemaAction.REINDEX).get();
    mgmt.commit();
    graph.addVertex(T.label, vertexL, key1, 1L, key2, 2L, key3, 3L);
    graph.tx().commit();
    assertTrue(graph.traversal().V().hasLabel(vertexL).has(key3, 3L).hasNext());
    try {
        graph2.addVertex(T.label, vertexL, key1, 1L, key2, 2L, key3, 3L);
        // this assertion might be flaky which is why we mark this test as RepeatedIfExceptionsTest.
        // the reason is, we cannot make sure when the schema update broadcast will be received by the graph2
        // instance.
        JanusGraphException ex = assertThrows(JanusGraphException.class, () -> graph2.tx().commit());
        assertEquals("testKey3 is not available in mixed index mixed", ex.getCause().getMessage());
        // graph2 needs some time to read from ManagementLogger asynchronously and updates cache
        // LOG_READ_INTERVAL is 5 seconds, so we wait for the same time here to ensure periodic read is triggered
        Thread.sleep(5000);
        graph2.tx().commit();
        assertTrue(graph2.traversal().V().hasLabel(vertexL).has(key3, 3L).hasNext());
    } finally {
        graph2.close();
    }
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) JanusGraph(org.janusgraph.core.JanusGraph) JanusGraphException(org.janusgraph.core.JanusGraphException) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) RepeatedIfExceptionsTest(io.github.artsok.RepeatedIfExceptionsTest)

Example 22 with JanusGraphException

use of org.janusgraph.core.JanusGraphException in project janusgraph by JanusGraph.

the class GraphDatabaseConfigurationInstanceIdTest method graphShouldNotOpenWithSameInstanceId.

@Disabled("Not working anymore. The bug is tracked here: https://github.com/JanusGraph/janusgraph/issues/2696")
@Test
public void graphShouldNotOpenWithSameInstanceId() {
    final Map<String, Object> map = getStorageConfiguration();
    map.put(UNIQUE_INSTANCE_ID.toStringWithoutRoot(), NON_UNIQUE_INSTANCE_ID);
    final MapConfiguration config = ConfigurationUtil.loadMapConfiguration(map);
    final StandardJanusGraph graph1 = new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(new CommonsConfiguration(config)));
    assertEquals(1, graph1.openManagement().getOpenInstances().size());
    assertEquals(NON_UNIQUE_CURRENT_INSTANCE_ID, graph1.openManagement().getOpenInstances().iterator().next());
    JanusGraphException janusGraphException = assertThrows(JanusGraphException.class, () -> {
        final StandardJanusGraph graph2 = new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(new CommonsConfiguration(config)));
        graph1.close();
    });
    assertEquals("A JanusGraph graph with the same instance id [" + NON_UNIQUE_INSTANCE_ID + "] is already open. Might required forced shutdown.", janusGraphException.getMessage());
}
Also used : GraphDatabaseConfigurationBuilder(org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) JanusGraphException(org.janusgraph.core.JanusGraphException) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 23 with JanusGraphException

use of org.janusgraph.core.JanusGraphException in project janusgraph by JanusGraph.

the class JanusGraphBaseTest method closeLogs.

private void closeLogs() {
    try {
        for (final LogManager lm : logManagers.values()) lm.close();
        logManagers.clear();
        if (logStoreManager != null) {
            logStoreManager.close();
            logStoreManager = null;
        }
    } catch (final BackendException e) {
        throw new JanusGraphException(e);
    }
}
Also used : JanusGraphException(org.janusgraph.core.JanusGraphException) LogManager(org.janusgraph.diskstorage.log.LogManager) KCVSLogManager(org.janusgraph.diskstorage.log.kcvs.KCVSLogManager) BackendException(org.janusgraph.diskstorage.BackendException)

Example 24 with JanusGraphException

use of org.janusgraph.core.JanusGraphException in project janusgraph by JanusGraph.

the class JanusGraphIndexTest method testIndexing.

private void testIndexing(Cardinality cardinality) {
    if (supportsCollections()) {
        final PropertyKey stringProperty = mgmt.makePropertyKey("name").dataType(String.class).cardinality(cardinality).make();
        final PropertyKey intProperty = mgmt.makePropertyKey("age").dataType(Integer.class).cardinality(cardinality).make();
        final PropertyKey longProperty = mgmt.makePropertyKey("long").dataType(Long.class).cardinality(cardinality).make();
        final PropertyKey uuidProperty = mgmt.makePropertyKey("uuid").dataType(UUID.class).cardinality(cardinality).make();
        JanusGraphManagement.IndexBuilder indexBuilder = mgmt.buildIndex("collectionIndex", Vertex.class).addKey(stringProperty, getStringMapping()).addKey(intProperty).addKey(longProperty).addKey(uuidProperty);
        if (supportsGeoCollections()) {
            final PropertyKey geopointProperty = mgmt.makePropertyKey("geopoint").dataType(Geoshape.class).cardinality(cardinality).make();
            indexBuilder.addKey(geopointProperty);
        }
        indexBuilder.buildMixedIndex(INDEX);
        finishSchema();
        testCollection(cardinality, "name", "Totoro", "Hiro");
        testCollection(cardinality, "age", 1, 2);
        testCollection(cardinality, "long", 1L, 2L);
        if (supportsGeoCollections()) {
            testCollection(cardinality, "geopoint", Geoshape.point(1.0, 1.0), Geoshape.point(2.0, 2.0));
        }
        final String backend = readConfig.get(INDEX_BACKEND, INDEX);
        // https://issues.apache.org/jira/browse/SOLR-11264
        if (!"solr".equals(backend)) {
            testCollection(cardinality, "uuid", UUID.randomUUID(), UUID.randomUUID());
        }
    } else {
        try {
            final PropertyKey stringProperty = mgmt.makePropertyKey("name").dataType(String.class).cardinality(cardinality).make();
            // This should throw an exception
            mgmt.buildIndex("collectionIndex", Vertex.class).addKey(stringProperty, getStringMapping()).buildMixedIndex(INDEX);
            fail("Should have thrown an exception");
        } catch (final JanusGraphException ignored) {
        }
    }
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) JanusGraphException(org.janusgraph.core.JanusGraphException) PropertyKey(org.janusgraph.core.PropertyKey)

Example 25 with JanusGraphException

use of org.janusgraph.core.JanusGraphException in project janusgraph by JanusGraph.

the class JanusGraphVertexStep method prefetchNextBatch.

/**
 * This initialisation method is called when an attempt to retrieve a vertex from the cached multiQuery results
 * doesn't find an entry.
 */
private void prefetchNextBatch(final Traverser.Admin<Vertex> traverser) {
    final JanusGraphMultiVertexQuery multiQuery = JanusGraphTraversalUtil.getTx(getTraversal()).multiQuery();
    if (verticesToPrefetch.isEmpty()) {
        multiQuery.addVertex(JanusGraphTraversalUtil.getJanusGraphVertex(traverser));
    } else {
        multiQuery.addAllVertices(verticesToPrefetch);
        verticesToPrefetch.clear();
    }
    makeQuery(multiQuery);
    try {
        multiQueryResults = (Vertex.class.isAssignableFrom(getReturnClass())) ? multiQuery.vertices() : multiQuery.edges();
    } catch (JanusGraphException janusGraphException) {
        if (janusGraphException.isCausedBy(InterruptedException.class)) {
            throw new TraversalInterruptedException();
        }
    }
}
Also used : JanusGraphMultiVertexQuery(org.janusgraph.core.JanusGraphMultiVertexQuery) TraversalInterruptedException(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalInterruptedException) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) JanusGraphException(org.janusgraph.core.JanusGraphException) TraversalInterruptedException(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalInterruptedException)

Aggregations

JanusGraphException (org.janusgraph.core.JanusGraphException)46 BackendException (org.janusgraph.diskstorage.BackendException)18 PropertyKey (org.janusgraph.core.PropertyKey)9 Test (org.junit.jupiter.api.Test)7 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)6 StandardScanner (org.janusgraph.diskstorage.keycolumnvalue.scan.StandardScanner)6 Set (java.util.Set)5 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)5 CompositeIndexType (org.janusgraph.graphdb.types.CompositeIndexType)5 IndexType (org.janusgraph.graphdb.types.IndexType)5 MixedIndexType (org.janusgraph.graphdb.types.MixedIndexType)5 RepeatedIfExceptionsTest (io.github.artsok.RepeatedIfExceptionsTest)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ExecutionException (java.util.concurrent.ExecutionException)4 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)4 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)4 RelationTypeIndex (org.janusgraph.core.schema.RelationTypeIndex)4 ScanMetrics (org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics)4