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 remove secondary index of cassandra backend exceeding 65535 limit #386

Merged
merged 1 commit into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
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 @@ -558,12 +558,18 @@ public void delete(CassandraSessionPool.Session session,
}

final String FIELD_VALUES = formatKey(HugeKeys.FIELD_VALUES);
int count = 0;
for (Iterator<Row> it = rs.iterator(); it.hasNext();) {
fieldValues = it.next().get(FIELD_VALUES, String.class);
Delete delete = QueryBuilder.delete().from(this.table());
delete.where(formatEQ(HugeKeys.INDEX_LABEL_ID, indexLabel));
delete.where(formatEQ(HugeKeys.FIELD_VALUES, fieldValues));
session.add(delete);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ public void removeVertices(VertexLabel vertexLabel) {
this.traverseVerticesByLabel(vertexLabel, vertex -> {
this.removeVertex((HugeVertex) vertex);
this.commitIfGtSize(COMMIT_BATCH);
});
}, true);
this.commit();
} catch (Exception e) {
LOG.error("Failed to remove vertices", e);
Expand Down Expand Up @@ -1395,7 +1395,7 @@ public void removeEdges(EdgeLabel edgeLabel) {
this.traverseEdgesByLabel(edgeLabel, edge -> {
this.removeEdge((HugeEdge) edge);
this.commitIfGtSize(COMMIT_BATCH);
});
}, true);
}
this.commit();
} catch (Exception e) {
Expand All @@ -1407,18 +1407,19 @@ public void removeEdges(EdgeLabel edgeLabel) {
}

public void traverseVerticesByLabel(VertexLabel label,
Consumer<Vertex> consumer) {
this.traverseByLabel(label, this::queryVertices, consumer);
Consumer<Vertex> consumer,
boolean remove) {
this.traverseByLabel(label, this::queryVertices, consumer, remove);
}

public void traverseEdgesByLabel(EdgeLabel label,
Consumer<Edge> consumer) {
this.traverseByLabel(label, this::queryEdges, consumer);
public void traverseEdgesByLabel(EdgeLabel label, Consumer<Edge> consumer,
boolean remove) {
this.traverseByLabel(label, this::queryEdges, consumer, remove);
}

private <T> void traverseByLabel(SchemaLabel label,
Function<Query, Iterator<T>> fetcher,
Consumer<T> consumer) {
Consumer<T> consumer, boolean remove) {
HugeType type = label.type() == HugeType.VERTEX_LABEL ?
HugeType.VERTEX : HugeType.EDGE;
ConditionQuery query = new ConditionQuery(type);
Expand Down Expand Up @@ -1449,9 +1450,11 @@ private <T> void traverseByLabel(SchemaLabel label,
query.capacity(Query.NO_CAPACITY);
query.eq(HugeKeys.LABEL, label.id());
int pass = 0;
int counter = 0;
int counter;
do {
query.offset(pass++ * Query.DEFAULT_CAPACITY);
if (!remove) {
query.offset(pass++ * Query.DEFAULT_CAPACITY);
}
// Process every element in current batch
Iterator<T> itor = fetcher.apply(query);
for (counter = 0; itor.hasNext(); ++counter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ private void rebuildIndex(SchemaLabel label, Collection<Id> indexLabelIds) {
if (label.type() == HugeType.VERTEX_LABEL) {
@SuppressWarnings("unchecked")
Consumer<Vertex> consumer = (Consumer<Vertex>) indexUpdater;
graphTx.traverseVerticesByLabel((VertexLabel) label, consumer);
graphTx.traverseVerticesByLabel((VertexLabel) label,
consumer, false);
} else {
assert label.type() == HugeType.EDGE_LABEL;
@SuppressWarnings("unchecked")
Consumer<Edge> consumer = (Consumer<Edge>) indexUpdater;
graphTx.traverseEdgesByLabel((EdgeLabel) label, consumer);
graphTx.traverseEdgesByLabel((EdgeLabel) label,
consumer, false);
}
graphTx.commit();

Expand Down