Search in sources :

Example 1 with GraphTransaction

use of com.baidu.hugegraph.backend.tx.GraphTransaction in project incubator-hugegraph by apache.

the class HugeEdge method onUpdateProperty.

@Watched(prefix = "edge")
@Override
protected <V> void onUpdateProperty(Cardinality cardinality, HugeProperty<V> prop) {
    if (prop != null) {
        assert prop instanceof HugeEdgeProperty;
        HugeEdgeProperty<V> edgeProp = (HugeEdgeProperty<V>) prop;
        GraphTransaction tx = this.tx();
        if (tx != null) {
            assert this.fresh();
            tx.addEdgeProperty(edgeProp);
        } else {
            this.graph().addEdgeProperty(edgeProp);
        }
    }
}
Also used : GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 2 with GraphTransaction

use of com.baidu.hugegraph.backend.tx.GraphTransaction in project incubator-hugegraph by apache.

the class HugeVertex method remove.

@Watched(prefix = "vertex")
@Override
public void remove() {
    this.removed(true);
    /*
         * Call by tx or by graph to remove vertex,
         * call by tx if the vertex is new because the context is dependent
         */
    GraphTransaction tx = this.tx();
    if (tx != null) {
        assert this.fresh();
        tx.removeVertex(this);
    } else {
        assert !this.fresh();
        this.graph().removeVertex(this);
    }
}
Also used : GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 3 with GraphTransaction

use of com.baidu.hugegraph.backend.tx.GraphTransaction in project incubator-hugegraph by apache.

the class OlapPropertyKeyClearJob method clearIndexLabel.

protected static void clearIndexLabel(HugeGraphParams graph, Id id) {
    Id olapIndexLabel = findOlapIndexLabel(graph, id);
    if (olapIndexLabel == null) {
        return;
    }
    GraphTransaction graphTx = graph.graphTransaction();
    SchemaTransaction schemaTx = graph.schemaTransaction();
    IndexLabel indexLabel = schemaTx.getIndexLabel(olapIndexLabel);
    // If the index label does not exist, return directly
    if (indexLabel == null) {
        return;
    }
    LockUtil.Locks locks = new LockUtil.Locks(graph.name());
    try {
        locks.lockWrites(LockUtil.INDEX_LABEL_DELETE, olapIndexLabel);
        // Set index label to "rebuilding" status
        schemaTx.updateSchemaStatus(indexLabel, SchemaStatus.REBUILDING);
        try {
            // Remove index data
            graphTx.removeIndex(indexLabel);
            /*
                 * Should commit changes to backend store before release
                 * delete lock
                 */
            graph.graph().tx().commit();
            schemaTx.updateSchemaStatus(indexLabel, SchemaStatus.CREATED);
        } catch (Throwable e) {
            schemaTx.updateSchemaStatus(indexLabel, SchemaStatus.INVALID);
            throw e;
        }
    } finally {
        locks.unlock();
    }
}
Also used : LockUtil(com.baidu.hugegraph.util.LockUtil) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) Id(com.baidu.hugegraph.backend.id.Id) GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction) SchemaTransaction(com.baidu.hugegraph.backend.tx.SchemaTransaction)

Example 4 with GraphTransaction

use of com.baidu.hugegraph.backend.tx.GraphTransaction in project incubator-hugegraph by apache.

the class VertexLabelRemoveJob method removeVertexLabel.

private static void removeVertexLabel(HugeGraphParams graph, Id id) {
    GraphTransaction graphTx = graph.graphTransaction();
    SchemaTransaction schemaTx = graph.schemaTransaction();
    VertexLabel vertexLabel = schemaTx.getVertexLabel(id);
    // If the vertex label does not exist, return directly
    if (vertexLabel == null) {
        return;
    }
    if (vertexLabel.status().deleting()) {
        LOG.info("The vertex label '{}' has been in {} status, " + "please check if it's expected to delete it again", vertexLabel, vertexLabel.status());
    }
    // Check no edge label use the vertex label
    List<EdgeLabel> edgeLabels = schemaTx.getEdgeLabels();
    for (EdgeLabel edgeLabel : edgeLabels) {
        if (edgeLabel.linkWithLabel(id)) {
            throw new HugeException("Not allowed to remove vertex label '%s' " + "because the edge label '%s' still link with it", vertexLabel.name(), edgeLabel.name());
        }
    }
    /*
         * Copy index label ids because removeIndexLabel will mutate
         * vertexLabel.indexLabels()
         */
    Set<Id> indexLabelIds = ImmutableSet.copyOf(vertexLabel.indexLabels());
    LockUtil.Locks locks = new LockUtil.Locks(graph.name());
    try {
        locks.lockWrites(LockUtil.VERTEX_LABEL_DELETE, id);
        schemaTx.updateSchemaStatus(vertexLabel, SchemaStatus.DELETING);
        try {
            for (Id ilId : indexLabelIds) {
                IndexLabelRemoveJob.removeIndexLabel(graph, ilId);
            }
            // TODO: use event to replace direct call
            // Deleting a vertex will automatically deletes the held edge
            graphTx.removeVertices(vertexLabel);
            /*
                 * Should commit changes to backend store before release
                 * delete lock
                 */
            graph.graph().tx().commit();
            // Remove vertex label
            removeSchema(schemaTx, vertexLabel);
        } catch (Throwable e) {
            schemaTx.updateSchemaStatus(vertexLabel, SchemaStatus.UNDELETED);
            throw e;
        }
    } finally {
        locks.unlock();
    }
}
Also used : LockUtil(com.baidu.hugegraph.util.LockUtil) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction) Id(com.baidu.hugegraph.backend.id.Id) HugeException(com.baidu.hugegraph.HugeException) SchemaTransaction(com.baidu.hugegraph.backend.tx.SchemaTransaction)

Example 5 with GraphTransaction

use of com.baidu.hugegraph.backend.tx.GraphTransaction in project incubator-hugegraph by apache.

the class DeleteExpiredIndexJob method execute.

@Override
public V execute() throws Exception {
    LOG.debug("Delete expired indexes: {}", this.indexes);
    HugeGraphParams graph = this.params();
    GraphTransaction tx = graph.graphTransaction();
    try {
        for (HugeIndex index : this.indexes) {
            this.deleteExpiredIndex(graph, index);
        }
        tx.commit();
    } catch (Throwable e) {
        tx.rollback();
        LOG.warn("Failed to delete expired indexes: {}", this.indexes);
        throw e;
    } finally {
        JOB_COUNTERS.jobCounter(graph.graph()).decrement();
    }
    return null;
}
Also used : HugeGraphParams(com.baidu.hugegraph.HugeGraphParams) GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction) HugeIndex(com.baidu.hugegraph.structure.HugeIndex)

Aggregations

GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)22 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)7 SchemaTransaction (com.baidu.hugegraph.backend.tx.SchemaTransaction)6 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)6 LockUtil (com.baidu.hugegraph.util.LockUtil)6 Id (com.baidu.hugegraph.backend.id.Id)5 HugeGraph (com.baidu.hugegraph.HugeGraph)4 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)4 Test (org.junit.Test)4 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)3 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)3 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)3 HugeElement (com.baidu.hugegraph.structure.HugeElement)3 Edge (org.apache.tinkerpop.gremlin.structure.Edge)3 HugeException (com.baidu.hugegraph.HugeException)2 HugeGraphParams (com.baidu.hugegraph.HugeGraphParams)2 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)2 Query (com.baidu.hugegraph.backend.query.Query)2 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)2 FakeEdge (com.baidu.hugegraph.testutil.FakeObjects.FakeEdge)2