Skip to content

Commit

Permalink
Commit index updates in batch
Browse files Browse the repository at this point in the history
To avoid commit all together during rebuilding index,
especially for Cassandra backend, which has batch limit 65535

fixed: #144
implemented: #82

Change-Id: I88ff4bc878bc24122f0bb6ecf9964246a083b9ab
  • Loading branch information
zhoney authored and Linary committed Oct 30, 2018
1 parent 15e9fc6 commit c02ed71
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,12 @@ public boolean closed() {
return this.refs.get() == 0;
}

public void commitIfGtSize(int size) {
// Only committing graph transaction data if reaching batch size
// is OK, bacause schema transaction is auto committed.
this.graphTransaction().commitIfGtSize(size);
}

@Override
public void commit() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public interface Transaction {

public void commit() throws BackendException;

public void commitIfGtSize(int size) throws BackendException;

public void rollback() throws BackendException;

public boolean autoCommit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ public void commit() throws BackendException {
}
}

public void commitIfGtSize(int size) throws BackendException {
if (this.mutationSize() >= size) {
this.commit();
}
}

@Watched(prefix = "tx")
@Override
public void rollback() throws BackendException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class GraphIndexTransaction extends AbstractTransaction {

private static final String INDEX_EMPTY_SYM = "\u0000";
private static final Query EMPTY_QUERY = new ConditionQuery(null);
private static final int REBUILD_COMMIT_BATCH = 1000;

private final Analyzer textAnalyzer;

Expand Down Expand Up @@ -1111,6 +1112,9 @@ public void rebuildIndex(HugeType type, Id label,
HugeVertex vertex = (HugeVertex) itor.next();
for (Id id : indexLabelIds) {
this.updateIndex(id, vertex, false);
// Commit per small batch to avoid too much data
// in single commit, especially for Cassandra backend.
this.commitIfGtSize(REBUILD_COMMIT_BATCH);
}
}
} else {
Expand All @@ -1123,6 +1127,9 @@ public void rebuildIndex(HugeType type, Id label,
HugeEdge edge = (HugeEdge) itor.next();
for (Id id : indexLabelIds) {
this.updateIndex(id, edge, false);
// Commit per small batch to avoid too much data
// in single commit, especially for Cassandra backend.
this.commitIfGtSize(REBUILD_COMMIT_BATCH);
}
}
}
Expand Down

0 comments on commit c02ed71

Please sign in to comment.