Database transactions
Every query run through gds.run_cypher() is executed inside a transaction.
Transaction types
By default, queries are run in driver-managed transactions, which are automatically retried on transient errors.
For more details about these transactions, see the Neo4j Python driver.
Queries using CALL { … } IN TRANSACTIONS are not supported by driver-managed transactions.
Use the auto_commit parameter to run a query in an auto-commit transaction instead.
Auto-commit transactions are the only transaction type supporting CALL { … } IN TRANSACTIONS, which splits the work into multiple server-side transactions.
This is useful for large write operations, such as batch imports or deletes, as every batch is committed separately and stays within the transaction memory limit.
CALL { … } IN TRANSACTIONSgds.run_cypher(
"""
MATCH (n)
CALL (n) {
DETACH DELETE n
} IN TRANSACTIONS
""",
auto_commit=True,
)
Unlike driver-managed transactions, auto-commit transactions are only retried by the driver when the server marks the query as idempotent. Use the auto_commit parameter only for queries that require it.
|
Coordinate parallel transactions
A bookmark is a marker representing a state of the database. Bookmarks are useful when subsequent transactions in a cluster need to be coordinated, for example when you need to read data right after writing it.
When using the GDS client, any query following a call to gds.set_bookmarks() is not executed until the bookmarked transactions are propagated across the cluster.
gds.run_cypher("""
CREATE (:Person {name: "Alice"})-[:KNOWS]->(:Person {name: "Bob"})
""")
# Make sure the next queries will be executed after the CREATE query is fully propagated through the cluster
gds.set_bookmarks(gds.last_bookmarks())
G, _ = gds.graph.project.native("myGraph", ["Person"], ["KNOWS"])
gds.page_rank.write(G, write_property="pagerank")
# Make sure the next queries will be executed after the pageRank scores were written back to the cluster
gds.set_bookmarks(gds.last_bookmarks())
result = gds.run_cypher("MATCH (p:Person) RETURN p.name, p.pagerank")
G.drop()
For more details about bookmarks, see the Neo4j Python driver.