[bug] Nested transaction with batch-mode do not flush batch on commit #3564
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.
Hi Rob,
we found an issue with nested transactions utilizing the batch mode.
We are using an outer transaction with a nested transaction for which we turn on batch mode, since we first do a lot of inserts of the same type and afterwards run some updates on the same type. Between the inserts and the updates we do an explicit flush, but after the updates we "just commit" the transaction and close the nested one to return to the parent without batching (see previous issue #3538 ). Our expectation would be, that the commit while not actually commiting the underlying transaction due to nesting, would at least flush the batch control since batching is turned off for the outer transaction, but this doesn't happen.
We discovered this, because we did multiple of these nested transactions with batch mode in sequence and statments in the following transactions conflicted with unflushed statements once the actual flush occured.
I'm currently not completely sure how to fix this. A simple solution is to just call
txn.flush()inScopeTrans#commitTransaction, but maybe this should only be done, whe the batch mode is active for the inner transaction but not the outer one. Additionally there might be other factors in play (e. g. PersistListeners, maybe more) which might need to be handled as well (PersistListeners would already be called on flush).What is your opinion on this issue? Would my suggested fix be enough or could this cause different problems?
All the best
Jonas