是neo4j-jdbc驱动3.x线程安全

时间:2017-05-15 18:36:37

标签: jdbc neo4j google-cloud-platform google-cloud-dataflow

我正在运行一个设置,我使用安装neo4j-jdbc驱动程序的jdbc API连接到VM中的neo4j数据库,并且在执行一些多线程工作时遇到了死锁问题。我想知道是否有人知道neo4j-jdbc驱动程序3.x是否是线程安全的?

错误记录

Exception: java.sql.BatchUpdateException: org.neo4j.driver.v1.exceptions.TransientException: LockClient[4211] can't wait on resource RWLock[NODE(2410), hash=1674994875] since => LockClient[4211] <-[:HELD_BY]- RWLock[NODE(2403), hash=1544505462] <-[:WAITING_FOR]- LockClient[4205] <-[:HELD_BY]- RWLock[NODE(2410), hash=1674994875]
org.neo4j.jdbc.bolt.BoltPreparedStatement.executeBatch(BoltPreparedStatement.java:178)
org.apache.commons.dbcp2.DelegatingStatement.executeBatch(DelegatingStatement.java:345)
org.apache.commons.dbcp2.DelegatingStatement.executeBatch(DelegatingStatement.java:345)
org.apache.beam.sdk.io.jdbc.JdbcIO$Write$WriteFn.finishBundle(JdbcIO.java:480)
Caused By: org.neo4j.driver.v1.exceptions.TransientException: LockClient[4211] can't wait on resource RWLock[NODE(2410), hash=1674994875] since => LockClient[4211] <-[:HELD_BY]- RWLock[NODE(2403), hash=1544505462] <-[:WAITING_FOR]- LockClient[4205] <-[:HELD_BY]- RWLock[NODE(2410), hash=1674994875]
org.neo4j.driver.internal.connector.socket.SocketResponseHandler.handleFailureMessage(SocketResponseHandler.java:71)
org.neo4j.driver.internal.messaging.PackStreamMessageFormatV1$Reader.unpackFailureMessage(PackStreamMessageFormatV1.java:464)
org.neo4j.driver.internal.messaging.PackStreamMessageFormatV1$Reader.read(PackStreamMessageFormatV1.java:425)
org.neo4j.driver.internal.connector.socket.SocketClient.receiveOne(SocketClient.java:130)
org.neo4j.driver.internal.connector.socket.SocketConnection.receiveOne(SocketConnection.java:143)
Stack trace truncated. Please see Cloud Logging for the entire trace.

1 个答案:

答案 0 :(得分:1)

死锁是&#34;正常&#34;的结果。存在并发请求时的neo4j行为。你应该知道neo4j的default locking behaviordocumentation on deadlocks

这可能是最有用的段落:

  

经历频繁的死锁是并发写入的指示   请求以无法执行的方式发生   他们同时实现了预期的隔离和   一致性。解决方案是确保发生并发更新   合理的方式。例如,给定两个特定节点(A和B),   以随机顺序添加或删除这两个节点的关系   当有两个或每个事务将导致死锁   同时执行此操作的更多事务。一个解决方案是制作   确保更新始终以相同的顺序发生(首先是A然后是B)。   另一种解决方案是确保每个线程/事务不会   与其他节点或关系的任何冲突写入   并发交易。这可以例如通过让a来实现   单线程执行特定类型的所有更新。