Fixes the Cypher files execution not happening sequentially #2707
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
Fixes
runFiles
so that the execution happens sequentially, rather than in parallel.It wasn't working because of two reasons:
runManyStatements
, which starts a thread. Which means all threads were started effectively at the same time for the different files it receives as input.Stream.reduce
doesn't have good semantics to achieve the sequential execution either. On the one hand it's eager (or terminal as they call it in the docs), which means the threads are fired when we call the reduce phase and not when the stream is consumed. On the other hand it asks for associativity, which means we could group operations like (read the+
as in execute the operation, not just concatenating them, since we have said it's eager):flatMap
on the other hand is an intermediate operation (it creates a lazy stream) and the threads will not be fired until the Stream is consumed.Why
apoc.cypher.runFiles
andapoc.cypher.runSchemaFile
were not being executed sequentially.That was a problem creating flakiness in the modified
testRunFilesMultiple
test.It was reproducible doing
apoc.cypher.runFiles
with the following (added in the PR to the test) files:and