Search in sources :

Example 1 with SchemaTransaction

use of com.baidu.hugegraph.backend.tx.SchemaTransaction 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 2 with SchemaTransaction

use of com.baidu.hugegraph.backend.tx.SchemaTransaction 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 3 with SchemaTransaction

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

the class EdgeLabelRemoveJob method removeEdgeLabel.

private static void removeEdgeLabel(HugeGraphParams graph, Id id) {
    GraphTransaction graphTx = graph.graphTransaction();
    SchemaTransaction schemaTx = graph.schemaTransaction();
    EdgeLabel edgeLabel = schemaTx.getEdgeLabel(id);
    // If the edge label does not exist, return directly
    if (edgeLabel == null) {
        return;
    }
    if (edgeLabel.status().deleting()) {
        LOG.info("The edge label '{}' has been in {} status, " + "please check if it's expected to delete it again", edgeLabel, edgeLabel.status());
    }
    // Remove index related data(include schema) of this edge label
    Set<Id> indexIds = ImmutableSet.copyOf(edgeLabel.indexLabels());
    LockUtil.Locks locks = new LockUtil.Locks(graph.name());
    try {
        locks.lockWrites(LockUtil.EDGE_LABEL_DELETE, id);
        schemaTx.updateSchemaStatus(edgeLabel, SchemaStatus.DELETING);
        try {
            for (Id indexId : indexIds) {
                IndexLabelRemoveJob.removeIndexLabel(graph, indexId);
            }
            // Remove all edges which has matched label
            // TODO: use event to replace direct call
            graphTx.removeEdges(edgeLabel);
            /*
                 * Should commit changes to backend store before release
                 * delete lock
                 */
            graph.graph().tx().commit();
            // Remove edge label
            removeSchema(schemaTx, edgeLabel);
        } catch (Throwable e) {
            schemaTx.updateSchemaStatus(edgeLabel, SchemaStatus.UNDELETED);
            throw e;
        }
    } finally {
        locks.unlock();
    }
}
Also used : LockUtil(com.baidu.hugegraph.util.LockUtil) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction) Id(com.baidu.hugegraph.backend.id.Id) SchemaTransaction(com.baidu.hugegraph.backend.tx.SchemaTransaction)

Example 4 with SchemaTransaction

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

the class IndexLabelRemoveJob method removeIndexLabel.

protected static void removeIndexLabel(HugeGraphParams graph, Id id) {
    GraphTransaction graphTx = graph.graphTransaction();
    SchemaTransaction schemaTx = graph.schemaTransaction();
    IndexLabel indexLabel = schemaTx.getIndexLabel(id);
    // If the index label does not exist, return directly
    if (indexLabel == null) {
        return;
    }
    if (indexLabel.status().deleting()) {
        LOG.info("The index label '{}' has been in {} status, " + "please check if it's expected to delete it again", indexLabel, indexLabel.status());
    }
    LockUtil.Locks locks = new LockUtil.Locks(graph.name());
    try {
        locks.lockWrites(LockUtil.INDEX_LABEL_DELETE, id);
        // TODO add update lock
        // Set index label to "deleting" status
        schemaTx.updateSchemaStatus(indexLabel, SchemaStatus.DELETING);
        try {
            // Remove indexLabel from indexLabels of vertex/edge label
            schemaTx.removeIndexLabelFromBaseLabel(indexLabel);
            // Remove index data
            // TODO: use event to replace direct call
            graphTx.removeIndex(indexLabel);
            /*
                 * Should commit changes to backend store before release
                 * delete lock
                 */
            graph.graph().tx().commit();
            // Remove index label
            removeSchema(schemaTx, indexLabel);
        } catch (Throwable e) {
            schemaTx.updateSchemaStatus(indexLabel, SchemaStatus.UNDELETED);
            throw e;
        }
    } finally {
        locks.unlock();
    }
}
Also used : LockUtil(com.baidu.hugegraph.util.LockUtil) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction) SchemaTransaction(com.baidu.hugegraph.backend.tx.SchemaTransaction)

Example 5 with SchemaTransaction

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

the class OlapPropertyKeyCreateJob method execute.

@Override
public Object execute() {
    SchemaTransaction schemaTx = this.params().schemaTransaction();
    PropertyKey propertyKey = schemaTx.getPropertyKey(this.schemaId());
    // Create olap index label schema
    schemaTx.createIndexLabelForOlapPk(propertyKey);
    // Create olap data table
    this.params().graphTransaction().createOlapPk(propertyKey.id());
    return null;
}
Also used : SchemaTransaction(com.baidu.hugegraph.backend.tx.SchemaTransaction) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Aggregations

SchemaTransaction (com.baidu.hugegraph.backend.tx.SchemaTransaction)9 Id (com.baidu.hugegraph.backend.id.Id)6 GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)6 LockUtil (com.baidu.hugegraph.util.LockUtil)6 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)4 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)3 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)2 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)2 HugeException (com.baidu.hugegraph.HugeException)1 HugeGraph (com.baidu.hugegraph.HugeGraph)1 BackendStoreSystemInfo (com.baidu.hugegraph.backend.store.BackendStoreSystemInfo)1 SchemaElement (com.baidu.hugegraph.schema.SchemaElement)1 SchemaLabel (com.baidu.hugegraph.schema.SchemaLabel)1 HugeElement (com.baidu.hugegraph.structure.HugeElement)1 HugeType (com.baidu.hugegraph.type.HugeType)1 SchemaStatus (com.baidu.hugegraph.type.define.SchemaStatus)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Collection (java.util.Collection)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1