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

[H5vz3qhy] Prevent cascade trigger transactions #346

Merged
merged 3 commits into from
Mar 30, 2023

Conversation

vga91
Copy link
Collaborator

@vga91 vga91 commented Mar 9, 2023

Added a CALL tx.setMetaData(<TRIGGER_META>) procedure in transactions with phase after and afterAsync,
in order to prevent cascade trigger transactions coming from TriggerHandler itself,
so that we can avoid some deadlock conditions.


I don't know if it is somehow directly related to this pr,
but I had to change the testRemoveNode too,
because it sometimes failed as the previous CREATE (f:Foo) had id = 0.

@vga91 vga91 added the dev label Mar 9, 2023
@@ -35,6 +35,7 @@
public class TriggerHandler extends LifecycleAdapter implements TransactionEventListener<Void> {

private enum Phase {before, after, rollback, afterAsync}
private static final Map<String, Object> TRIGGER_META = Map.of("trigger", true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Map.of("apoc.trigger", true) would be better in my opinion. Just in case people start seeing things in their transactions they don't know where they came from, that's more self explanatory than just trigger

Comment on lines 207 to 209
// if `txData.metaData()` is equal to TRIGGER_META, it means that the transaction
// if it is equal, it means that the transaction comes from another TriggerHandler transaction,
// therefore the execution must be blocked to prevent a deadlock due to cascading transactions
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// if `txData.metaData()` is equal to TRIGGER_META, it means that the transaction
// if it is equal, it means that the transaction comes from another TriggerHandler transaction,
// therefore the execution must be blocked to prevent a deadlock due to cascading transactions
// if `txData.metaData()` is equal to TRIGGER_META, it means that the transaction
// comes from another TriggerHandler transaction,
// therefore the execution must be blocked to prevent a deadlock due to cascading transactions

// if it is equal, it means that the transaction comes from another TriggerHandler transaction,
// therefore the execution must be blocked to prevent a deadlock due to cascading transactions
Map<String, Object> metaData = txData.metaData();
if (metaData.equals(TRIGGER_META)) {
Copy link
Collaborator

@ncordon ncordon Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is personal preference but if you extract this block outside to a function:

public Boolean isTransactionCreatedByTrigger(TransactionData txData) {
  Map<String, Object> metaData = txData.metaData();
  return metaData.equals(TRIGGER_META);
}

then this method becomes more self-documented

@vga91 vga91 merged commit 7c1023d into dev Mar 30, 2023
@vga91 vga91 deleted the prevent-cascade-trigger-transactions branch March 30, 2023 13:52
vga91 added a commit to neo4j-contrib/neo4j-apoc-procedures that referenced this pull request Mar 30, 2023
* [H5vz3qhy] Prevent cascade trigger transactions

* [H5vz3qhy] Changed flaky test

* [H5vz3qhy] Small changes review
vga91 added a commit to neo4j-contrib/neo4j-apoc-procedures that referenced this pull request Mar 30, 2023
* [H5vz3qhy] Prevent cascade trigger transactions

* [H5vz3qhy] Changed flaky test

* [H5vz3qhy] Small changes review
vga91 added a commit to neo4j-contrib/neo4j-apoc-procedures that referenced this pull request Apr 4, 2023
* [H5vz3qhy] Prevent cascade trigger transactions

* [H5vz3qhy] Changed flaky test

* [H5vz3qhy] Small changes review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants