Search in sources :

Example 36 with JanusGraphException

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

the class StandardIDPool method nextID.

@Override
public synchronized long nextID() {
    assert currentIndex <= currentBlock.numIds();
    if (currentIndex == currentBlock.numIds()) {
        try {
            nextBlock();
        } catch (InterruptedException e) {
            throw new JanusGraphException("Could not renew id block due to interruption", e);
        }
    }
    if (currentIndex == renewBlockIndex) {
        startIDBlockGetter();
    }
    long returnId = currentBlock.getId(currentIndex);
    currentIndex++;
    if (returnId >= idUpperBound)
        throw new IDPoolExhaustedException("Reached id upper bound of " + idUpperBound);
    log.trace("partition({})-namespace({}) Returned id: {}", partition, idNamespace, returnId);
    return returnId;
}
Also used : JanusGraphException(org.janusgraph.core.JanusGraphException)

Example 37 with JanusGraphException

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

the class ElasticsearchIndexTest method testErrorInBatch.

@Test
public void testErrorInBatch() throws Exception {
    initialize("vertex");
    Multimap<String, Object> doc1 = HashMultimap.create();
    doc1.put(TIME, "not a time");
    add("vertex", "failing-doc", doc1, true);
    add("vertex", "non-failing-doc", getRandomDocument(), true);
    JanusGraphException janusGraphException = assertThrows(JanusGraphException.class, () -> {
        tx.commit();
    }, "Commit should not have succeeded.");
    String message = Throwables.getRootCause(janusGraphException).getMessage();
    switch(JanusGraphElasticsearchContainer.getEsMajorVersion().value) {
        case 7:
        case 6:
            assertTrue(message.contains("mapper_parsing_exception"));
            break;
        case 5:
            assertTrue(message.contains("number_format_exception"));
            break;
        default:
            fail();
            break;
    }
    tx = null;
}
Also used : JanusGraphException(org.janusgraph.core.JanusGraphException) JSONObject(org.json.simple.JSONObject) Test(org.junit.jupiter.api.Test) IndexProviderTest(org.janusgraph.diskstorage.indexing.IndexProviderTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 38 with JanusGraphException

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

the class Backend method initialize.

/**
 * Initializes this backend with the given configuration. Must be called before this Backend can be used
 *
 * @param config
 */
public void initialize(Configuration config) {
    try {
        // EdgeStore & VertexIndexStore
        KeyColumnValueStore idStore = storeManager.openDatabase(config.get(IDS_STORE_NAME));
        idAuthority = null;
        if (storeFeatures.isKeyConsistent()) {
            idAuthority = new ConsistentKeyIDAuthority(idStore, storeManager, config);
        } else {
            throw new IllegalStateException("Store needs to support consistent key or transactional operations for ID manager to guarantee proper id allocations");
        }
        KeyColumnValueStore edgeStoreRaw = storeManagerLocking.openDatabase(EDGESTORE_NAME);
        KeyColumnValueStore indexStoreRaw = storeManagerLocking.openDatabase(INDEXSTORE_NAME);
        // Configure caches
        if (cacheEnabled) {
            long expirationTime = configuration.get(DB_CACHE_TIME);
            Preconditions.checkArgument(expirationTime >= 0, "Invalid cache expiration time: %s", expirationTime);
            if (expirationTime == 0)
                expirationTime = ETERNAL_CACHE_EXPIRATION;
            long cacheSizeBytes;
            double cacheSize = configuration.get(DB_CACHE_SIZE);
            Preconditions.checkArgument(cacheSize > 0.0, "Invalid cache size specified: %s", cacheSize);
            if (cacheSize < 1.0) {
                // Its a percentage
                Runtime runtime = Runtime.getRuntime();
                cacheSizeBytes = (long) ((runtime.maxMemory() - (runtime.totalMemory() - runtime.freeMemory())) * cacheSize);
            } else {
                Preconditions.checkArgument(cacheSize > 1000, "Cache size is too small: %s", cacheSize);
                cacheSizeBytes = (long) cacheSize;
            }
            log.info("Configuring total store cache size: {}", cacheSizeBytes);
            long cleanWaitTime = configuration.get(DB_CACHE_CLEAN_WAIT);
            Preconditions.checkArgument(EDGESTORE_CACHE_PERCENT + INDEXSTORE_CACHE_PERCENT == 1.0, "Cache percentages don't add up!");
            long edgeStoreCacheSize = Math.round(cacheSizeBytes * EDGESTORE_CACHE_PERCENT);
            long indexStoreCacheSize = Math.round(cacheSizeBytes * INDEXSTORE_CACHE_PERCENT);
            edgeStore = new ExpirationKCVSCache(edgeStoreRaw, getMetricsCacheName(EDGESTORE_NAME), expirationTime, cleanWaitTime, edgeStoreCacheSize);
            indexStore = new ExpirationKCVSCache(indexStoreRaw, getMetricsCacheName(INDEXSTORE_NAME), expirationTime, cleanWaitTime, indexStoreCacheSize);
        } else {
            edgeStore = new NoKCVSCache(edgeStoreRaw);
            indexStore = new NoKCVSCache(indexStoreRaw);
        }
        // Just open them so that they are cached
        txLogManager.openLog(SYSTEM_TX_LOG_NAME);
        managementLogManager.openLog(SYSTEM_MGMT_LOG_NAME);
        txLogStore = new NoKCVSCache(storeManager.openDatabase(SYSTEM_TX_LOG_NAME));
        // Open global configuration
        KeyColumnValueStore systemConfigStore = storeManagerLocking.openDatabase(SYSTEM_PROPERTIES_STORE_NAME);
        KCVSConfigurationBuilder kcvsConfigurationBuilder = new KCVSConfigurationBuilder();
        systemConfig = kcvsConfigurationBuilder.buildGlobalConfiguration(new BackendOperation.TransactionalProvider() {

            @Override
            public StoreTransaction openTx() throws BackendException {
                return storeManagerLocking.beginTransaction(StandardBaseTransactionConfig.of(configuration.get(TIMESTAMP_PROVIDER), storeFeatures.getKeyConsistentTxConfig()));
            }

            @Override
            public void close() throws BackendException {
            // Do nothing, storeManager is closed explicitly by Backend
            }
        }, systemConfigStore, configuration);
        userConfig = kcvsConfigurationBuilder.buildConfiguration(new BackendOperation.TransactionalProvider() {

            @Override
            public StoreTransaction openTx() throws BackendException {
                return storeManagerLocking.beginTransaction(StandardBaseTransactionConfig.of(configuration.get(TIMESTAMP_PROVIDER)));
            }

            @Override
            public void close() throws BackendException {
            // Do nothing, storeManager is closed explicitly by Backend
            }
        }, systemConfigStore, USER_CONFIGURATION_IDENTIFIER, configuration);
    } catch (BackendException e) {
        throw new JanusGraphException("Could not initialize backend", e);
    }
}
Also used : ConsistentKeyIDAuthority(org.janusgraph.diskstorage.idmanagement.ConsistentKeyIDAuthority) KCVSConfigurationBuilder(org.janusgraph.diskstorage.configuration.backend.builder.KCVSConfigurationBuilder) KeyColumnValueStore(org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore) NoKCVSCache(org.janusgraph.diskstorage.keycolumnvalue.cache.NoKCVSCache) ExpirationKCVSCache(org.janusgraph.diskstorage.keycolumnvalue.cache.ExpirationKCVSCache) JanusGraphException(org.janusgraph.core.JanusGraphException)

Example 39 with JanusGraphException

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

the class KCVSConfiguration method close.

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

Example 40 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)

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