Skip to content

Routing driver #141

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

Merged
merged 18 commits into from
Oct 28, 2016
Merged

Routing driver #141

merged 18 commits into from
Oct 28, 2016

Conversation

pontusmelke
Copy link
Contributor

@pontusmelke pontusmelke commented Sep 20, 2016

Support for routing operations in the js driver:

Usage:

let driver = neo4j.driver("bolt+routing://127.0.0.1:9001", neo4j.auth.basic("neo4j", "neo4j"));
let session = driver.session(neo4j.session.WRITE);
let tx = session.beginTransaction();

tx.run('CREATE ()');

tx.commit()
    .then((results) => {/*handle results*/})
    .catch((err) => {
       if (err.code === neo4j.error.SESSION_EXPIRED) {
         //session expired, ask the driver for a new one and replay
       } else if (err.code === neo4j.error.SERVICE_UNAVAILABLE) {
         //driver has no contact with the cluster, recreate the driver and replay
       } else {
         //a "normal error" has occurred handle it appropriately
      }

By using the scheme bolt+routing the driver will ask the seed server to provide a view of the current cluster, which contains information on where to direct read requests, write requests and where to direct new routing requests. The driver maintains this information and will automatically spread the load among these servers. If servers go offline the driver will remove them and when running out of servers a new routing request will be performed to refresh the view of the cluster. The return from the routing request also contains a ttl, when this time has expired the driver will also refresh the cluster view.

On running requests two types of errors can happen:

  • SESSION_EXPIRED: Means that the server is unable to perform the current action, the application should ask for a new session from the driver and retry the operation.
  • SERVICE_UNAVAILABLE: The driver has completely lost contact with the cluster, the driver needs to be recreated in order for any new operations to be possible.

@pontusmelke pontusmelke force-pushed the 1.1-routing branch 2 times, most recently from 59d8b03 to 822a438 Compare October 5, 2016 17:31
@pontusmelke pontusmelke changed the title Extended pool to handle multiple keys Routing driver Oct 7, 2016
The connection pool now handles connections to multiple URI, this work
is a precursor to handling multiple connections in the driver.
We need purging of item in the connection pool since we need a way of removing connections
that are no longer online or in other ways have been removed from a cluster.
Updating to babel 6 required significant changes mostly on how we do
export and import since babel 6 is more strict than babel 5.
Instead of keeping a connection `Session` and `Transaction` now keep
a promise to a connection instead of a resolved connection.
Support routing on session acquistion.
If the response from `getServers` contains an empty `writers` list we should
reject that answer and procede to the next available router.
index = this._items.indexOf(item, index);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively you could move the _index manipulation logic into next so that it does bounds checking and adjustment before using the value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

splice does in-place rewrite of the array I want to be sure that the index is up-to-date after each removal in the loop

@pontusmelke pontusmelke merged commit 93807c3 into neo4j:1.1 Oct 28, 2016
@pontusmelke pontusmelke deleted the 1.1-routing branch October 28, 2016 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants