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

[madSHaLz] APOC triggers aren't updated after a user deletes a database #348

Merged
merged 5 commits into from
Apr 26, 2023

Conversation

vga91
Copy link
Collaborator

@vga91 vga91 commented Mar 14, 2023

Implemented 3rd solution - DatabaseEventListener,
so that we can delete every system node belonging to the database that we delete.

Added a cleanUpSystemNodes() for backward compatibility

@vga91 vga91 force-pushed the delete-trigger-after-drop-database branch from a23e84c to 6a2fca5 Compare March 14, 2023 10:53
Comment on lines 91 to 95

// this block is already in system db, so we can directly execute system operation
// for backward compatibility: clear system nodes at start-up if the corresponding database name doesn't exist
// placed here instead of e.g. `ApocConfig` because at this point we are sure that all databases are recovered
cleanUpSystemNodes();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is true. Databases are brought up in an eventual consistent way in 5.x so when system is up neo4j could not be up

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes indeed it is not safe.
I've been looking for other ways to do this but I don't think there is currently a method that isn't completely error prone, but maybe I'm missing something.

Perhaps it's better not to do this thing at all and document somewhere that for backward compatibility we have to delete the triggers manually. Wdyt?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps it's better not to do this thing at all and document somewhere that for backward compatibility we have to delete the triggers manually. Wdyt?

I think that's a better option definitely

@vga91 vga91 force-pushed the delete-trigger-after-drop-database branch from 6a2fca5 to d7df89d Compare April 8, 2023 08:40
@vga91 vga91 force-pushed the delete-trigger-after-drop-database branch from feac91d to 22c9aad Compare April 13, 2023 18:15
import static apoc.trigger.TriggerTestUtil.TRIGGER_DEFAULT_REFRESH;
import static apoc.trigger.TriggerTestUtil.awaitTriggerDiscovered;
import static apoc.util.TestUtil.waitDbsAvailable;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think these imports are not needed anymore?

Comment on lines 192 to 210
// same as above with the database `initDb`, created via apoc.initializer.*
testCall(sysSession, "CALL apoc.trigger.install($dbName, $name, 'return 1', {})",
Map.of("dbName", INIT_DB, "name", defaultTriggerName),
r -> assertEquals(defaultTriggerName, r.get("name"))
);

testCall(sysSession, "CALL apoc.trigger.show($dbName)",
Map.of("dbName", INIT_DB),
r -> assertEquals(defaultTriggerName, r.get("name"))
);

// drop database
sysSession.writeTransaction(tx -> tx.run(String.format("DROP DATABASE %s WAIT;", INIT_DB)));

// check that the trigger has been removed
testCallEmpty(sysSession, "CALL apoc.trigger.show($dbName)",
Map.of("dbName", INIT_DB)
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you split this into another test please?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Separated

Copy link
Collaborator

@ncordon ncordon left a comment

Choose a reason for hiding this comment

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

Just minor nitpicks, happy to approve after those comments have been addressed

@ncordon
Copy link
Collaborator

ncordon commented Apr 21, 2023

Feel free to merge, we can fix the Snyk issues in another PR, as they are related to dependencies that they've just deemed are insecure

@vga91 vga91 merged commit 95c36aa into dev Apr 26, 2023
@vga91 vga91 deleted the delete-trigger-after-drop-database branch April 26, 2023 07:41
vga91 added a commit to neo4j-contrib/neo4j-apoc-procedures that referenced this pull request Apr 28, 2023
…se (neo4j/apoc#348)

* [madSHaLz] APOC triggers aren't updated after a user deletes a database

* [madSHaLz] changes review

* [madSHaLz] removed no longer valid test

* [madSHaLz] split test

---------

Co-authored-by: Nacho Cordón <[email protected]>
vga91 added a commit to neo4j-contrib/neo4j-apoc-procedures that referenced this pull request May 5, 2023
…se (neo4j/apoc#348)

* [madSHaLz] APOC triggers aren't updated after a user deletes a database

* [madSHaLz] changes review

* [madSHaLz] removed no longer valid test

* [madSHaLz] split test

---------

Co-authored-by: Nacho Cordón <[email protected]>
vga91 added a commit to neo4j-contrib/neo4j-apoc-procedures that referenced this pull request May 5, 2023
…se (neo4j/apoc#348) (#3550)

* [madSHaLz] APOC triggers aren't updated after a user deletes a database

* [madSHaLz] changes review

* [madSHaLz] removed no longer valid test

* [madSHaLz] split test

---------

Co-authored-by: Nacho Cordón <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants