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

Add pipelining #99

Closed
stefanak-michal opened this issue Jul 28, 2022 · 2 comments
Closed

Add pipelining #99

stefanak-michal opened this issue Jul 28, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@stefanak-michal
Copy link
Collaborator

Add support for pipelining bolt messages https://www.neo4j.com/docs/bolt/current/bolt/message/#pipelining

Messages may also be pipelined. In other words, clients may send multiple requests eagerly without first waiting for responses. When a failure occurs in this scenario, servers must ignore all subsequent requests until the client has explicitly acknowledged receipt of the failure. This prevents inadvertent execution of queries that may not be valid. More details of this process can be found in the sections below.

@stefanak-michal
Copy link
Collaborator Author

stefanak-michal commented Aug 2, 2022

I reverted added pipelining because the implementation wasn't very good. I'm still in the process of thinking how to do it properly. Currently I'm working on branch https://github.com/neo4j-php/Bolt/tree/traits_pipeline where I did some interesting changes in approach.

you can do this:

$res = iterator_to_array(
    $protocol
        ->begin()
        ->run('CREATE (a:Test) RETURN a, ID(a)')
        ->pull()
        ->rollback()
        ->getResponse()
);

Variable $res will be array with this indexes and context:

  • 0 - response from begin
  • 1 - response from run
  • 2 - record message from pull
  • 3 - meta message from pull
  • 4 - response from rollback

You can chain all methods beside hello and goodbye.

Reading data from database output buffer is continuously and getResponse is using yield for every readed message from buffer. Also getResponse has parameter limit which you can use to limit how many messages to read from buffer (maybe also add skip?).

Any ideas or feedback?

@stefanak-michal
Copy link
Collaborator Author

stefanak-michal commented Aug 2, 2022

01b9c0a

Added new \Bolt\protocol\Response class for all readed messages from host. This class contains called bolt message, result signature and response content. https://github.com/neo4j-php/Bolt/blob/traits_pipeline/src/protocol/Response.php

Removed throwing MessageException and IgnoredException because handling of these can be based on Response instance in implementation of this library.

Changed protocol method for reading response, now it has two methods: getResponse for one Response and getResponses to get Iterator.

Usage with getResponse

$protocol
    ->run('RETURN 1 AS num')
    ->pull();

$runResponse = $protocol->getResponse(); // \Bolt\protocol\Response(RUN, SUCCESS, [content])
$pullRecord = $protocol->getResponse(); // \Bolt\protocol\Response(PULL, RECORD, [content])
$pullMeta = $protocol->getResponse(); // \Bolt\protocol\Response(PULL, SUCCESS, [content])

Usage with getResponses

$gen = $protocol
    ->run('RETURN 1 AS num')
    ->pull()
    ->getResponses();

foreach ($gen as $response) {
    // logic
}

@stefanak-michal stefanak-michal added this to the v5 milestone Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant