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);
}
}
}
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);
}
}
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();
}
}
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();
}
}
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;
}
Aggregations