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

Fixes #2034: The procedure apoc.cypher.mapParallel2 sometime fails with Unable to complete transaction error #2061

Merged
merged 3 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 6 additions & 5 deletions full/src/main/java/apoc/cypher/CypherExtended.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,12 @@ public Stream<MapResult> mapParallel2(@Name("fragment") String fragment, @Name("
Util.inFuture(pools, () -> {
long total = parallelPartitions
.map((List<Object> partition) -> {
try {
try (Result result = tx.execute(statement, parallelParams(params, "_", partition))) {
return consumeResult(result, queue, false, timeout);
}
} catch (Exception e) {throw new RuntimeException(e);}}
try (Transaction transaction = db.beginTx();
Result result = transaction.execute(statement, parallelParams(params, "_", partition))) {
return consumeResult(result, queue, false, timeout);
} catch (Exception e) {
throw new RuntimeException(e);
}}
).count();
queue.put(RowResult.TOMBSTONE);
return total;
Expand Down
13 changes: 13 additions & 0 deletions full/src/test/java/apoc/cypher/CypherExtendedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,19 @@ public void testRunFileWithResults() throws Exception {
assertEquals(false, r.hasNext());
});
}

@Test
public void shouldNotFailWithTransactionErrorWithMapParallel2() {
// Flaky test. Sometimes it's green even without `db.beginTx()` modification
fbiville marked this conversation as resolved.
Show resolved Hide resolved
db.executeTransactionally("UNWIND range(1, 100) as i create (p:Page {title: i})-[:Link]->(p1:Page1)<-[:Link]-(p2:Page2 {title: 'myTitle'})");
testResult(db, "MATCH (p:Page) WITH collect(p) as pages\n" +
"CALL apoc.cypher.mapParallel2(\"MATCH (_)-[:Link]->(p1)<-[:Link]-(p2)\n" +
"RETURN p2.title as title\", {}, pages, 1) yield value\n" +
"RETURN value.title limit 5",
r -> assertEquals(5, Iterators.count(r)));
}


@Test
public void testRunFileWithParameters() throws Exception {
testResult(db, "CALL apoc.cypher.runFile('parameterized.cypher', {statistics:false,parameters:{foo:123,bar:'baz'}})",
Expand Down