Search in sources :

Example 1 with StandardVertexProperty

use of org.janusgraph.graphdb.relations.StandardVertexProperty in project janusgraph by JanusGraph.

the class StandardJanusGraphTx method addProperty.

public JanusGraphVertexProperty addProperty(VertexProperty.Cardinality cardinality, JanusGraphVertex vertex, PropertyKey key, Object value, Long id) {
    if (key.cardinality().convert() != cardinality && cardinality != VertexProperty.Cardinality.single)
        throw new SchemaViolationException("Key is defined for %s cardinality which conflicts with specified: %s", key.cardinality(), cardinality);
    verifyWriteAccess(vertex);
    Preconditions.checkArgument(!(key instanceof ImplicitKey), "Cannot create a property of implicit type: %s", key.name());
    vertex = ((InternalVertex) vertex).it();
    Preconditions.checkNotNull(key);
    checkPropertyConstraintForVertexOrCreatePropertyConstraint(vertex, key);
    final Object normalizedValue = verifyAttribute(key, value);
    Cardinality keyCardinality = key.cardinality();
    // Determine unique indexes
    final List<IndexLockTuple> uniqueIndexTuples = new ArrayList<>();
    for (CompositeIndexType index : TypeUtil.getUniqueIndexes(key)) {
        IndexSerializer.IndexRecords matches = IndexSerializer.indexMatches(vertex, index, key, normalizedValue);
        for (Object[] match : matches.getRecordValues()) uniqueIndexTuples.add(new IndexLockTuple(index, match));
    }
    TransactionLock uniqueLock = getUniquenessLock(vertex, (InternalRelationType) key, normalizedValue);
    // Add locks for unique indexes
    for (IndexLockTuple lockTuple : uniqueIndexTuples) uniqueLock = new CombinerLock(uniqueLock, getLock(lockTuple), times);
    uniqueLock.lock(LOCK_TIMEOUT);
    try {
        // //Check vertex-centric uniqueness -> this doesn't really make sense to check
        // if (config.hasVerifyUniqueness()) {
        // if (cardinality == Cardinality.SINGLE) {
        // if (!Iterables.isEmpty(query(vertex).type(key).properties()))
        // throw new SchemaViolationException("A property with the given key [%s] already exists on the vertex [%s] and the property key is defined as single-valued", key.name(), vertex);
        // }
        // if (cardinality == Cardinality.SET) {
        // if (!Iterables.isEmpty(Iterables.filter(query(vertex).type(key).properties(), new Predicate<JanusGraphVertexProperty>() {
        // @Override
        // public boolean apply(@Nullable JanusGraphVertexProperty janusgraphProperty) {
        // return normalizedValue.equals(janusgraphProperty.value());
        // }
        // })))
        // throw new SchemaViolationException("A property with the given key [%s] and value [%s] already exists on the vertex and the property key is defined as set-valued", key.name(), normalizedValue);
        // }
        // }
        long propId = id == null ? IDManager.getTemporaryRelationID(temporaryIds.nextID()) : id;
        StandardVertexProperty prop = new StandardVertexProperty(propId, key, (InternalVertex) vertex, normalizedValue, ElementLifeCycle.New);
        if (config.hasAssignIDsImmediately() && id == null)
            graph.assignID(prop);
        // Delete properties if the cardinality is restricted
        if (cardinality == VertexProperty.Cardinality.single || cardinality == VertexProperty.Cardinality.set) {
            Consumer<JanusGraphVertexProperty> propertyRemover = JanusGraphVertexProperty.getRemover(cardinality, normalizedValue);
            if ((!config.hasVerifyUniqueness() || ((InternalRelationType) key).getConsistencyModifier() != ConsistencyModifier.LOCK) && !TypeUtil.hasAnyIndex(key) && cardinality == keyCardinality.convert()) {
                // Only delete in-memory so as to not trigger a read from the database which isn't necessary because we will overwrite blindly
                // We need to label the new property as "upsert", so that in case property deletion happens, we not only delete this new
                // in-memory property, but also read from database to delete the old value (if exists)
                ((InternalVertex) vertex).getAddedRelations(p -> p.getType().equals(key)).forEach(p -> propertyRemover.accept((JanusGraphVertexProperty) p));
                prop.setUpsert(true);
            } else {
                ((InternalVertex) vertex).query().types(key).properties().forEach(propertyRemover);
            }
        }
        // Check index uniqueness
        if (config.hasVerifyUniqueness()) {
            // Check all unique indexes
            for (IndexLockTuple lockTuple : uniqueIndexTuples) {
                if (!Iterables.isEmpty(IndexHelper.getQueryResults(lockTuple.getIndex(), lockTuple.getAll(), this)))
                    throw new SchemaViolationException("Adding this property for key [%s] and value [%s] violates a uniqueness constraint [%s]", key.name(), normalizedValue, lockTuple.getIndex());
            }
        }
        connectRelation(prop);
        return prop;
    } finally {
        uniqueLock.unlock();
    }
}
Also used : InternalVertex(org.janusgraph.graphdb.internal.InternalVertex) PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) CacheVertex(org.janusgraph.graphdb.vertices.CacheVertex) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) EdgeLabelVertex(org.janusgraph.graphdb.types.vertices.EdgeLabelVertex) StringUtils(org.apache.commons.lang3.StringUtils) AddedRelationsContainer(org.janusgraph.graphdb.transaction.addedrelations.AddedRelationsContainer) CombinerLock(org.janusgraph.graphdb.transaction.lock.CombinerLock) MixedIndexCountQuery(org.janusgraph.core.MixedIndexCountQuery) SystemTypeManager(org.janusgraph.graphdb.types.system.SystemTypeManager) Cardinality(org.janusgraph.core.Cardinality) TypeDefinitionCategory(org.janusgraph.graphdb.types.TypeDefinitionCategory) StandardVertex(org.janusgraph.graphdb.vertices.StandardVertex) InternalRelation(org.janusgraph.graphdb.internal.InternalRelation) Duration(java.time.Duration) Map(java.util.Map) IndexType(org.janusgraph.graphdb.types.IndexType) ConcurrentIndexCache(org.janusgraph.graphdb.transaction.indexcache.ConcurrentIndexCache) TransactionLock(org.janusgraph.graphdb.transaction.lock.TransactionLock) And(org.janusgraph.graphdb.query.condition.And) StandardVertexProperty(org.janusgraph.graphdb.relations.StandardVertexProperty) PropertyKey(org.janusgraph.core.PropertyKey) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) BaseLabel(org.janusgraph.graphdb.types.system.BaseLabel) Set(java.util.Set) EdgeSerializer(org.janusgraph.graphdb.database.EdgeSerializer) EdgeLabel(org.janusgraph.core.EdgeLabel) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty) EdgeLabelMaker(org.janusgraph.core.schema.EdgeLabelMaker) IndexCache(org.janusgraph.graphdb.transaction.indexcache.IndexCache) ProfiledIterator(org.janusgraph.graphdb.util.ProfiledIterator) IndexQueryBuilder(org.janusgraph.graphdb.query.graph.IndexQueryBuilder) JanusGraphRelation(org.janusgraph.core.JanusGraphRelation) FakeLock(org.janusgraph.graphdb.transaction.lock.FakeLock) LongArrayList(com.carrotsearch.hppc.LongArrayList) Iterables(com.google.common.collect.Iterables) IndexSerializer(org.janusgraph.graphdb.database.IndexSerializer) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) JanusGraphIndexQuery(org.janusgraph.core.JanusGraphIndexQuery) NonBlockingHashMap(org.jctools.maps.NonBlockingHashMap) SchemaInspector(org.janusgraph.core.schema.SchemaInspector) VertexCentricQueryBuilder(org.janusgraph.graphdb.query.vertex.VertexCentricQueryBuilder) Cmp(org.janusgraph.core.attribute.Cmp) ConsistencyModifier(org.janusgraph.core.schema.ConsistencyModifier) EntryList(org.janusgraph.diskstorage.EntryList) JanusGraphException(org.janusgraph.core.JanusGraphException) StandardEdgeLabelMaker(org.janusgraph.graphdb.types.StandardEdgeLabelMaker) EmptySubqueryCache(org.janusgraph.graphdb.transaction.subquerycache.EmptySubqueryCache) Nullable(javax.annotation.Nullable) JanusGraphElement(org.janusgraph.core.JanusGraphElement) IDPool(org.janusgraph.graphdb.database.idassigner.IDPool) QueryUtil(org.janusgraph.graphdb.query.QueryUtil) PropertyKeyVertex(org.janusgraph.graphdb.types.vertices.PropertyKeyVertex) JanusGraphMultiVertexQuery(org.janusgraph.core.JanusGraphMultiVertexQuery) SimpleAddedRelations(org.janusgraph.graphdb.transaction.addedrelations.SimpleAddedRelations) RelationIdentifierUtils(org.janusgraph.graphdb.relations.RelationIdentifierUtils) CompositeIndexType(org.janusgraph.graphdb.types.CompositeIndexType) JanusGraphSchemaCategory(org.janusgraph.graphdb.internal.JanusGraphSchemaCategory) RelationComparator(org.janusgraph.graphdb.relations.RelationComparator) TypeDefinitionDescription(org.janusgraph.graphdb.types.TypeDefinitionDescription) EmptyAddedRelations(org.janusgraph.graphdb.transaction.addedrelations.EmptyAddedRelations) SimpleIndexCache(org.janusgraph.graphdb.transaction.indexcache.SimpleIndexCache) AtomicLong(java.util.concurrent.atomic.AtomicLong) Direction(org.apache.tinkerpop.gremlin.structure.Direction) Retriever(org.janusgraph.util.datastructures.Retriever) InternalVertexLabel(org.janusgraph.graphdb.internal.InternalVertexLabel) ConcurrentAddedRelations(org.janusgraph.graphdb.transaction.addedrelations.ConcurrentAddedRelations) SubqueryIterator(org.janusgraph.graphdb.util.SubqueryIterator) LockTuple(org.janusgraph.graphdb.transaction.lock.LockTuple) Preconditions(com.google.common.base.Preconditions) VertexLabel(org.janusgraph.core.VertexLabel) GraphCentricQuery(org.janusgraph.graphdb.query.graph.GraphCentricQuery) VertexCentricQuery(org.janusgraph.graphdb.query.vertex.VertexCentricQuery) BaseKey(org.janusgraph.graphdb.types.system.BaseKey) TypeDefinitionMap(org.janusgraph.graphdb.types.TypeDefinitionMap) LoggerFactory(org.slf4j.LoggerFactory) VertexLabelMaker(org.janusgraph.core.schema.VertexLabelMaker) QueryExecutor(org.janusgraph.graphdb.query.QueryExecutor) MetricManager(org.janusgraph.util.stats.MetricManager) JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) MixedIndexCountQueryBuilder(org.janusgraph.graphdb.query.graph.MixedIndexCountQueryBuilder) SystemRelationType(org.janusgraph.graphdb.types.system.SystemRelationType) JanusGraphSchemaElement(org.janusgraph.core.schema.JanusGraphSchemaElement) MetricsQueryExecutor(org.janusgraph.graphdb.query.MetricsQueryExecutor) ReentrantTransactionLock(org.janusgraph.graphdb.transaction.lock.ReentrantTransactionLock) AttributeHandler(org.janusgraph.graphdb.database.serialize.AttributeHandler) TypeInspector(org.janusgraph.graphdb.types.TypeInspector) Multiplicity(org.janusgraph.core.Multiplicity) RelationType(org.janusgraph.core.RelationType) Property(org.apache.tinkerpop.gremlin.structure.Property) ElementLifeCycle(org.janusgraph.graphdb.internal.ElementLifeCycle) SchemaViolationException(org.janusgraph.core.SchemaViolationException) VertexCache(org.janusgraph.graphdb.transaction.vertexcache.VertexCache) ImmutableMap(com.google.common.collect.ImmutableMap) PropertyKeyMaker(org.janusgraph.core.schema.PropertyKeyMaker) Collection(java.util.Collection) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Connection(org.janusgraph.core.Connection) JanusGraphSchemaVertex(org.janusgraph.graphdb.types.vertices.JanusGraphSchemaVertex) StandardPropertyKeyMaker(org.janusgraph.graphdb.types.StandardPropertyKeyMaker) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) RelationIdentifier(org.janusgraph.graphdb.relations.RelationIdentifier) ImplicitKey(org.janusgraph.graphdb.types.system.ImplicitKey) GraphCentricQueryBuilder(org.janusgraph.graphdb.query.graph.GraphCentricQueryBuilder) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) IndexHelper(org.janusgraph.graphdb.util.IndexHelper) ConditionUtil(org.janusgraph.graphdb.query.condition.ConditionUtil) JointIndexQuery(org.janusgraph.graphdb.query.graph.JointIndexQuery) Condition(org.janusgraph.graphdb.query.condition.Condition) VertexCentricEdgeIterable(org.janusgraph.graphdb.util.VertexCentricEdgeIterable) IndexTransaction(org.janusgraph.diskstorage.indexing.IndexTransaction) BackendTransaction(org.janusgraph.diskstorage.BackendTransaction) IDManager(org.janusgraph.graphdb.idmanagement.IDManager) VertexLabelVertex(org.janusgraph.graphdb.types.VertexLabelVertex) PreloadedVertex(org.janusgraph.graphdb.vertices.PreloadedVertex) HashMap(java.util.HashMap) Function(java.util.function.Function) StandardEdge(org.janusgraph.graphdb.relations.StandardEdge) ConcurrentMap(java.util.concurrent.ConcurrentMap) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) StandardVertexLabelMaker(org.janusgraph.graphdb.types.StandardVertexLabelMaker) IndexLockTuple(org.janusgraph.graphdb.transaction.lock.IndexLockTuple) MultiVertexCentricQueryBuilder(org.janusgraph.graphdb.query.vertex.MultiVertexCentricQueryBuilder) RelationCategory(org.janusgraph.graphdb.internal.RelationCategory) IndexSelectionStrategy(org.janusgraph.graphdb.query.index.IndexSelectionStrategy) NoSuchElementException(java.util.NoSuchElementException) JanusGraphBlueprintsTransaction(org.janusgraph.graphdb.tinkerpop.JanusGraphBlueprintsTransaction) BackendException(org.janusgraph.diskstorage.BackendException) TypeUtil(org.janusgraph.graphdb.types.TypeUtil) EmptyVertexCache(org.janusgraph.graphdb.transaction.vertexcache.EmptyVertexCache) QueryProfiler(org.janusgraph.graphdb.query.profile.QueryProfiler) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Query(org.janusgraph.graphdb.query.Query) BaseVertexLabel(org.janusgraph.graphdb.types.system.BaseVertexLabel) SubqueryCache(org.janusgraph.graphdb.transaction.subquerycache.SubqueryCache) ElementCategory(org.janusgraph.graphdb.internal.ElementCategory) Consumer(java.util.function.Consumer) EmptyIndexCache(org.janusgraph.graphdb.transaction.indexcache.EmptyIndexCache) GuavaVertexCache(org.janusgraph.graphdb.transaction.vertexcache.GuavaVertexCache) Collections(java.util.Collections) GuavaSubqueryCache(org.janusgraph.graphdb.transaction.subquerycache.GuavaSubqueryCache) ReadOnlyTransactionException(org.janusgraph.core.ReadOnlyTransactionException) Cardinality(org.janusgraph.core.Cardinality) IndexSerializer(org.janusgraph.graphdb.database.IndexSerializer) LongArrayList(com.carrotsearch.hppc.LongArrayList) ArrayList(java.util.ArrayList) StandardVertexProperty(org.janusgraph.graphdb.relations.StandardVertexProperty) IndexLockTuple(org.janusgraph.graphdb.transaction.lock.IndexLockTuple) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty) CombinerLock(org.janusgraph.graphdb.transaction.lock.CombinerLock) CompositeIndexType(org.janusgraph.graphdb.types.CompositeIndexType) SchemaViolationException(org.janusgraph.core.SchemaViolationException) ImplicitKey(org.janusgraph.graphdb.types.system.ImplicitKey) TransactionLock(org.janusgraph.graphdb.transaction.lock.TransactionLock) ReentrantTransactionLock(org.janusgraph.graphdb.transaction.lock.ReentrantTransactionLock)

Example 2 with StandardVertexProperty

use of org.janusgraph.graphdb.relations.StandardVertexProperty in project janusgraph by JanusGraph.

the class StandardJanusGraphTx method addProperty.

public JanusGraphVertexProperty addProperty(VertexProperty.Cardinality cardinality, JanusGraphVertex vertex, PropertyKey key, Object value) {
    if (key.cardinality().convert() != cardinality && cardinality != VertexProperty.Cardinality.single)
        throw new SchemaViolationException(String.format("Key is defined for %s cardinality which conflicts with specified: %s", key.cardinality(), cardinality));
    verifyWriteAccess(vertex);
    Preconditions.checkArgument(!(key instanceof ImplicitKey), "Cannot create a property of implicit type: %s", key.name());
    vertex = ((InternalVertex) vertex).it();
    Preconditions.checkNotNull(key);
    final Object normalizedValue = verifyAttribute(key, value);
    Cardinality keyCardinality = key.cardinality();
    // Determine unique indexes
    final List<IndexLockTuple> uniqueIndexTuples = new ArrayList<>();
    for (CompositeIndexType index : TypeUtil.getUniqueIndexes(key)) {
        IndexSerializer.IndexRecords matches = IndexSerializer.indexMatches(vertex, index, key, normalizedValue);
        for (Object[] match : matches.getRecordValues()) uniqueIndexTuples.add(new IndexLockTuple(index, match));
    }
    TransactionLock uniqueLock = getUniquenessLock(vertex, (InternalRelationType) key, normalizedValue);
    // Add locks for unique indexes
    for (IndexLockTuple lockTuple : uniqueIndexTuples) uniqueLock = new CombinerLock(uniqueLock, getLock(lockTuple), times);
    uniqueLock.lock(LOCK_TIMEOUT);
    try {
        // Delete properties if the cardinality is restricted
        if (cardinality == VertexProperty.Cardinality.single || cardinality == VertexProperty.Cardinality.set) {
            Consumer<JanusGraphRelation> propertyRemover;
            if (cardinality == VertexProperty.Cardinality.single)
                propertyRemover = JanusGraphElement::remove;
            else
                propertyRemover = p -> {
                    if (((JanusGraphVertexProperty) p).value().equals(normalizedValue))
                        p.remove();
                };
            if ((!config.hasVerifyUniqueness() || ((InternalRelationType) key).getConsistencyModifier() != ConsistencyModifier.LOCK) && !TypeUtil.hasAnyIndex(key) && cardinality == keyCardinality.convert()) {
                // Only delete in-memory so as to not trigger a read from the database which isn't necessary because we will overwrite blindly
                ((InternalVertex) vertex).getAddedRelations(p -> p.getType().equals(key)).forEach(propertyRemover);
            } else {
                ((InternalVertex) vertex).query().types(key).properties().forEach(propertyRemover);
            }
        }
        // Check index uniqueness
        if (config.hasVerifyUniqueness()) {
            // Check all unique indexes
            for (IndexLockTuple lockTuple : uniqueIndexTuples) {
                if (!Iterables.isEmpty(IndexHelper.getQueryResults(lockTuple.getIndex(), lockTuple.getAll(), this)))
                    throw new SchemaViolationException("Adding this property for key [%s] and value [%s] violates a uniqueness constraint [%s]", key.name(), normalizedValue, lockTuple.getIndex());
            }
        }
        StandardVertexProperty prop = new StandardVertexProperty(IDManager.getTemporaryRelationID(temporaryIds.nextID()), key, (InternalVertex) vertex, normalizedValue, ElementLifeCycle.New);
        if (config.hasAssignIDsImmediately())
            graph.assignID(prop);
        connectRelation(prop);
        return prop;
    } finally {
        uniqueLock.unlock();
    }
}
Also used : CacheVertex(org.janusgraph.graphdb.vertices.CacheVertex) StringUtils(org.apache.commons.lang.StringUtils) org.janusgraph.graphdb.internal(org.janusgraph.graphdb.internal) EdgeLabelVertex(org.janusgraph.graphdb.types.vertices.EdgeLabelVertex) org.janusgraph.graphdb.query.condition(org.janusgraph.graphdb.query.condition) LoggerFactory(org.slf4j.LoggerFactory) MetricManager(org.janusgraph.util.stats.MetricManager) AddedRelationsContainer(org.janusgraph.graphdb.transaction.addedrelations.AddedRelationsContainer) AttributeHandler(org.janusgraph.graphdb.database.serialize.AttributeHandler) org.janusgraph.graphdb.transaction.lock(org.janusgraph.graphdb.transaction.lock) StandardVertex(org.janusgraph.graphdb.vertices.StandardVertex) Duration(java.time.Duration) com.google.common.collect(com.google.common.collect) ConcurrentIndexCache(org.janusgraph.graphdb.transaction.indexcache.ConcurrentIndexCache) Weigher(com.google.common.cache.Weigher) org.janusgraph.core.schema(org.janusgraph.core.schema) StandardVertexProperty(org.janusgraph.graphdb.relations.StandardVertexProperty) ConcurrentBufferAddedRelations(org.janusgraph.graphdb.transaction.addedrelations.ConcurrentBufferAddedRelations) VertexCache(org.janusgraph.graphdb.transaction.vertexcache.VertexCache) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) java.util.concurrent(java.util.concurrent) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) org.janusgraph.core(org.janusgraph.core) JanusGraphSchemaVertex(org.janusgraph.graphdb.types.vertices.JanusGraphSchemaVertex) EdgeSerializer(org.janusgraph.graphdb.database.EdgeSerializer) Collectors(java.util.stream.Collectors) RelationIdentifier(org.janusgraph.graphdb.relations.RelationIdentifier) Predicate(com.google.common.base.Predicate) IndexCache(org.janusgraph.graphdb.transaction.indexcache.IndexCache) GraphCentricQueryBuilder(org.janusgraph.graphdb.query.graph.GraphCentricQueryBuilder) CacheBuilder(com.google.common.cache.CacheBuilder) IndexQueryBuilder(org.janusgraph.graphdb.query.graph.IndexQueryBuilder) IndexHelper(org.janusgraph.graphdb.util.IndexHelper) LongArrayList(com.carrotsearch.hppc.LongArrayList) org.janusgraph.graphdb.query(org.janusgraph.graphdb.query) java.util(java.util) JointIndexQuery(org.janusgraph.graphdb.query.graph.JointIndexQuery) VertexCentricEdgeIterable(org.janusgraph.graphdb.util.VertexCentricEdgeIterable) BackendTransaction(org.janusgraph.diskstorage.BackendTransaction) IDManager(org.janusgraph.graphdb.idmanagement.IDManager) PreloadedVertex(org.janusgraph.graphdb.vertices.PreloadedVertex) org.janusgraph.graphdb.types(org.janusgraph.graphdb.types) IndexSerializer(org.janusgraph.graphdb.database.IndexSerializer) Function(java.util.function.Function) StandardEdge(org.janusgraph.graphdb.relations.StandardEdge) VertexCentricQueryBuilder(org.janusgraph.graphdb.query.vertex.VertexCentricQueryBuilder) Cmp(org.janusgraph.core.attribute.Cmp) MultiVertexCentricQueryBuilder(org.janusgraph.graphdb.query.vertex.MultiVertexCentricQueryBuilder) org.apache.tinkerpop.gremlin.structure(org.apache.tinkerpop.gremlin.structure) EntryList(org.janusgraph.diskstorage.EntryList) JanusGraphBlueprintsTransaction(org.janusgraph.graphdb.tinkerpop.JanusGraphBlueprintsTransaction) Nullable(javax.annotation.Nullable) BackendException(org.janusgraph.diskstorage.BackendException) IDPool(org.janusgraph.graphdb.database.idassigner.IDPool) SimpleBufferAddedRelations(org.janusgraph.graphdb.transaction.addedrelations.SimpleBufferAddedRelations) PropertyKeyVertex(org.janusgraph.graphdb.types.vertices.PropertyKeyVertex) QueryProfiler(org.janusgraph.graphdb.query.profile.QueryProfiler) Logger(org.slf4j.Logger) NonBlockingHashMap(org.cliffc.high_scale_lib.NonBlockingHashMap) org.janusgraph.graphdb.types.system(org.janusgraph.graphdb.types.system) RelationComparator(org.janusgraph.graphdb.relations.RelationComparator) Consumer(java.util.function.Consumer) SimpleIndexCache(org.janusgraph.graphdb.transaction.indexcache.SimpleIndexCache) AtomicLong(java.util.concurrent.atomic.AtomicLong) Retriever(org.janusgraph.util.datastructures.Retriever) GuavaVertexCache(org.janusgraph.graphdb.transaction.vertexcache.GuavaVertexCache) SubqueryIterator(org.janusgraph.graphdb.util.SubqueryIterator) Preconditions(com.google.common.base.Preconditions) Cache(com.google.common.cache.Cache) GraphCentricQuery(org.janusgraph.graphdb.query.graph.GraphCentricQuery) VertexCentricQuery(org.janusgraph.graphdb.query.vertex.VertexCentricQuery) IndexSerializer(org.janusgraph.graphdb.database.IndexSerializer) LongArrayList(com.carrotsearch.hppc.LongArrayList) StandardVertexProperty(org.janusgraph.graphdb.relations.StandardVertexProperty)

Example 3 with StandardVertexProperty

use of org.janusgraph.graphdb.relations.StandardVertexProperty in project janusgraph by JanusGraph.

the class ModificationDeserializer method parseRelation.

public static InternalRelation parseRelation(TransactionLogHeader.Modification modification, StandardJanusGraphTx tx) {
    Change state = modification.state;
    assert state.isProper();
    long outVertexId = modification.outVertexId;
    Entry relEntry = modification.relationEntry;
    InternalVertex outVertex = tx.getInternalVertex(outVertexId);
    // Special relation parsing, compare to {@link RelationConstructor}
    RelationCache relCache = tx.getEdgeSerializer().readRelation(relEntry, false, tx);
    assert relCache.direction == Direction.OUT;
    InternalRelationType type = (InternalRelationType) tx.getExistingRelationType(relCache.typeId);
    assert type.getBaseType() == null;
    InternalRelation rel;
    if (type.isPropertyKey()) {
        if (state == Change.REMOVED) {
            rel = new StandardVertexProperty(relCache.relationId, (PropertyKey) type, outVertex, relCache.getValue(), ElementLifeCycle.Removed);
        } else {
            rel = new CacheVertexProperty(relCache.relationId, (PropertyKey) type, outVertex, relCache.getValue(), relEntry);
        }
    } else {
        assert type.isEdgeLabel();
        InternalVertex otherVertex = tx.getInternalVertex(relCache.getOtherVertexId());
        if (state == Change.REMOVED) {
            rel = new StandardEdge(relCache.relationId, (EdgeLabel) type, outVertex, otherVertex, ElementLifeCycle.Removed);
        } else {
            rel = new CacheEdge(relCache.relationId, (EdgeLabel) type, outVertex, otherVertex, relEntry);
        }
    }
    if (state == Change.REMOVED && relCache.hasProperties()) {
        // copy over properties
        for (LongObjectCursor<Object> entry : relCache) {
            rel.setPropertyDirect(tx.getExistingPropertyKey(entry.key), entry.value);
        }
    }
    return rel;
}
Also used : RelationCache(org.janusgraph.graphdb.relations.RelationCache) EdgeLabel(org.janusgraph.core.EdgeLabel) StandardVertexProperty(org.janusgraph.graphdb.relations.StandardVertexProperty) Change(org.janusgraph.core.log.Change) InternalRelation(org.janusgraph.graphdb.internal.InternalRelation) StandardEdge(org.janusgraph.graphdb.relations.StandardEdge) Entry(org.janusgraph.diskstorage.Entry) CacheVertexProperty(org.janusgraph.graphdb.relations.CacheVertexProperty) CacheEdge(org.janusgraph.graphdb.relations.CacheEdge) InternalVertex(org.janusgraph.graphdb.internal.InternalVertex) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) PropertyKey(org.janusgraph.core.PropertyKey)

Aggregations

LongArrayList (com.carrotsearch.hppc.LongArrayList)2 Preconditions (com.google.common.base.Preconditions)2 Duration (java.time.Duration)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Consumer (java.util.function.Consumer)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Nullable (javax.annotation.Nullable)2 EdgeLabel (org.janusgraph.core.EdgeLabel)2 StandardEdge (org.janusgraph.graphdb.relations.StandardEdge)2 StandardVertexProperty (org.janusgraph.graphdb.relations.StandardVertexProperty)2 Predicate (com.google.common.base.Predicate)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 Weigher (com.google.common.cache.Weigher)1 com.google.common.collect (com.google.common.collect)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables (com.google.common.collect.Iterables)1 Sets (com.google.common.collect.Sets)1 java.util (java.util)1