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

[HFWBmuq2] Fixes #155: Check for correct tx terminations #256

Merged
merged 9 commits into from
Feb 27, 2023
Merged

Conversation

vga91
Copy link
Collaborator

@vga91 vga91 commented Nov 28, 2022

Fixes #155

  • Added terminationGuard.check() where needed.
  • Added various tests via TransactionTestUtil to verify procedures/functions are correctly terminated when the transaction is interrupted.
  • Changed movies.cypher in order to be executed multiple times in BigGraphTest

CREATE (AndyW:Person {name:'Andy Wachowski', born:1967})
CREATE (LanaW:Person {name:'Lana Wachowski', born:1965})
CREATE (JoelS:Person {name:'Joel Silver', born:1952})
CREATE (Keanu:Person:Other {name:'Keanu Reeves', id: randomUUID(), born:1964})
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the same file used for apoc.examples.movies? we should perhaps not change it if it is as it would be a breaking change I imagine, perhaps make a new file for testing purposes instead

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, i didn't noticed it :( Now I created another file

@@ -52,6 +57,12 @@ public Stream<MapResult> runTimeboxed(@Name("statement") String cypher, @Name("p
txAtomic.set(innerTx);
Result result = innerTx.execute(cypher, params == null ? Collections.EMPTY_MAP : params);
while (result.hasNext()) {
if (Util.transactionIsTerminated(terminationGuard)) {
txAtomic.get().close();
offerToQueue(queue, POISON, timeout);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really understand the Posion part here, if the tx is terminated would we not want to just return the same warning as below? I might be missing some context here, so feel free to explain it to me :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A bit strange but without the poison queue, the transaction is marked as terminated but actually continues the execution until it finishes, and after that throws an exception The transaction has been terminated...

Anyway, I realized that the TransactionTestUtil.checkTerminationGuard could potentially produce a false positive, therefore I also added the execution time check (which in fact fails without this POISON)

@@ -190,6 +194,7 @@ private boolean proceedReader(XMLStreamReader reader) throws XMLStreamException
}

private void handleNode(Deque<Map<String, Object>> stack, Node node, boolean simpleMode) {
terminationGuard.check();
Copy link
Contributor

Choose a reason for hiding this comment

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

If this check fails does it throw an exception? do we need to do anything, or just let it happen :) perhaps a comment saying what it does could be useful

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 it throw an exception if the check fails.
Do you mean add a comment for each piece of code with terminationGuard.check()?

However I personally don't think if it's really necessary add a comment, because it's already explained in the org.neo4j.procedure.TerminationGuard interface

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I didn't see the comment in the interface! This is fine then, thanks for explaining :)

// assert query terminated (RETURN 0)
TestUtil.testCall(db, query,
Map.of("innerQuery", innerLongQuery),
row -> assertEquals(Map.of("0", 0L), row.get("value")));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to check warnings returned maybe? (if there is one returned that is)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In this case the log.warn("query " + cypher + " has been terminated") is not returned, because we terminate the inner transaction, so it doesn't execute that piece of code

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see, thanks :)

Copy link
Member

Choose a reason for hiding this comment

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

and afaik there is no way for procedures to add a warning to the Cypher ExecutionContext

final Object actual = ((Map) row.get("updateStatistics")).get("nodesCreated");
assertEquals(0L, actual);
});
fail("Should have terminated");
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this fail give us?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is just to verify that the query really fails, because of terminationGuard, and don't go ahead without errors.

@@ -41,8 +42,19 @@ public static boolean terminateQuery(String pattern, GraphDatabaseAPI db) {
return numberOfKilledTransactions > 0;
}

// todo - we could get rid of this method (and related code), and leverage the TransactionTestUtil.testTerminateWithCommand
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer todos are added as Trello tickets instead of in the code :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added the trello ticket, id aWY2zoX5 in Low priority column,
but I can always move it elsewhere, in case :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome, thanks

return false;
}
transactionId[0] = msgIterator.next();
return transactionId[0] != null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the transactionId an array and not just a string?


@Test
public void shouldTerminateLoadWhenTransactionIsTimedOut() {
final String query = "CALL apoc.load.json('https://github.com/knowitall/yelp-dataset-challenge/blob/master/data/yelp_phoenix_academic_dataset/yelp_academic_dataset_review.json?raw=truehttps://github.com/knowitall/yelp-dataset-challenge/blob/master/data/yelp_phoenix_academic_dataset/yelp_academic_dataset_review.json?raw=true')";
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer you didn't reference external resources in case it is deleted in the future, is it possible to add to this repo instead?

Copy link
Contributor

@gem-neo4j gem-neo4j left a comment

Choose a reason for hiding this comment

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

Nice work with this :)

@vga91 vga91 force-pushed the issue_155 branch 2 times, most recently from 3d226f2 to 9622843 Compare December 15, 2022 15:18
@jexp
Copy link
Member

jexp commented Dec 15, 2022

@gem-neo4j are we good to merge this one?

@gem-neo4j
Copy link
Contributor

@jexp yep :) after a green build it will be

@vga91 vga91 force-pushed the issue_155 branch 3 times, most recently from 0a919cf to c24687b Compare January 5, 2023 16:29
@vga91 vga91 force-pushed the issue_155 branch 3 times, most recently from 9e813d9 to 7dc7d9a Compare January 17, 2023 14:11
@vga91 vga91 force-pushed the issue_155 branch 2 times, most recently from 53907c8 to a008e94 Compare January 23, 2023 08:26
@CLAassistant
Copy link

CLAassistant commented Jan 24, 2023

CLA assistant check
All committers have signed the CLA.

@vga91 vga91 force-pushed the issue_155 branch 4 times, most recently from 0fc7e82 to b15b3ad Compare February 22, 2023 13:10
@vga91 vga91 merged commit ab6d58a into dev Feb 27, 2023
@vga91 vga91 deleted the issue_155 branch February 27, 2023 08:13
vga91 added a commit to neo4j-contrib/neo4j-apoc-procedures that referenced this pull request Apr 17, 2023
…eo4j/apoc#256)

* [HFWBmuq2] Fixes neo4j/apoc#155: Check for correct tx terminations

* [HFWBmuq2] Code clean

* [HFWBmuq2] removed unused code

* [HFWBmuq2] try solving flaky tests

* [HFWBmuq2] changes review - added time check

* [HFWBmuq2] added local file tests - small changes

* [HFWBmuq2] removed unused imports after rebase

* [HFWBmuq2] fix flaky transaction not found error

* [HFWBmuq2] Fix heapspace and flaky errors
vga91 added a commit to neo4j-contrib/neo4j-apoc-procedures that referenced this pull request May 17, 2023
…eo4j/apoc#256)

* [HFWBmuq2] Fixes neo4j/apoc#155: Check for correct tx terminations

* [HFWBmuq2] Code clean

* [HFWBmuq2] removed unused code

* [HFWBmuq2] try solving flaky tests

* [HFWBmuq2] changes review - added time check

* [HFWBmuq2] added local file tests - small changes

* [HFWBmuq2] removed unused imports after rebase

* [HFWBmuq2] fix flaky transaction not found error

* [HFWBmuq2] Fix heapspace and flaky errors
vga91 added a commit to neo4j-contrib/neo4j-apoc-procedures that referenced this pull request Jun 21, 2023
…eo4j/apoc#256)

* [HFWBmuq2] Fixes neo4j/apoc#155: Check for correct tx terminations

* [HFWBmuq2] Code clean

* [HFWBmuq2] removed unused code

* [HFWBmuq2] try solving flaky tests

* [HFWBmuq2] changes review - added time check

* [HFWBmuq2] added local file tests - small changes

* [HFWBmuq2] removed unused imports after rebase

* [HFWBmuq2] fix flaky transaction not found error

* [HFWBmuq2] Fix heapspace and flaky errors
vga91 added a commit to neo4j-contrib/neo4j-apoc-procedures that referenced this pull request Jun 27, 2023
…eo4j/apoc#256)

* [HFWBmuq2] Fixes neo4j/apoc#155: Check for correct tx terminations

* [HFWBmuq2] Code clean

* [HFWBmuq2] removed unused code

* [HFWBmuq2] try solving flaky tests

* [HFWBmuq2] changes review - added time check

* [HFWBmuq2] added local file tests - small changes

* [HFWBmuq2] removed unused imports after rebase

* [HFWBmuq2] fix flaky transaction not found error

* [HFWBmuq2] Fix heapspace and flaky errors
vga91 added a commit to neo4j-contrib/neo4j-apoc-procedures that referenced this pull request Jun 29, 2023
…eo4j/apoc#256) (#3534)

* [HFWBmuq2] Fixes neo4j/apoc#155: Check for correct tx terminations (neo4j/apoc#256)

* [HFWBmuq2] Fixes neo4j/apoc#155: Check for correct tx terminations

* [HFWBmuq2] Code clean

* [HFWBmuq2] removed unused code

* [HFWBmuq2] try solving flaky tests

* [HFWBmuq2] changes review - added time check

* [HFWBmuq2] added local file tests - small changes

* [HFWBmuq2] removed unused imports after rebase

* [HFWBmuq2] fix flaky transaction not found error

* [HFWBmuq2] Fix heapspace and flaky errors

* [HFWBmuq2] [Bc2lkk3N] Fixed testImportCsvTerminate and added TerminationGuard to apoc.import.csv (neo4j/apoc#343)

* [Bc2lkk3N] Fix testImportCsvTerminate and add TerminationGuard to apoc.import.csv

* [Bc2lkk3N] Fix failing tests

* [Bc2lkk3N] Fix typo

* [HFWBmuq2] fix compile error

* [HFWBmuq2] remove imports

* [HFWBmuq2] fix flaky Timeboxed error

* [HFWBmuq2] removed unused imports
BennuFire pushed a commit to BennuFire/neo4j-apoc-procedures that referenced this pull request Jul 10, 2023
…eo4j/apoc#256) (neo4j-contrib#3534)

* [HFWBmuq2] Fixes neo4j/apoc#155: Check for correct tx terminations (neo4j/apoc#256)

* [HFWBmuq2] Fixes neo4j/apoc#155: Check for correct tx terminations

* [HFWBmuq2] Code clean

* [HFWBmuq2] removed unused code

* [HFWBmuq2] try solving flaky tests

* [HFWBmuq2] changes review - added time check

* [HFWBmuq2] added local file tests - small changes

* [HFWBmuq2] removed unused imports after rebase

* [HFWBmuq2] fix flaky transaction not found error

* [HFWBmuq2] Fix heapspace and flaky errors

* [HFWBmuq2] [Bc2lkk3N] Fixed testImportCsvTerminate and added TerminationGuard to apoc.import.csv (neo4j/apoc#343)

* [Bc2lkk3N] Fix testImportCsvTerminate and add TerminationGuard to apoc.import.csv

* [Bc2lkk3N] Fix failing tests

* [Bc2lkk3N] Fix typo

* [HFWBmuq2] fix compile error

* [HFWBmuq2] remove imports

* [HFWBmuq2] fix flaky Timeboxed error

* [HFWBmuq2] removed unused imports
BennuFire pushed a commit to neo4j-contrib/neo4j-apoc-procedures that referenced this pull request Jul 10, 2023
…eo4j/apoc#256) (#3534)

* [HFWBmuq2] Fixes neo4j/apoc#155: Check for correct tx terminations (neo4j/apoc#256)

* [HFWBmuq2] Fixes neo4j/apoc#155: Check for correct tx terminations

* [HFWBmuq2] Code clean

* [HFWBmuq2] removed unused code

* [HFWBmuq2] try solving flaky tests

* [HFWBmuq2] changes review - added time check

* [HFWBmuq2] added local file tests - small changes

* [HFWBmuq2] removed unused imports after rebase

* [HFWBmuq2] fix flaky transaction not found error

* [HFWBmuq2] Fix heapspace and flaky errors

* [HFWBmuq2] [Bc2lkk3N] Fixed testImportCsvTerminate and added TerminationGuard to apoc.import.csv (neo4j/apoc#343)

* [Bc2lkk3N] Fix testImportCsvTerminate and add TerminationGuard to apoc.import.csv

* [Bc2lkk3N] Fix failing tests

* [Bc2lkk3N] Fix typo

* [HFWBmuq2] fix compile error

* [HFWBmuq2] remove imports

* [HFWBmuq2] fix flaky Timeboxed error

* [HFWBmuq2] removed unused imports
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.

check for tx termination
4 participants