Search in sources :

Example 16 with JanusGraphException

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

the class BackendTransaction method edgeStoreMultiQuery.

public Map<StaticBuffer, EntryList> edgeStoreMultiQuery(final List<StaticBuffer> keys, final SliceQuery query) {
    if (storeFeatures.hasMultiQuery()) {
        return executeRead(new Callable<Map<StaticBuffer, EntryList>>() {

            @Override
            public Map<StaticBuffer, EntryList> call() throws Exception {
                return cacheEnabled ? edgeStore.getSlice(keys, query, storeTx) : edgeStore.getSliceNoCache(keys, query, storeTx);
            }

            @Override
            public String toString() {
                return "MultiEdgeStoreQuery";
            }
        });
    } else {
        final Map<StaticBuffer, EntryList> results = new HashMap<>(keys.size());
        if (threadPool == null || keys.size() < MIN_TASKS_TO_PARALLELIZE) {
            for (StaticBuffer key : keys) {
                results.put(key, edgeStoreQuery(new KeySliceQuery(key, query)));
            }
        } else {
            final CountDownLatch doneSignal = new CountDownLatch(keys.size());
            final AtomicInteger failureCount = new AtomicInteger(0);
            EntryList[] resultArray = new EntryList[keys.size()];
            for (int i = 0; i < keys.size(); i++) {
                threadPool.execute(new SliceQueryRunner(new KeySliceQuery(keys.get(i), query), doneSignal, failureCount, resultArray, i));
            }
            try {
                doneSignal.await();
            } catch (InterruptedException e) {
                throw new JanusGraphException("Interrupted while waiting for multi-query to complete", e);
            }
            if (failureCount.get() > 0) {
                throw new JanusGraphException("Could not successfully complete multi-query. " + failureCount.get() + " individual queries failed.");
            }
            for (int i = 0; i < keys.size(); i++) {
                assert resultArray[i] != null;
                results.put(keys.get(i), resultArray[i]);
            }
        }
        return results;
    }
}
Also used : HashMap(java.util.HashMap) JanusGraphException(org.janusgraph.core.JanusGraphException) CountDownLatch(java.util.concurrent.CountDownLatch) TraversalInterruptedException(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalInterruptedException) TraversalInterruptedException(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalInterruptedException) JanusGraphException(org.janusgraph.core.JanusGraphException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) Map(java.util.Map) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)

Example 17 with JanusGraphException

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

the class KCVSConfiguration method close.

@Override
public void close() {
    try {
        store.close();
        txProvider.close();
        IOUtils.closeQuietly(serializer);
    } catch (BackendException e) {
        throw new JanusGraphException("Could not close configuration store", e);
    }
}
Also used : JanusGraphException(org.janusgraph.core.JanusGraphException) BackendException(org.janusgraph.diskstorage.BackendException)

Example 18 with JanusGraphException

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

the class IDPoolTest method testAllocationTimeoutAndRecovery.

@Test
public void testAllocationTimeoutAndRecovery() throws BackendException {
    IMocksControl ctrl = EasyMock.createStrictControl();
    final int partition = 42;
    final int idNamespace = 777;
    final Duration timeout = Duration.ofSeconds(1L);
    final IDAuthority mockAuthority = ctrl.createMock(IDAuthority.class);
    // Sleep for two seconds, then throw a BackendException
    // this whole delegate could be deleted if we abstracted StandardIDPool's internal executor and stopwatches
    expect(mockAuthority.getIDBlock(partition, idNamespace, timeout)).andDelegateTo(new IDAuthority() {

        @Override
        public IDBlock getIDBlock(int partition, int idNamespace, Duration timeout) throws BackendException {
            try {
                Thread.sleep(2000L);
            } catch (InterruptedException e) {
                fail();
            }
            throw new TemporaryBackendException("slow backend");
        }

        @Override
        public List<KeyRange> getLocalIDPartition() {
            throw new IllegalArgumentException();
        }

        @Override
        public void setIDBlockSizer(IDBlockSizer sizer) {
            throw new IllegalArgumentException();
        }

        @Override
        public void close() {
            throw new IllegalArgumentException();
        }

        @Override
        public String getUniqueID() {
            throw new IllegalArgumentException();
        }

        @Override
        public boolean supportsInterruption() {
            return true;
        }
    });
    expect(mockAuthority.getIDBlock(partition, idNamespace, timeout)).andReturn(new IDBlock() {

        @Override
        public long numIds() {
            return 2;
        }

        @Override
        public long getId(long index) {
            return 200;
        }
    });
    expect(mockAuthority.supportsInterruption()).andStubReturn(true);
    ctrl.replay();
    StandardIDPool pool = new StandardIDPool(mockAuthority, partition, idNamespace, Integer.MAX_VALUE, timeout, 0.1);
    try {
        pool.nextID();
        fail();
    } catch (JanusGraphException ignored) {
    }
    long nextID = pool.nextID();
    assertEquals(200, nextID);
    ctrl.verify();
}
Also used : IDBlockSizer(org.janusgraph.graphdb.database.idassigner.IDBlockSizer) JanusGraphException(org.janusgraph.core.JanusGraphException) Duration(java.time.Duration) BackendException(org.janusgraph.diskstorage.BackendException) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) IMocksControl(org.easymock.IMocksControl) StandardIDPool(org.janusgraph.graphdb.database.idassigner.StandardIDPool) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) IDAuthority(org.janusgraph.diskstorage.IDAuthority) IDBlock(org.janusgraph.diskstorage.IDBlock) List(java.util.List) Test(org.junit.Test)

Example 19 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()) {
        PropertyKey stringProperty = mgmt.makePropertyKey("name").dataType(String.class).cardinality(cardinality).make();
        PropertyKey intProperty = mgmt.makePropertyKey("age").dataType(Integer.class).cardinality(cardinality).make();
        PropertyKey longProperty = mgmt.makePropertyKey("long").dataType(Long.class).cardinality(cardinality).make();
        PropertyKey uuidProperty = mgmt.makePropertyKey("uuid").dataType(UUID.class).cardinality(cardinality).make();
        PropertyKey geopointProperty = mgmt.makePropertyKey("geopoint").dataType(Geoshape.class).cardinality(cardinality).make();
        mgmt.buildIndex("collectionIndex", Vertex.class).addKey(stringProperty, getStringMapping()).addKey(intProperty).addKey(longProperty).addKey(uuidProperty).addKey(geopointProperty).buildMixedIndex(INDEX);
        finishSchema();
        testCollection(cardinality, "name", "Totoro", "Hiro");
        testCollection(cardinality, "age", 1, 2);
        testCollection(cardinality, "long", 1L, 2L);
        testCollection(cardinality, "geopoint", Geoshape.point(1.0, 1.0), Geoshape.point(2.0, 2.0));
        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 {
            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);
            Assert.fail("Should have thrown an exception");
        } catch (JanusGraphException ignored) {
        }
    }
}
Also used : JanusGraphException(org.janusgraph.core.JanusGraphException) PropertyKey(org.janusgraph.core.PropertyKey)

Aggregations

JanusGraphException (org.janusgraph.core.JanusGraphException)19 BackendException (org.janusgraph.diskstorage.BackendException)4 PropertyKey (org.janusgraph.core.PropertyKey)3 Instant (java.time.Instant)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)2 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)2 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)2 RelationTypeIndex (org.janusgraph.core.schema.RelationTypeIndex)2 StandardScanner (org.janusgraph.diskstorage.keycolumnvalue.scan.StandardScanner)2 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)2 Function (com.google.common.base.Function)1 Preconditions (com.google.common.base.Preconditions)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Duration (java.time.Duration)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1