Search in sources :

Example 1 with TitanRelation

use of com.thinkaurelius.titan.core.TitanRelation in project titan by thinkaurelius.

the class GhostVertexRemover method process.

@Override
public void process(StaticBuffer key, Map<SliceQuery, EntryList> entries, ScanMetrics metrics) {
    long vertexId = getVertexId(key);
    assert entries.size() == 1;
    assert entries.get(everythingQueryLimit) != null;
    final EntryList everything = entries.get(everythingQueryLimit);
    if (!isGhostVertex(vertexId, everything)) {
        return;
    }
    if (everything.size() >= RELATION_COUNT_LIMIT) {
        metrics.incrementCustom(SKIPPED_GHOST_LIMIT_COUNT);
        return;
    }
    TitanVertex vertex = tx.getInternalVertex(vertexId);
    Preconditions.checkArgument(vertex instanceof CacheVertex, "The bounding transaction is not configured correctly");
    CacheVertex v = (CacheVertex) vertex;
    v.loadRelations(EVERYTHING_QUERY, new Retriever<SliceQuery, EntryList>() {

        @Override
        public EntryList get(SliceQuery input) {
            return everything;
        }
    });
    int removedRelations = 0;
    Iterator<TitanRelation> iter = v.query().noPartitionRestriction().relations().iterator();
    while (iter.hasNext()) {
        iter.next();
        iter.remove();
        removedRelations++;
    }
    //There should be no more system relations to remove
    metrics.incrementCustom(REMOVED_VERTEX_COUNT);
    metrics.incrementCustom(REMOVED_RELATION_COUNT, removedRelations);
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) EntryList(com.thinkaurelius.titan.diskstorage.EntryList) CacheVertex(com.thinkaurelius.titan.graphdb.vertices.CacheVertex) TitanRelation(com.thinkaurelius.titan.core.TitanRelation) SliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)

Example 2 with TitanRelation

use of com.thinkaurelius.titan.core.TitanRelation 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)

Aggregations

TitanRelation (com.thinkaurelius.titan.core.TitanRelation)2 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)2 RelationType (com.thinkaurelius.titan.core.RelationType)1 EntryList (com.thinkaurelius.titan.diskstorage.EntryList)1 SliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)1 StandardTitanTx (com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx)1 CacheVertex (com.thinkaurelius.titan.graphdb.vertices.CacheVertex)1 Direction (org.apache.tinkerpop.gremlin.structure.Direction)1