Search in sources :

Example 36 with BackendException

use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.

the class StandardJanusGraph method newTransaction.

public StandardJanusGraphTx newTransaction(final TransactionConfiguration configuration) {
    if (!isOpen)
        ExceptionFactory.graphShutdown();
    try {
        StandardJanusGraphTx tx = new StandardJanusGraphTx(this, configuration);
        tx.setBackendTransaction(openBackendTransaction(tx));
        openTransactions.add(tx);
        return tx;
    } catch (BackendException e) {
        throw new JanusGraphException("Could not start new transaction", e);
    }
}
Also used : StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) JanusGraphException(org.janusgraph.core.JanusGraphException) BackendException(org.janusgraph.diskstorage.BackendException)

Example 37 with BackendException

use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.

the class StandardLogProcessorFramework method shutdown.

@Override
public synchronized void shutdown() throws JanusGraphException {
    if (!isOpen)
        return;
    isOpen = false;
    try {
        ExceptionWrapper exceptionWrapper = new ExceptionWrapper();
        for (Log log : processorLogs.values()) {
            ExecuteUtil.executeWithCatching(log::close, exceptionWrapper);
        }
        ExecuteUtil.throwIfException(exceptionWrapper);
        processorLogs.clear();
    } catch (BackendException e) {
        throw new JanusGraphException(e);
    }
}
Also used : Log(org.janusgraph.diskstorage.log.Log) JanusGraphException(org.janusgraph.core.JanusGraphException) ExceptionWrapper(org.janusgraph.util.datastructures.ExceptionWrapper) BackendException(org.janusgraph.diskstorage.BackendException)

Example 38 with BackendException

use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.

the class IndexRepairJob method workerIterationEnd.

@Override
public void workerIterationEnd(final ScanMetrics metrics) {
    try {
        if (index instanceof JanusGraphIndex) {
            BackendTransaction mutator = writeTx.getTxHandle();
            IndexType indexType = managementSystem.getSchemaVertex(index).asIndexType();
            if (indexType.isMixedIndex() && documentsPerStore.size() > 0) {
                mutator.getIndexTransaction(indexType.getBackingIndexName()).restore(documentsPerStore);
                documentsPerStore = new HashMap<>();
            }
        }
    } catch (BackendException e) {
        throw new JanusGraphException(e.getMessage(), e);
    } finally {
        super.workerIterationEnd(metrics);
    }
}
Also used : JanusGraphException(org.janusgraph.core.JanusGraphException) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) MixedIndexType(org.janusgraph.graphdb.types.MixedIndexType) IndexType(org.janusgraph.graphdb.types.IndexType) CompositeIndexType(org.janusgraph.graphdb.types.CompositeIndexType) BackendTransaction(org.janusgraph.diskstorage.BackendTransaction) BackendException(org.janusgraph.diskstorage.BackendException)

Example 39 with BackendException

use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.

the class ElasticSearchIndex method getNewDocument.

public Map<String, Object> getNewDocument(final List<IndexEntry> additions, KeyInformation.StoreRetriever information) throws BackendException {
    // JSON writes duplicate fields one after another, which forces us
    // at this stage to make de-duplication on the IndexEntry list. We don't want to pay the
    // price map storage on the Mutation level because none of other backends need that.
    final Multimap<String, IndexEntry> unique = LinkedListMultimap.create();
    for (final IndexEntry e : additions) {
        unique.put(e.field, e);
    }
    final Map<String, Object> doc = new HashMap<>();
    for (final Map.Entry<String, Collection<IndexEntry>> add : unique.asMap().entrySet()) {
        final KeyInformation keyInformation = information.get(add.getKey());
        final Object value;
        switch(keyInformation.getCardinality()) {
            case SINGLE:
                value = convertToEsType(Iterators.getLast(add.getValue().iterator()).value, Mapping.getMapping(keyInformation));
                break;
            case SET:
            case LIST:
                value = add.getValue().stream().map(v -> convertToEsType(v.value, Mapping.getMapping(keyInformation))).filter(v -> {
                    Preconditions.checkArgument(!(v instanceof byte[]), "Collections not supported for %s", add.getKey());
                    return true;
                }).toArray();
                break;
            default:
                value = null;
                break;
        }
        doc.put(add.getKey(), value);
        if (hasDualStringMapping(information.get(add.getKey())) && keyInformation.getDataType() == String.class) {
            doc.put(getDualMappingName(add.getKey()), value);
        }
    }
    return doc;
}
Also used : PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) INDEX_MAX_RESULT_SET_SIZE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INDEX_MAX_RESULT_SET_SIZE) Arrays(java.util.Arrays) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) Date(java.util.Date) Spliterators(java.util.Spliterators) ES_LANG_KEY(org.janusgraph.diskstorage.es.ElasticSearchConstants.ES_LANG_KEY) LoggerFactory(org.slf4j.LoggerFactory) ConfigOption(org.janusgraph.diskstorage.configuration.ConfigOption) Geoshape(org.janusgraph.core.attribute.Geoshape) AbstractESCompat(org.janusgraph.diskstorage.es.compat.AbstractESCompat) ESCompatUtils(org.janusgraph.diskstorage.es.compat.ESCompatUtils) BaseTransaction(org.janusgraph.diskstorage.BaseTransaction) IndexProvider(org.janusgraph.diskstorage.indexing.IndexProvider) Cardinality(org.janusgraph.core.Cardinality) IndexEntry(org.janusgraph.diskstorage.indexing.IndexEntry) KeyInformation(org.janusgraph.diskstorage.indexing.KeyInformation) Map(java.util.Map) IndexQuery(org.janusgraph.diskstorage.indexing.IndexQuery) LinkedListMultimap(com.google.common.collect.LinkedListMultimap) And(org.janusgraph.graphdb.query.condition.And) Mapping(org.janusgraph.core.schema.Mapping) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ES_GEO_COORDS_KEY(org.janusgraph.diskstorage.es.ElasticSearchConstants.ES_GEO_COORDS_KEY) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) List(java.util.List) ES_SCRIPT_KEY(org.janusgraph.diskstorage.es.ElasticSearchConstants.ES_SCRIPT_KEY) Parameter(org.janusgraph.core.schema.Parameter) Stream(java.util.stream.Stream) INDEX_NAME(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INDEX_NAME) HttpAuthTypes(org.janusgraph.diskstorage.es.rest.util.HttpAuthTypes) Spliterator(java.util.Spliterator) PreInitializeConfigOptions(org.janusgraph.graphdb.configuration.PreInitializeConfigOptions) Not(org.janusgraph.graphdb.query.condition.Not) IntStream(java.util.stream.IntStream) ConfigNamespace(org.janusgraph.diskstorage.configuration.ConfigNamespace) Condition(org.janusgraph.graphdb.query.condition.Condition) AttributeUtils(org.janusgraph.graphdb.database.serialize.AttributeUtils) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) Iterators(com.google.common.collect.Iterators) ArrayList(java.util.ArrayList) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) Rectangle(org.locationtech.spatial4j.shape.Rectangle) ImmutableList(com.google.common.collect.ImmutableList) Cmp(org.janusgraph.core.attribute.Cmp) IndexFeatures(org.janusgraph.diskstorage.indexing.IndexFeatures) Or(org.janusgraph.graphdb.query.condition.Or) JanusGraphException(org.janusgraph.core.JanusGraphException) StreamSupport(java.util.stream.StreamSupport) Geo(org.janusgraph.core.attribute.Geo) BackendException(org.janusgraph.diskstorage.BackendException) JanusGraphPredicate(org.janusgraph.graphdb.query.JanusGraphPredicate) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Configuration(org.janusgraph.diskstorage.configuration.Configuration) BaseTransactionConfigurable(org.janusgraph.diskstorage.BaseTransactionConfigurable) RawQuery(org.janusgraph.diskstorage.indexing.RawQuery) ES_TYPE_KEY(org.janusgraph.diskstorage.es.ElasticSearchConstants.ES_TYPE_KEY) IOException(java.io.IOException) DefaultTransaction(org.janusgraph.diskstorage.util.DefaultTransaction) ES_DOC_KEY(org.janusgraph.diskstorage.es.ElasticSearchConstants.ES_DOC_KEY) Text(org.janusgraph.core.attribute.Text) BaseTransactionConfig(org.janusgraph.diskstorage.BaseTransactionConfig) ESScriptResponse(org.janusgraph.diskstorage.es.script.ESScriptResponse) ConfigOption.disallowEmpty(org.janusgraph.diskstorage.configuration.ConfigOption.disallowEmpty) Preconditions(com.google.common.base.Preconditions) IndexMapping(org.janusgraph.diskstorage.es.mapping.IndexMapping) ParameterType(org.janusgraph.graphdb.types.ParameterType) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) INDEX_NS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INDEX_NS) IndexMutation(org.janusgraph.diskstorage.indexing.IndexMutation) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IndexEntry(org.janusgraph.diskstorage.indexing.IndexEntry) Collection(java.util.Collection) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) KeyInformation(org.janusgraph.diskstorage.indexing.KeyInformation)

Example 40 with BackendException

use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.

the class ElasticSearchIndex method mutate.

@Override
public void mutate(Map<String, Map<String, IndexMutation>> mutations, KeyInformation.IndexRetriever information, BaseTransaction tx) throws BackendException {
    final List<ElasticSearchMutation> requests = new ArrayList<>();
    try {
        for (final Map.Entry<String, Map<String, IndexMutation>> stores : mutations.entrySet()) {
            final List<ElasticSearchMutation> requestByStore = new ArrayList<>();
            final String storeName = stores.getKey();
            final String indexStoreName = getIndexStoreName(storeName);
            for (final Map.Entry<String, IndexMutation> entry : stores.getValue().entrySet()) {
                final String documentId = entry.getKey();
                final IndexMutation mutation = entry.getValue();
                assert mutation.isConsolidated();
                Preconditions.checkArgument(!(mutation.isNew() && mutation.isDeleted()));
                Preconditions.checkArgument(!mutation.isNew() || !mutation.hasDeletions());
                Preconditions.checkArgument(!mutation.isDeleted() || !mutation.hasAdditions());
                // Deletions first
                if (mutation.hasDeletions()) {
                    if (mutation.isDeleted()) {
                        log.trace("Deleting entire document {}", documentId);
                        requestByStore.add(ElasticSearchMutation.createDeleteRequest(indexStoreName, storeName, documentId));
                    } else {
                        List<Map<String, Object>> params = getParameters(information.get(storeName), mutation.getDeletions(), true);
                        Map doc = compat.prepareStoredScript(parameterizedDeletionScriptId, params).build();
                        log.trace("Deletion script {} with params {}", PARAMETERIZED_DELETION_SCRIPT, params);
                        requestByStore.add(ElasticSearchMutation.createUpdateRequest(indexStoreName, storeName, documentId, doc));
                    }
                }
                if (mutation.hasAdditions()) {
                    if (mutation.isNew()) {
                        // Index
                        log.trace("Adding entire document {}", documentId);
                        final Map<String, Object> source = getNewDocument(mutation.getAdditions(), information.get(storeName));
                        requestByStore.add(ElasticSearchMutation.createIndexRequest(indexStoreName, storeName, documentId, source));
                    } else {
                        final Map upsert;
                        if (!mutation.hasDeletions()) {
                            upsert = getNewDocument(mutation.getAdditions(), information.get(storeName));
                        } else {
                            upsert = null;
                        }
                        List<Map<String, Object>> params = getParameters(information.get(storeName), mutation.getAdditions(), false, Cardinality.SINGLE);
                        if (!params.isEmpty()) {
                            ImmutableMap.Builder builder = compat.prepareStoredScript(parameterizedAdditionScriptId, params);
                            requestByStore.add(ElasticSearchMutation.createUpdateRequest(indexStoreName, storeName, documentId, builder, upsert));
                            log.trace("Adding script {} with params {}", PARAMETERIZED_ADDITION_SCRIPT, params);
                        }
                        final Map<String, Object> doc = getAdditionDoc(information, storeName, mutation);
                        if (!doc.isEmpty()) {
                            final ImmutableMap.Builder builder = ImmutableMap.builder().put(ES_DOC_KEY, doc);
                            requestByStore.add(ElasticSearchMutation.createUpdateRequest(indexStoreName, storeName, documentId, builder, upsert));
                            log.trace("Adding update {}", doc);
                        }
                    }
                }
            }
            if (!requestByStore.isEmpty() && ingestPipelines.containsKey(storeName)) {
                client.bulkRequest(requestByStore, String.valueOf(ingestPipelines.get(storeName)));
            } else if (!requestByStore.isEmpty()) {
                requests.addAll(requestByStore);
            }
        }
        if (!requests.isEmpty()) {
            client.bulkRequest(requests, null);
        }
    } catch (final Exception e) {
        log.error("Failed to execute bulk Elasticsearch mutation", e);
        throw convert(e);
    }
}
Also used : ArrayList(java.util.ArrayList) ImmutableMap(com.google.common.collect.ImmutableMap) UncheckedIOException(java.io.UncheckedIOException) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) JanusGraphException(org.janusgraph.core.JanusGraphException) BackendException(org.janusgraph.diskstorage.BackendException) IOException(java.io.IOException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) IndexMutation(org.janusgraph.diskstorage.indexing.IndexMutation) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Aggregations

BackendException (org.janusgraph.diskstorage.BackendException)62 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)26 TemporaryBackendException (org.janusgraph.diskstorage.TemporaryBackendException)18 JanusGraphException (org.janusgraph.core.JanusGraphException)17 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)16 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)16 ArrayList (java.util.ArrayList)14 List (java.util.List)13 Map (java.util.Map)12 Duration (java.time.Duration)11 HashMap (java.util.HashMap)11 Configuration (org.janusgraph.diskstorage.configuration.Configuration)11 Entry (org.janusgraph.diskstorage.Entry)10 Test (org.junit.jupiter.api.Test)10 BaseTransactionConfig (org.janusgraph.diskstorage.BaseTransactionConfig)9 BackendOperation (org.janusgraph.diskstorage.util.BackendOperation)9 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)9 IOException (java.io.IOException)8 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)8 Preconditions (com.google.common.base.Preconditions)6