Search in sources :

Example 1 with StandardJanusGraphTx

use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.

the class RelationTypeIndexWrapper method getSortKey.

@Override
public RelationType[] getSortKey() {
    StandardJanusGraphTx tx = type.tx();
    long[] ids = type.getSortKey();
    RelationType[] keys = new RelationType[ids.length];
    for (int i = 0; i < keys.length; i++) {
        keys[i] = tx.getExistingRelationType(ids[i]);
    }
    return keys;
}
Also used : StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) RelationType(org.janusgraph.core.RelationType) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType)

Example 2 with StandardJanusGraphTx

use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.

the class StandardTransactionLogProcessor method restoreExternalIndexes.

private void restoreExternalIndexes(Predicate<String> isFailedIndex, TransactionLogHeader.Entry entry) {
    // 1) Collect all elements (vertices and relations) and the indexes for which they need to be restored
    SetMultimap<String, IndexRestore> indexRestores = HashMultimap.create();
    BackendOperation.execute(() -> {
        final StandardJanusGraphTx tx = (StandardJanusGraphTx) graph.newTransaction();
        try {
            entry.getContentAsModifications(serializer).stream().map(m -> ModificationDeserializer.parseRelation(m, tx)).forEach(rel -> {
                // Collect affected vertex indexes
                for (final MixedIndexType index : getMixedIndexes(rel.getType())) {
                    if (index.getElement() == ElementCategory.VERTEX && isFailedIndex.apply(index.getBackingIndexName())) {
                        assert rel.isProperty();
                        indexRestores.put(index.getBackingIndexName(), new IndexRestore(rel.getVertex(0).longId(), ElementCategory.VERTEX, getIndexId(index)));
                    }
                }
                // See if relation itself is affected
                for (final RelationType relType : rel.getPropertyKeysDirect()) {
                    for (final MixedIndexType index : getMixedIndexes(relType)) {
                        if (index.getElement().isInstance(rel) && isFailedIndex.apply(index.getBackingIndexName())) {
                            assert rel.id() instanceof RelationIdentifier;
                            indexRestores.put(index.getBackingIndexName(), new IndexRestore(rel.id(), ElementCategory.getByClazz(rel.getClass()), getIndexId(index)));
                        }
                    }
                }
            });
        } finally {
            if (tx.isOpen())
                tx.rollback();
        }
        return true;
    }, readTime);
    // 2) Restore elements per backing index
    for (final String indexName : indexRestores.keySet()) {
        final StandardJanusGraphTx tx = (StandardJanusGraphTx) graph.newTransaction();
        try {
            BackendTransaction btx = tx.getTxHandle();
            final IndexTransaction indexTx = btx.getIndexTransaction(indexName);
            BackendOperation.execute(new Callable<Boolean>() {

                @Override
                public Boolean call() throws Exception {
                    Map<String, Map<String, List<IndexEntry>>> restoredDocs = Maps.newHashMap();
                    indexRestores.get(indexName).forEach(restore -> {
                        JanusGraphSchemaVertex indexV = (JanusGraphSchemaVertex) tx.getVertex(restore.indexId);
                        MixedIndexType index = (MixedIndexType) indexV.asIndexType();
                        JanusGraphElement element = restore.retrieve(tx);
                        if (element != null) {
                            graph.getIndexSerializer().reindexElement(element, index, restoredDocs);
                        } else {
                            // Element is deleted
                            graph.getIndexSerializer().removeElement(restore.elementId, index, restoredDocs);
                        }
                    });
                    indexTx.restore(restoredDocs);
                    indexTx.commit();
                    return true;
                }

                @Override
                public String toString() {
                    return "IndexMutation";
                }
            }, persistenceTime);
        } finally {
            if (tx.isOpen())
                tx.rollback();
        }
    }
}
Also used : SchemaSource(org.janusgraph.graphdb.types.SchemaSource) org.janusgraph.diskstorage.log(org.janusgraph.diskstorage.log) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) BackgroundThread(org.janusgraph.util.system.BackgroundThread) BackendOperation(org.janusgraph.diskstorage.util.BackendOperation) LoggerFactory(org.slf4j.LoggerFactory) IndexTransaction(org.janusgraph.diskstorage.indexing.IndexTransaction) HashCodeBuilder(org.apache.commons.lang.builder.HashCodeBuilder) Callable(java.util.concurrent.Callable) IndexTypeWrapper(org.janusgraph.graphdb.types.indextype.IndexTypeWrapper) JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) Future(java.util.concurrent.Future) Serializer(org.janusgraph.graphdb.database.serialize.Serializer) IndexEntry(org.janusgraph.diskstorage.indexing.IndexEntry) Duration(java.time.Duration) Map(java.util.Map) Predicates(com.google.common.base.Predicates) MixedIndexType(org.janusgraph.graphdb.types.MixedIndexType) JanusGraphException(org.janusgraph.core.JanusGraphException) IndexType(org.janusgraph.graphdb.types.IndexType) com.google.common.collect(com.google.common.collect) LogTxStatus(org.janusgraph.graphdb.database.log.LogTxStatus) JanusGraphElement(org.janusgraph.core.JanusGraphElement) TransactionLogHeader(org.janusgraph.graphdb.database.log.TransactionLogHeader) TransactionRecovery(org.janusgraph.core.log.TransactionRecovery) RelationType(org.janusgraph.core.RelationType) Logger(org.slf4j.Logger) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) JanusGraphSchemaVertex(org.janusgraph.graphdb.types.vertices.JanusGraphSchemaVertex) LogTxMeta(org.janusgraph.graphdb.database.log.LogTxMeta) Instant(java.time.Instant) ElementCategory(org.janusgraph.graphdb.internal.ElementCategory) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) com.google.common.cache(com.google.common.cache) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) RelationIdentifier(org.janusgraph.graphdb.relations.RelationIdentifier) Predicate(com.google.common.base.Predicate) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) Preconditions(com.google.common.base.Preconditions) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) Collections(java.util.Collections) org.janusgraph.diskstorage(org.janusgraph.diskstorage) MixedIndexType(org.janusgraph.graphdb.types.MixedIndexType) IndexTransaction(org.janusgraph.diskstorage.indexing.IndexTransaction) RelationIdentifier(org.janusgraph.graphdb.relations.RelationIdentifier) JanusGraphException(org.janusgraph.core.JanusGraphException) ExecutionException(java.util.concurrent.ExecutionException) JanusGraphElement(org.janusgraph.core.JanusGraphElement) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) RelationType(org.janusgraph.core.RelationType) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) JanusGraphSchemaVertex(org.janusgraph.graphdb.types.vertices.JanusGraphSchemaVertex) List(java.util.List) Map(java.util.Map)

Example 3 with StandardJanusGraphTx

use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.

the class VertexJobConverter method startTransaction.

public static StandardJanusGraphTx startTransaction(StandardJanusGraph graph) {
    StandardTransactionBuilder txb = graph.buildTransaction().readOnly();
    txb.setPreloadedData(true);
    txb.checkInternalVertexExistence(false);
    txb.dirtyVertexSize(0);
    txb.vertexCacheSize(0);
    return (StandardJanusGraphTx) txb.start();
}
Also used : StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) StandardTransactionBuilder(org.janusgraph.graphdb.transaction.StandardTransactionBuilder)

Example 4 with StandardJanusGraphTx

use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.

the class CassandraGraphTest method testGraphConfigUsedByTx.

@Test
public void testGraphConfigUsedByTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "TWO");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "THREE");
    graph = (StandardJanusGraph) JanusGraphFactory.open(wc);
    StandardJanusGraphTx tx = (StandardJanusGraphTx) graph.newTransaction();
    assertEquals("TWO", tx.getTxHandle().getBaseTransactionConfig().getCustomOptions().get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("THREE", tx.getTxHandle().getBaseTransactionConfig().getCustomOptions().get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
    tx.rollback();
}
Also used : StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration) Test(org.junit.Test)

Example 5 with StandardJanusGraphTx

use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx in project janusgraph by JanusGraph.

the class JanusGraphSchemaVertex method getDefinition.

@Override
public TypeDefinitionMap getDefinition() {
    TypeDefinitionMap def = definition;
    if (def == null) {
        def = new TypeDefinitionMap();
        Iterable<JanusGraphVertexProperty> ps;
        if (isLoaded()) {
            StandardJanusGraphTx tx = tx();
            ps = (Iterable) RelationConstructor.readRelation(this, tx.getGraph().getSchemaCache().getSchemaRelations(longId(), BaseKey.SchemaDefinitionProperty, Direction.OUT), tx);
        } else {
            ps = query().type(BaseKey.SchemaDefinitionProperty).properties();
        }
        for (JanusGraphVertexProperty property : ps) {
            TypeDefinitionDescription desc = property.valueOrNull(BaseKey.SchemaDefinitionDesc);
            Preconditions.checkArgument(desc != null && desc.getCategory().isProperty());
            def.setValue(desc.getCategory(), property.value());
        }
        assert def.size() > 0;
        definition = def;
    }
    assert def != null;
    return def;
}
Also used : StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty)

Aggregations

StandardJanusGraphTx (org.janusgraph.graphdb.transaction.StandardJanusGraphTx)17 Test (org.junit.Test)4 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)3 RelationType (org.janusgraph.core.RelationType)3 WriteConfiguration (org.janusgraph.diskstorage.configuration.WriteConfiguration)3 InternalRelationType (org.janusgraph.graphdb.internal.InternalRelationType)3 Instant (java.time.Instant)2 Map (java.util.Map)2 ExecutionException (java.util.concurrent.ExecutionException)2 Direction (org.apache.tinkerpop.gremlin.structure.Direction)2 JanusGraphTransaction (org.janusgraph.core.JanusGraphTransaction)2 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)2 Preconditions (com.google.common.base.Preconditions)1 Predicate (com.google.common.base.Predicate)1 Predicates (com.google.common.base.Predicates)1 com.google.common.cache (com.google.common.cache)1 com.google.common.collect (com.google.common.collect)1 IOException (java.io.IOException)1 Duration (java.time.Duration)1 Collections (java.util.Collections)1