use of com.baidu.hugegraph.backend.tx.GraphTransaction in project incubator-hugegraph by apache.
the class DeleteExpiredIndexJob method deleteExpiredIndex.
/*
* Delete expired element(if exist) of the index,
* otherwise just delete expired index only
*/
private void deleteExpiredIndex(HugeGraphParams graph, HugeIndex index) {
GraphTransaction tx = graph.graphTransaction();
HugeType type = index.indexLabel().queryType().isVertex() ? HugeType.VERTEX : HugeType.EDGE;
IdQuery query = new IdQuery(type);
query.query(index.elementId());
query.showExpired(true);
Iterator<?> elements = type.isVertex() ? tx.queryVertices(query) : tx.queryEdges(query);
if (elements.hasNext()) {
HugeElement element = (HugeElement) elements.next();
if (element.expiredTime() == index.expiredTime()) {
element.remove();
} else {
tx.removeIndex(index);
}
} else {
tx.removeIndex(index);
}
}
use of com.baidu.hugegraph.backend.tx.GraphTransaction 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();
}
}
use of com.baidu.hugegraph.backend.tx.GraphTransaction 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();
}
}
use of com.baidu.hugegraph.backend.tx.GraphTransaction in project incubator-hugegraph by apache.
the class EdgeCoreTest method testRemoveEdgeAfterAddEdgeWithTx.
@Test
public void testRemoveEdgeAfterAddEdgeWithTx() {
HugeGraph graph = graph();
GraphTransaction tx = params().openTransaction();
Vertex james = tx.addVertex(T.label, "author", "id", 1, "name", "James Gosling", "age", 62, "lived", "Canadian");
Vertex java = tx.addVertex(T.label, "language", "name", "java");
Edge created = james.addEdge("created", java);
created.remove();
try {
tx.commit();
} finally {
tx.close();
}
List<Edge> edges = graph.traversal().E().toList();
Assert.assertEquals(0, edges.size());
}
use of com.baidu.hugegraph.backend.tx.GraphTransaction in project incubator-hugegraph by apache.
the class HugeVariables method queryAllVariableVertices.
private Iterator<Vertex> queryAllVariableVertices() {
GraphTransaction tx = this.params.graphTransaction();
Query query = this.createVariableQuery(null);
Iterator<Vertex> vertices = tx.queryVertices(query);
return vertices;
}
Aggregations