协调并行事务
书签是一种标记,用于表示数据库的某个状态。当需要在集群中协调后续事务时,书签非常有用,例如在写入数据后立刻读取数据的情况。
使用 GDS 客户端时,任何在调用 gds.set_bookmarks() 之后的查询都不会执行,直到书签事务在整个集群中传播完毕。
使用书签的 GDS 示例
# Use the `bookmarks` parameter to set any existing bookmarks, for example
# after running a query through the Neo4j driver. The default value is `None`.
gds = GraphDataScience(NEO4J_URI, auth=(NEO4J_USER, NEO4J_PASSWORD), bookmarks=None)
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("myGraph", "Person", "KNOWS")
gds.pageRank.write(G, writeProperty="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()
有关书签的更多细节,请参阅 Neo4j Python 驱动程序。