Search in sources :

Example 16 with StandardTitanTx

use of com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx in project titan by thinkaurelius.

the class VertexJobConverter method startTransaction.

public static StandardTitanTx startTransaction(StandardTitanGraph graph) {
    StandardTransactionBuilder txb = graph.buildTransaction().readOnly();
    txb.setPreloadedData(true);
    txb.checkInternalVertexExistence(false);
    txb.dirtyVertexSize(0);
    txb.vertexCacheSize(0);
    return (StandardTitanTx) txb.start();
}
Also used : StandardTitanTx(com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx) StandardTransactionBuilder(com.thinkaurelius.titan.graphdb.transaction.StandardTransactionBuilder)

Example 17 with StandardTitanTx

use of com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx in project titan by thinkaurelius.

the class PartitionedVertexProgramExecutor method run.

public void run(int numThreads, ScanMetrics metrics) {
    StandardTitanTx 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> pvertices : pVertexAggregates.entrySet()) {
            if (pvertices.getValue() == null) {
                metrics.incrementCustom(GHOTST_PARTITION_VERTEX);
                continue;
            }
            workers.submit(new PartitionedVertexProcessor(pvertices.getKey(), pvertices.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(com.thinkaurelius.titan.graphdb.util.WorkerPool) EntryList(com.thinkaurelius.titan.diskstorage.EntryList) StandardTitanTx(com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx) Map(java.util.Map)

Example 18 with StandardTitanTx

use of com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx in project titan by thinkaurelius.

the class RelationTypeIndexWrapper method getSortKey.

@Override
public RelationType[] getSortKey() {
    StandardTitanTx 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 : RelationType(com.thinkaurelius.titan.core.RelationType) InternalRelationType(com.thinkaurelius.titan.graphdb.internal.InternalRelationType) StandardTitanTx(com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx)

Example 19 with StandardTitanTx

use of com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx in project titan by thinkaurelius.

the class RelationIdentifier method findRelation.

TitanRelation findRelation(TitanTransaction tx) {
    TitanVertex v = ((StandardTitanTx) tx).getInternalVertex(outVertexId);
    if (v == null || v.isRemoved())
        return null;
    TitanVertex 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 TitanRelation> rels;
    if (((RelationType) typeVertex).isEdgeLabel()) {
        Direction dir = Direction.OUT;
        TitanVertex other = ((StandardTitanTx) tx).getInternalVertex(inVertexId);
        if (other == null || other.isRemoved())
            return null;
        if (((StandardTitanTx) tx).isPartitionedVertex(v) && !((StandardTitanTx) tx).isPartitionedVertex(other)) {
            //Swap for likely better performance
            TitanVertex tmp = other;
            other = v;
            v = tmp;
            dir = Direction.IN;
        }
        rels = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types((EdgeLabel) type).direction(dir).adjacent(other).edges();
    } else {
        rels = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types((PropertyKey) type).properties();
    }
    for (TitanRelation r : rels) {
        //Find current or previous relation
        if (r.longId() == relationId || ((r instanceof StandardRelation) && ((StandardRelation) r).getPreviousID() == relationId))
            return r;
    }
    return null;
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) RelationType(com.thinkaurelius.titan.core.RelationType) StandardTitanTx(com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx) Direction(org.apache.tinkerpop.gremlin.structure.Direction) TitanRelation(com.thinkaurelius.titan.core.TitanRelation)

Example 20 with StandardTitanTx

use of com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx in project titan by thinkaurelius.

the class StandardTitanGraph method newTransaction.

public StandardTitanTx newTransaction(final TransactionConfiguration configuration) {
    if (!isOpen)
        ExceptionFactory.graphShutdown();
    try {
        StandardTitanTx tx = new StandardTitanTx(this, configuration);
        tx.setBackendTransaction(openBackendTransaction(tx));
        openTransactions.add(tx);
        return tx;
    } catch (BackendException e) {
        throw new TitanException("Could not start new transaction", e);
    }
}
Also used : StandardTitanTx(com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx)

Aggregations

StandardTitanTx (com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx)20 Test (org.junit.Test)5 RelationType (com.thinkaurelius.titan.core.RelationType)3 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)3 WriteConfiguration (com.thinkaurelius.titan.diskstorage.configuration.WriteConfiguration)3 InternalRelationType (com.thinkaurelius.titan.graphdb.internal.InternalRelationType)3 IOException (java.io.IOException)2 Map (java.util.Map)2 ExecutionException (java.util.concurrent.ExecutionException)2 Direction (org.apache.tinkerpop.gremlin.structure.Direction)2 TitanEdge (com.thinkaurelius.titan.core.TitanEdge)1 TitanElement (com.thinkaurelius.titan.core.TitanElement)1 TitanException (com.thinkaurelius.titan.core.TitanException)1 TitanGraph (com.thinkaurelius.titan.core.TitanGraph)1 TitanRelation (com.thinkaurelius.titan.core.TitanRelation)1 TitanTransaction (com.thinkaurelius.titan.core.TitanTransaction)1 TitanVertexProperty (com.thinkaurelius.titan.core.TitanVertexProperty)1 EntryList (com.thinkaurelius.titan.diskstorage.EntryList)1 ModifiableConfiguration (com.thinkaurelius.titan.diskstorage.configuration.ModifiableConfiguration)1 IndexTransaction (com.thinkaurelius.titan.diskstorage.indexing.IndexTransaction)1