Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cassandra delete edge with label covered too many lines #727

Merged
merged 1 commit into from
Nov 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ protected void deleteEdgesByLabel(CassandraSessionPool.Session session,
}

final String OWNER_VERTEX = formatKey(HugeKeys.OWNER_VERTEX);
final String SORT_VALUES = formatKey(HugeKeys.SORT_VALUES);
final String OTHER_VERTEX = formatKey(HugeKeys.OTHER_VERTEX);

// Query edges by label index
Expand All @@ -419,29 +420,38 @@ protected void deleteEdgesByLabel(CassandraSessionPool.Session session,
int count = 0;
for (Iterator<Row> it = rs.iterator(); it.hasNext();) {
Row row = it.next();
// Delete OUT edges from edges_out table
Object ownerVertex = row.getObject(OWNER_VERTEX);
session.add(buildDelete(label, ownerVertex, Directions.OUT));
Object sortValues = row.getObject(SORT_VALUES);
Object otherVertex = row.getObject(OTHER_VERTEX);

// Delete OUT edges from edges_out table
session.add(buildDelete(label, ownerVertex, Directions.OUT,
sortValues, otherVertex));
// Delete IN edges from edges_in table
Object otherVertex = row.getObject(OTHER_VERTEX);
session.add(buildDelete(label, otherVertex, Directions.IN));
session.add(buildDelete(label, otherVertex, Directions.IN,
sortValues, ownerVertex));

count += 2;
if (count >= COMMIT_DELETE_BATCH - 2) {
if (count >= COMMIT_DELETE_BATCH) {
session.commit();
count = 0;
}
}
if (count > 0) {
session.commit();
}
}

private Delete buildDelete(Id label, Object ownerVertex,
Directions direction) {
Directions direction, Object sortValues,
Object otherVertex) {
Delete delete = QueryBuilder.delete().from(edgesTable(direction));
delete.where(formatEQ(HugeKeys.OWNER_VERTEX, ownerVertex));
delete.where(formatEQ(HugeKeys.DIRECTION,
EdgeId.directionToCode(direction)));
delete.where(formatEQ(HugeKeys.LABEL, label.asLong()));
delete.where(formatEQ(HugeKeys.SORT_VALUES, sortValues));
delete.where(formatEQ(HugeKeys.OTHER_VERTEX, otherVertex));
return delete;
}

Expand Down