Skip to content

Introduce Bookmark Manager #974

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 43 commits into from
Sep 2, 2022
Merged

Conversation

bigmontz
Copy link
Contributor

@bigmontz bigmontz commented Aug 1, 2022

Neo4j clusters are causally consistent, meaning that by default there is no guarantee a query will be able to read changes made by a previous query. For cases where such a guarantee is necessary, the server provides bookmarks to the client. A bookmark is an abstract token that represents some state of the database. By passing one or multiple bookmarks along with a query, the server will make sure that the query will not get executed before the represented state(s) (or a later state) have been established.

The bookmark manager is an interface used by the driver for keeping track of the bookmarks and this way keeping sessions automatically consistent.

Usage in the session

Enabling it is done by supplying an BookmarkManager implementation instance to this param.
A default implementation could be acquired by calling the factory function neo4j.bookmarkManager().

Warning: Share the same BookmarkManager instance across all session can have a negative impact
on performance since all the queries will wait for the latest changes being propagated across the cluster.
For keeping consistency between a group of queries, use Session for grouping them.
For keeping consistency between a group of sessions, use BookmarkManager instance for grouping them.

const bookmarkManager = neo4j.bookmarkManager()
const linkedSession1 = driver.session({ database:'neo4j', bookmarkManager })
const linkedSession2 = driver.session({ database:'neo4j', bookmarkManager })
const unlinkedSession = driver.session({ database:'neo4j' })

// Creating Driver User
const createUserQueryResult = await linkedSession1.run('CREATE (p:Person {name: $name})', { name: 'Driver User'})

// Reading Driver User will *NOT* wait of the changes being propagated to the server before RUN the query
// So the 'Driver User' person might not exist in the Result
const unlinkedReadResult = await unlinkedSession.run('CREATE (p:Person {name: $name}) RETURN p', { name: 'Driver User'})

// Reading Driver User will wait of the changes being propagated to the server before RUN the query
// So the 'Driver User' person should exist in the Result, unless deleted.
const linkedSession2 = await linkedSession2.run('CREATE (p:Person {name: $name}) RETURN p', { name: 'Driver User'})

await linkedSession1.close()
await linkedSession2.close()
await unlinkedSession.close()

@bigmontz bigmontz force-pushed the 5.0-bookmark-manager branch from 166df47 to 30785e5 Compare August 12, 2022 10:17
@bigmontz bigmontz marked this pull request as ready for review August 12, 2022 12:35
@bigmontz bigmontz force-pushed the 5.0-bookmark-manager branch from 30785e5 to 2e4bf21 Compare August 17, 2022 14:38
@robsdedude robsdedude self-requested a review August 18, 2022 16:39
Copy link
Member

@robsdedude robsdedude left a comment

Choose a reason for hiding this comment

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

🔖 :bowtie:

@bigmontz bigmontz force-pushed the 5.0-bookmark-manager branch from d09bbd9 to 8575825 Compare August 31, 2022 10:57
@bigmontz bigmontz force-pushed the 5.0-bookmark-manager branch 4 times, most recently from 0726ae4 to 7af8730 Compare September 1, 2022 15:19
Copy link
Member

@robsdedude robsdedude left a comment

Choose a reason for hiding this comment

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

⏱️

@bigmontz
Copy link
Contributor Author

bigmontz commented Sep 2, 2022

Depends on: neo4j-drivers/testkit#513

@bigmontz bigmontz force-pushed the 5.0-bookmark-manager branch from 177e5d0 to 28cd7cf Compare September 2, 2022 14:00
@bigmontz bigmontz merged commit 42e5855 into neo4j:5.0 Sep 2, 2022
@bigmontz bigmontz deleted the 5.0-bookmark-manager branch September 2, 2022 16:12
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.

3 participants