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

Run response immediate processing update #897

Merged
merged 7 commits into from Jun 18, 2021

Conversation

injectives
Copy link
Contributor

@injectives injectives commented May 24, 2021

This update makes run methods (session, tx) wait for successful request acknowledgement by the server. Specifically, the Result object will only be returned when there is a successful response from the server to the RUN message, meaning that the request was at least accepted by the server for processing. Otherwise, an appropriate error will be thrown.

Additionally, this update also makes the Result.keys method non-blocking and free from potential communication errors.

@injectives injectives marked this pull request as draft May 24, 2021 22:04
@injectives injectives force-pushed the feature/runprocessing branch 17 times, most recently from dfc7a49 to 9ab3f57 Compare June 1, 2021 15:59
@injectives injectives marked this pull request as ready for review June 1, 2021 15:59
Copy link
Contributor

@michael-simons michael-simons left a comment

Choose a reason for hiding this comment

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

From what I understand it seems to make sense. Looks at least simpler in a positive way.
The core idea is not to pass that boolean to ResultCursorFactoryImpl and a new runFuture, right?
Could you elaborate a bit more on the purpose of that runFucture? By maybe choosing a different name?

@injectives
Copy link
Contributor Author

The core idea is not to pass that boolean to ResultCursorFactoryImpl and a new runFuture, right?

Basically, yes. The waitForRunResponse did not make sense anymore given the goal of these changes. From API perspective, the main objective is to improve the run methods handling by making sure we only return Result object when server successfully accepts the RUN Bolt message (details). In such way the Result object represents a successful acceptance of the request by the server. Otherwise, an error must be thrown.
Previously, it would return Result object in most cases, even if waitForRunResponse was set to true. For instance, see the previous implementation. Keep in mind that runFuture() used to return CompletableFuture<Throwable>.
The new runFuture if part of achieving the aforementioned goal.

@injectives
Copy link
Contributor Author

Could you elaborate a bit more on the purpose of that runFucture? By maybe choosing a different name?

Basic ResponseHandler implementations take CompletableFuture (or something similar) that is meant to contain the processed response. They are responsible for completing it when appropriate. For instance:

  • beginTxFuture in (BeginTxResponseHandler)[https://github.com/neo4j/neo4j-java-driver/blob/4.3/driver/src/main/java/org/neo4j/driver/internal/handlers/BeginTxResponseHandler.java#L32]
  • commitFuture in (CommitTxResponseHandler)[https://github.com/neo4j/neo4j-java-driver/blob/4.3/driver/src/main/java/org/neo4j/driver/internal/handlers/CommitTxResponseHandler.java#L34]
  • rollbackFuture in (RollbackTxResponseHandler)[https://github.com/neo4j/neo4j-java-driver/blob/4.3/driver/src/main/java/org/neo4j/driver/internal/handlers/RollbackTxResponseHandler.java#L32]
  • completionFuture in (ResetResponseHandler)[https://github.com/neo4j/neo4j-java-driver/blob/4.3/driver/src/main/java/org/neo4j/driver/internal/handlers/ResetResponseHandler.java#L31]
  • completableFuture in (RouteMessageResponseHandler)[https://github.com/neo4j/neo4j-java-driver/blob/4.3/driver/src/main/java/org/neo4j/driver/internal/handlers/RouteMessageResponseHandler.java#L38]
  • etc.

Following this approach, the runFuture is meant to contain the processed response. I am happy to rename it to something else, I just though it could be better to keep the naming similar to other handlers in this change. While there is actually some discrepancy in names, this 'action'Future pattern seems to be a fairly common in the current implementation.

How about introducing doing a separate pull request and introducing a new common naming, like 'action`CompletionFuture (subject to discussion in that PR)? It might be easier from review standpoint.

@michael-simons
Copy link
Contributor

Following this approach, the runFuture is meant to contain the processed response. I am happy to rename it to something else, I just though it could be better to keep the naming similar to other handlers in this change. While there is actually some discrepancy in names, this 'action'Future pattern seems to be a fairly common in the current implementation.

I think responseFuture would fit than.

@injectives
Copy link
Contributor Author

Following this approach, the runFuture is meant to contain the processed response. I am happy to rename it to something else, I just though it could be better to keep the naming similar to other handlers in this change. While there is actually some discrepancy in names, this 'action'Future pattern seems to be a fairly common in the current implementation.

I think responseFuture would fit than.

As discussed, a separate PR will be created with renames to make them easier to review.

@injectives injectives force-pushed the feature/runprocessing branch 5 times, most recently from f9cc023 to 86b6606 Compare June 8, 2021 11:42
@injectives injectives force-pushed the feature/runprocessing branch 4 times, most recently from 605194f to 38ff211 Compare June 8, 2021 14:45
This update makes `run` methods (session, tx) wait for successful request acknowledgement by the server. Specifically, the `Result` object will only be returned when there is a successful response from the server to the `RUN` message, meaning that the request was at least accepted by the server for processing. Otherwise, an appropriate error will be thrown.

Additionally, this update makes the `Result.keys` method non-blocking and free from potential communication errors.
@injectives injectives force-pushed the feature/runprocessing branch 2 times, most recently from 9e8e6ad to e0df679 Compare June 8, 2021 16:40
@injectives injectives requested a review from gjmwoods June 9, 2021 10:48
Copy link
Contributor

@michael-simons michael-simons left a comment

Choose a reason for hiding this comment

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

Thanks for the excellent walkthrough. I have tested the change afterwards with

  • Neo4j-OGM 3.2.25-SNAPSHOT (no failures)
  • Cypher-DSL main (no failures)
  • Spring Data Neo4j 6.0.10-SNAPSHOT (one failure)

The failure was caused indirectly by our autoclosable query runner as it swallowed the target exception (see change here spring-projects/spring-data-neo4j@dcd422d).

We wouldn't have noticed the change in behavior otherwise, as we only consume via

try {
    var result = s.run();
    result.consume(); // or list, whatever
} catch(Whatever e) {
}

So in any case an exception would be handled.

Having said that, I would agree bringing this into the next patch.

@injectives injectives merged commit 575bbae into neo4j:4.3 Jun 18, 2021
@injectives injectives deleted the feature/runprocessing branch June 18, 2021 13:08
michael-simons added a commit to neo4j/neo4j-ogm that referenced this pull request May 23, 2022
This cataches and translations `ClientException` into the generic
Neo4j-OGM `CypherException` while consuming the results too.

It should fix
spring-projects/spring-data-neo4j#2542 and is
most likely necessary to encounter for the changes in
neo4j/neo4j-java-driver#897.
michael-simons added a commit to neo4j/neo4j-ogm that referenced this pull request May 30, 2022
This cataches and translations `ClientException` into the generic
Neo4j-OGM `CypherException` while consuming the results too.

It should fix
spring-projects/spring-data-neo4j#2542 and is
most likely necessary to encounter for the changes in
neo4j/neo4j-java-driver#897.
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.

None yet

3 participants