Search in sources :

Example 6 with StandardJanusGraphTx

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

the class RelationIdentifier method findRelation.

JanusGraphRelation findRelation(JanusGraphTransaction tx) {
    JanusGraphVertex v = ((StandardJanusGraphTx) tx).getInternalVertex(outVertexId);
    if (v == null || v.isRemoved())
        return null;
    JanusGraphVertex typeVertex = tx.getVertex(typeId);
    if (typeVertex == null)
        return null;
    if (!(typeVertex instanceof RelationType))
        throw new IllegalArgumentException("Invalid RelationIdentifier: typeID does not reference a type");
    RelationType type = (RelationType) typeVertex;
    Iterable<? extends JanusGraphRelation> relations;
    if (((RelationType) typeVertex).isEdgeLabel()) {
        Direction dir = Direction.OUT;
        JanusGraphVertex other = ((StandardJanusGraphTx) tx).getInternalVertex(inVertexId);
        if (other == null || other.isRemoved())
            return null;
        if (((StandardJanusGraphTx) tx).isPartitionedVertex(v) && !((StandardJanusGraphTx) tx).isPartitionedVertex(other)) {
            // Swap for likely better performance
            JanusGraphVertex tmp = other;
            other = v;
            v = tmp;
            dir = Direction.IN;
        }
        relations = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types((EdgeLabel) type).direction(dir).adjacent(other).edges();
    } else {
        relations = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types((PropertyKey) type).properties();
    }
    for (JanusGraphRelation r : relations) {
        // Find current or previous relation
        if (r.longId() == relationId || ((r instanceof StandardRelation) && ((StandardRelation) r).getPreviousID() == relationId))
            return r;
    }
    return null;
}
Also used : JanusGraphRelation(org.janusgraph.core.JanusGraphRelation) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) RelationType(org.janusgraph.core.RelationType) Direction(org.apache.tinkerpop.gremlin.structure.Direction)

Example 7 with StandardJanusGraphTx

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

the class PartitionedVertexProgramExecutor method run.

public void run(int numThreads, ScanMetrics metrics) {
    StandardJanusGraphTx tx = null;
    Map<Long, EntryList> pVertexAggregates = vertexMemory.retrievePartitionAggregates();
    // Nothing to do here
    if (pVertexAggregates.isEmpty())
        return;
    try (WorkerPool workers = new WorkerPool(numThreads)) {
        tx = VertexJobConverter.startTransaction(graph);
        for (Map.Entry<Long, EntryList> partitionedVertices : pVertexAggregates.entrySet()) {
            if (partitionedVertices.getValue() == null) {
                metrics.incrementCustom(GHOST_PARTITION_VERTEX);
                continue;
            }
            workers.submit(new PartitionedVertexProcessor(partitionedVertices.getKey(), partitionedVertices.getValue(), tx, metrics));
        }
    } catch (Throwable ex) {
        log.error("Could not post-process partitioned vertices", ex);
        metrics.incrementCustom(PARTITION_VERTEX_POSTFAIL);
    } finally {
        if (tx != null && tx.isOpen())
            tx.rollback();
    }
}
Also used : WorkerPool(org.janusgraph.graphdb.util.WorkerPool) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) EntryList(org.janusgraph.diskstorage.EntryList) Map(java.util.Map)

Example 8 with StandardJanusGraphTx

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

the class IndexRemoveJob method getQueries.

@Override
public List<SliceQuery> getQueries() {
    if (isGlobalGraphIndex()) {
        // Everything
        return ImmutableList.of(new SliceQuery(BufferUtil.zeroBuffer(1), BufferUtil.oneBuffer(128)));
    } else {
        RelationTypeIndexWrapper wrapper = (RelationTypeIndexWrapper) index;
        InternalRelationType wrappedType = wrapper.getWrappedType();
        Direction direction = null;
        for (Direction dir : Direction.values()) if (wrappedType.isUnidirected(dir))
            direction = dir;
        assert direction != null;
        StandardJanusGraphTx tx = (StandardJanusGraphTx) graph.get().buildTransaction().readOnly().start();
        try {
            QueryContainer qc = new QueryContainer(tx);
            qc.addQuery().type(wrappedType).direction(direction).relations();
            return qc.getSliceQueries();
        } finally {
            tx.rollback();
        }
    }
}
Also used : StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) RelationTypeIndexWrapper(org.janusgraph.graphdb.database.management.RelationTypeIndexWrapper) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) Direction(org.apache.tinkerpop.gremlin.structure.Direction) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) QueryContainer(org.janusgraph.graphdb.olap.QueryContainer)

Example 9 with StandardJanusGraphTx

use of org.janusgraph.graphdb.transaction.StandardJanusGraphTx 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)

Example 10 with StandardJanusGraphTx

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

the class StandardJanusGraph method closeInternal.

private synchronized void closeInternal() {
    if (!isOpen)
        return;
    Map<JanusGraphTransaction, RuntimeException> txCloseExceptions = new HashMap<>();
    try {
        // Unregister instance
        String uniqueId = null;
        try {
            uniqueId = config.getUniqueGraphId();
            ModifiableConfiguration globalConfig = GraphDatabaseConfiguration.getGlobalSystemConfig(backend);
            globalConfig.remove(REGISTRATION_TIME, uniqueId);
        } catch (Exception e) {
            log.warn("Unable to remove graph instance uniqueid {}", uniqueId, e);
        }
        /* Assuming a couple of properties about openTransactions:
             * 1. no concurrent modifications during graph shutdown
             * 2. all contained txs are open
             */
        for (StandardJanusGraphTx otx : openTransactions) {
            try {
                otx.close();
            } catch (RuntimeException e) {
                // Catch and store these exceptions, but proceed wit the loop
                // Any remaining txs on the iterator should get a chance to close before we throw up
                log.warn("Unable to close transaction {}", otx, e);
                txCloseExceptions.put(otx, e);
            }
        }
        super.close();
        IOUtils.closeQuietly(idAssigner);
        IOUtils.closeQuietly(backend);
        IOUtils.closeQuietly(queryCache);
        IOUtils.closeQuietly(serializer);
    } finally {
        isOpen = false;
    }
    // Throw an exception if at least one transaction failed to close
    if (1 == txCloseExceptions.size()) {
        // TP3's test suite requires that this be of type ISE
        throw new IllegalStateException("Unable to close transaction", Iterables.getOnlyElement(txCloseExceptions.values()));
    } else if (1 < txCloseExceptions.size()) {
        throw new IllegalStateException(String.format("Unable to close %s transactions (see warnings in log output for details)", txCloseExceptions.size()));
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

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