Search in sources :

Example 31 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class SchemaTransaction method removeVertexLabel.

@Watched(prefix = "schema")
public Id removeVertexLabel(Id id) {
    LOG.debug("SchemaTransaction remove vertex label '{}'", id);
    SchemaJob callable = new VertexLabelRemoveJob();
    VertexLabel schema = this.getVertexLabel(id);
    return asyncRun(this.graph(), schema, callable);
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) VertexLabelRemoveJob(com.baidu.hugegraph.job.schema.VertexLabelRemoveJob) SchemaJob(com.baidu.hugegraph.job.schema.SchemaJob) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 32 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class CachedGraphTransaction method commitMutation2Backend.

@Override
@Watched(prefix = "graphcache")
protected final void commitMutation2Backend(BackendMutation... mutations) {
    // Collect changes before commit
    Collection<HugeVertex> updates = this.verticesInTxUpdated();
    Collection<HugeVertex> deletions = this.verticesInTxRemoved();
    Id[] vertexIds = new Id[updates.size() + deletions.size()];
    int vertexOffset = 0;
    int edgesInTxSize = this.edgesInTxSize();
    try {
        super.commitMutation2Backend(mutations);
        // Update vertex cache
        if (this.enableCacheVertex()) {
            for (HugeVertex vertex : updates) {
                vertexIds[vertexOffset++] = vertex.id();
                if (needCacheVertex(vertex)) {
                    // Update cache
                    this.verticesCache.updateIfPresent(vertex.id(), vertex);
                } else {
                    // Skip large vertex
                    this.verticesCache.invalidate(vertex.id());
                }
            }
        }
    } finally {
        // Update removed vertex in cache whatever success or fail
        if (this.enableCacheVertex()) {
            for (HugeVertex vertex : deletions) {
                vertexIds[vertexOffset++] = vertex.id();
                this.verticesCache.invalidate(vertex.id());
            }
            if (vertexOffset > 0) {
                this.notifyChanges(Cache.ACTION_INVALIDED, HugeType.VERTEX, vertexIds);
            }
        }
        /*
             * Update edge cache if any vertex or edge changed
             * For vertex change, the edges linked with should also be updated
             * Before we find a more precise strategy, just clear all the edge cache now
             */
        boolean invalidEdgesCache = (edgesInTxSize + updates.size() + deletions.size()) > 0;
        if (invalidEdgesCache && this.enableCacheEdge()) {
            // TODO: Use a more precise strategy to update the edge cache
            this.edgesCache.clear();
            this.notifyChanges(Cache.ACTION_CLEARED, HugeType.EDGE, null);
        }
    }
}
Also used : QueryId(com.baidu.hugegraph.backend.cache.CachedBackendStore.QueryId) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 33 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class GraphTransaction method removeEdgeProperty.

@Watched(prefix = "graph")
public <V> void removeEdgeProperty(HugeEdgeProperty<V> prop) {
    HugeEdge edge = prop.element();
    PropertyKey propKey = prop.propertyKey();
    E.checkState(edge != null, "No owner for removing property '%s'", prop.key());
    // Maybe have ever been removed
    if (!edge.hasProperty(propKey.id())) {
        return;
    }
    // Check is removing sort key
    List<Id> sortKeyIds = edge.schemaLabel().sortKeys();
    E.checkArgument(!sortKeyIds.contains(prop.propertyKey().id()), "Can't remove sort key '%s'", prop.key());
    // Remove property in memory for new created edge
    if (edge.fresh()) {
        // The owner will do property update
        edge.removeProperty(propKey.id());
        return;
    }
    // Check is updating property of added/removed edge
    E.checkArgument(!this.addedEdges.containsKey(edge.id()) || this.updatedEdges.containsKey(edge.id()), "Can't remove property '%s' for adding-state edge", prop.key());
    E.checkArgument(!this.removedEdges.containsKey(edge.id()), "Can't remove property '%s' for removing-state edge", prop.key());
    // Do property update
    this.lockForUpdateProperty(edge.schemaLabel(), prop, () -> {
        // Update old edge to remove index (with the property)
        this.indexTx.updateEdgeIndex(edge, true);
        // Update(remove) edge property
        this.propertyUpdated(edge, null, edge.removeProperty(propKey.id()));
    });
}
Also used : HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 34 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class GraphTransaction method addVertexProperty.

@Watched(prefix = "graph")
public <V> void addVertexProperty(HugeVertexProperty<V> prop) {
    // NOTE: this method can also be used to update property
    HugeVertex vertex = prop.element();
    E.checkState(vertex != null, "No owner for updating property '%s'", prop.key());
    // Add property in memory for new created vertex
    if (vertex.fresh()) {
        // The owner will do property update
        vertex.setProperty(prop);
        return;
    }
    // Check is updating property of added/removed vertex
    E.checkArgument(!this.addedVertices.containsKey(vertex.id()) || this.updatedVertices.containsKey(vertex.id()), "Can't update property '%s' for adding-state vertex", prop.key());
    E.checkArgument(!vertex.removed() && !this.removedVertices.containsKey(vertex.id()), "Can't update property '%s' for removing-state vertex", prop.key());
    // Check is updating primary key
    List<Id> primaryKeyIds = vertex.schemaLabel().primaryKeys();
    E.checkArgument(!primaryKeyIds.contains(prop.propertyKey().id()), "Can't update primary key: '%s'", prop.key());
    // Do property update
    this.lockForUpdateProperty(vertex.schemaLabel(), prop, () -> {
        // Update old vertex to remove index (without new property)
        this.indexTx.updateVertexIndex(vertex, true);
        // Update(add) vertex property
        this.propertyUpdated(vertex, prop, vertex.setProperty(prop));
    });
}
Also used : Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 35 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class GraphTransaction method constructVertex.

@Watched(prefix = "graph")
public HugeVertex constructVertex(boolean verifyVL, Object... keyValues) {
    HugeElement.ElementKeys elemKeys = HugeElement.classifyKeys(keyValues);
    if (possibleOlapVertex(elemKeys)) {
        Id id = HugeVertex.getIdValue(elemKeys.id());
        HugeVertex vertex = HugeVertex.create(this, id, VertexLabel.OLAP_VL);
        ElementHelper.attachProperties(vertex, keyValues);
        Iterator<HugeProperty<?>> iterator = vertex.getProperties().iterator();
        assert iterator.hasNext();
        if (iterator.next().propertyKey().olap()) {
            return vertex;
        }
    }
    VertexLabel vertexLabel = this.checkVertexLabel(elemKeys.label(), verifyVL);
    Id id = HugeVertex.getIdValue(elemKeys.id());
    List<Id> keys = this.graph().mapPkName2Id(elemKeys.keys());
    // Check whether id match with id strategy
    this.checkId(id, keys, vertexLabel);
    // Create HugeVertex
    HugeVertex vertex = HugeVertex.create(this, null, vertexLabel);
    // Set properties
    ElementHelper.attachProperties(vertex, keyValues);
    // Assign vertex id
    if (this.params().mode().maintaining() && vertexLabel.idStrategy() == IdStrategy.AUTOMATIC) {
        // Resume id for AUTOMATIC id strategy in restoring mode
        vertex.assignId(id, true);
    } else {
        vertex.assignId(id);
    }
    return vertex;
}
Also used : HugeProperty(com.baidu.hugegraph.structure.HugeProperty) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) HugeElement(com.baidu.hugegraph.structure.HugeElement) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Aggregations

Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)65 Id (com.baidu.hugegraph.backend.id.Id)30 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)9 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)8 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)8 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)7 ArrayList (java.util.ArrayList)7 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)6 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)6 BatchIdHolder (com.baidu.hugegraph.backend.page.IdHolder.BatchIdHolder)5 HugeIndex (com.baidu.hugegraph.structure.HugeIndex)5 IdHolder (com.baidu.hugegraph.backend.page.IdHolder)4 FixedIdHolder (com.baidu.hugegraph.backend.page.IdHolder.FixedIdHolder)4 PagingIdHolder (com.baidu.hugegraph.backend.page.IdHolder.PagingIdHolder)4 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)4 Query (com.baidu.hugegraph.backend.query.Query)4 SchemaJob (com.baidu.hugegraph.job.schema.SchemaJob)4 SchemaLabel (com.baidu.hugegraph.schema.SchemaLabel)4 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)4 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)4