Neo4j - 不是链的一部分!关系遍历游标

Neo4j - NOT PART OF CHAIN! RelationshipTraversalCursor

我的数据导入突然出现以下错误:

neo4j.exceptions.DatabaseError: NOT PART OF CHAIN! RelationshipTraversalCursor[id=328769435, open state with: denseNode=false, next=328769435, mode=regular, underlying record=Relationship[328769435,used=false,source=0,target=0,type=0,sPrev=0,sNext=0,tPrev=0,tNext=0,prop=0,secondaryUnitId=-1,!sFirst,!tFirst] ]

这个错误到底是什么意思?我该如何进一步调试它?

我还没有找到这方面的任何文档。

debug.log 的最后一部分(Whosebug 不允许):

2018-07-19 14:29:57.551+0000 ERROR [o.n.b.v.r.ErrorReporter] Client 

...
org.neo4j.cypher.internal.runtime.slotted.pipes.ApplySlottedPipe$$anonfun$internalCreateResults.apply(ApplySlottedPipe.scala:34)
        at scala.collection.Iterator$$anon.nextCur(Iterator.scala:435)
        at scala.collection.Iterator$$anon.hasNext(Iterator.scala:441)
        at scala.collection.Iterator$$anon.hasNext(Iterator.scala:409)
        at scala.collection.Iterator$class.foreach(Iterator.scala:891)
        at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
        at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:59)
        at scala.collection.immutable.VectorBuilder.$plus$plus$eq(Vector.scala:732)
        at scala.collection.immutable.VectorBuilder.$plus$plus$eq(Vector.scala:708)
        at scala.collection.TraversableOnce$class.to(TraversableOnce.scala:310)
        at scala.collection.AbstractIterator.to(Iterator.scala:1334)
        at scala.collection.TraversableOnce$class.toIndexedSeq(TraversableOnce.scala:300)
        at scala.collection.AbstractIterator.toIndexedSeq(Iterator.scala:1334)
        at org.neo4j.cypher.internal.runtime.slotted.pipes.EagerSlottedPipe.internalCreateResults(EagerSlottedPipe.scala:40)
        at org.neo4j.cypher.internal.runtime.interpreted.pipes.PipeWithSource.createResults(Pipe.scala:76)
        at org.neo4j.cypher.internal.runtime.interpreted.pipes.PipeWithSource.createResults(Pipe.scala:72)
        at org.neo4j.cypher.internal.runtime.interpreted.pipes.PipeWithSource.createResults(Pipe.scala:72)
        at org.neo4j.cypher.internal.runtime.interpreted.pipes.PipeWithSource.createResults(Pipe.scala:72)
        at org.neo4j.cypher.internal.runtime.interpreted.pipes.PipeWithSource.createResults(Pipe.scala:72)
        at org.neo4j.cypher.internal.runtime.interpreted.pipes.PipeWithSource.createResults(Pipe.scala:72)
        at org.neo4j.cypher.internal.runtime.interpreted.pipes.PipeWithSource.createResults(Pipe.scala:72)
        at org.neo4j.cypher.internal.runtime.interpreted.pipes.PipeWithSource.createResults(Pipe.scala:72)
        at org.neo4j.cypher.internal.runtime.interpreted.pipes.PipeWithSource.createResults(Pipe.scala:72)
        at org.neo4j.cypher.internal.runtime.interpreted.pipes.PipeWithSource.createResults(Pipe.scala:72)
        at org.neo4j.cypher.internal.runtime.interpreted.pipes.PipeWithSource.createResults(Pipe.scala:72)
        at org.neo4j.cypher.internal.runtime.interpreted.pipes.PipeWithSource.createResults(Pipe.scala:72)
        at org.neo4j.cypher.internal.compatibility.v3_4.runtime.executionplan.BaseExecutionResultBuilderFactory$BaseExecutionWorkflowBuilder.createResults(DefaultExecutionResultBuilderFactory.scala:105)
        at org.neo4j.cypher.internal.compatibility.v3_4.runtime.executionplan.BaseExecutionResultBuilderFactory$BaseExecutionWorkflowBuilder.build(DefaultExecutionResultBuilderFactory.scala:77)
        at org.neo4j.cypher.internal.compatibility.v3_4.runtime.BuildInterpretedExecutionPlan$$anonfun$getExecutionPlanFunction.apply(BuildInterpretedExecutionPlan.scala:97)
        at org.neo4j.cypher.internal.compatibility.v3_4.runtime.BuildInterpretedExecutionPlan$$anonfun$getExecutionPlanFunction.apply(BuildInterpretedExecutionPlan.scala:80)
        at org.neo4j.cypher.internal.BuildSlottedExecutionPlan$SlottedExecutionPlan.run(BuildSlottedExecutionPlan.scala:152)
        at org.neo4j.cypher.internal.compatibility.LatestRuntimeVariablePlannerCompatibility$ExecutionPlanWrapper$$anonfun$run.apply(LatestRuntimeVariablePlannerCompatibility.scala:128)
        at org.neo4j.cypher.internal.compatibility.LatestRuntimeVariablePlannerCompatibility$ExecutionPlanWrapper$$anonfun$run.apply(LatestRuntimeVariablePlannerCompatibility.scala:124)
        at org.neo4j.cypher.exceptionHandler$runSafely$.apply(exceptionHandler.scala:89)
        at org.neo4j.cypher.internal.compatibility.LatestRuntimeVariablePlannerCompatibility$ExecutionPlanWrapper.run(LatestRuntimeVariablePlannerCompatibility.scala:124)
        at org.neo4j.cypher.internal.PreparedPlanExecution.execute(PreparedPlanExecution.scala:29)
        at org.neo4j.cypher.internal.ExecutionEngine.execute(ExecutionEngine.scala:119)
        at org.neo4j.cypher.internal.javacompat.ExecutionEngine.executeQuery(ExecutionEngine.java:61)
        at org.neo4j.bolt.v1.runtime.TransactionStateMachineSPI.start(TransactionStateMachineSPI.java:144)
        at org.neo4j.bolt.v1.runtime.TransactionStateMachine$State.startExecution(TransactionStateMachine.java:446)
        at org.neo4j.bolt.v1.runtime.TransactionStateMachine$State.run(TransactionStateMachine.java:343)
        at org.neo4j.bolt.v1.runtime.TransactionStateMachine.run(TransactionStateMachine.java:81)
        at org.neo4j.bolt.v1.runtime.BoltStateMachine$State.run(BoltStateMachine.java:456)
        at org.neo4j.bolt.v1.runtime.BoltStateMachine.run(BoltStateMachine.java:222)
        at org.neo4j.bolt.v1.messaging.BoltMessageRouter.lambda$onRun(BoltMessageRouter.java:93)
        at org.neo4j.bolt.runtime.MetricsReportingBoltConnection.lambda$enqueue[=11=](MetricsReportingBoltConnection.java:69)
        at org.neo4j.bolt.runtime.DefaultBoltConnection.processNextBatch(DefaultBoltConnection.java:193)
        at org.neo4j.bolt.runtime.MetricsReportingBoltConnection.processNextBatch(MetricsReportingBoltConnection.java:87)
        at org.neo4j.bolt.runtime.DefaultBoltConnection.processNextBatch(DefaultBoltConnection.java:143)
        at org.neo4j.bolt.runtime.ExecutorBoltScheduler.executeBatch(ExecutorBoltScheduler.java:163)
        at org.neo4j.bolt.runtime.ExecutorBoltScheduler.lambda$null[=11=](ExecutorBoltScheduler.java:145)
        at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:748)

对于我之前成功导入的文件,现在也会发生这种情况。

这一定与我的密码查询有关,因为当我将它减少到绝对最小值时它会起作用,但它有助于理解错误。

编辑 - 尝试调试

现在我被这个错误困住了。

通过我的脚本中的这个超级最小的 Cypher 查询,一切正常:

WITH $custom_dict as pubmed_list
UNWIND pubmed_list as article
    MERGE (p:Publication {pmid: COALESCE (article.pmid, 'NO-PMID')})
    ON CREATE SET p.title = article.article_title, p.journal_title = article.journal_title, p.db = 'pubmed'

但是,当我添加这个时:

    MERGE (dc:Date { year: COALESCE (article.year_revised, 'NO-YEAR-COMPLETION') })
    MERGE (p)-[:COMPLETED]->(dc)

    MERGE (dr:Date { year: COALESCE (article.year_completed, 'NO-YEAR-REVISION')})
    MERGE (p)-[:REVISED]->(dr)

我传递给 UNWINDing 的字典看起来也很好:

编辑 2 - 一致性检查

运行 一致性检查后:

$ "$NEO4J_HOME"/bin/neo4j-admin check-consistency --database=graph.db

它是这样开始的:

2018-07-20 08:41:15.337+0000 INFO [o.n.k.i.s.f.RecordFormatSelector] Selected RecordFormat:StandardV3_4[v0.A.9] record format from store /Users/rich/Library/Application Support/Neo4j Desktop/Application/neo4jDatabases/database-4ca696a4-add3-4f69-a97b-1b89ce8e854b/installation-3.4.0/data/databases/graph.db
2018-07-20 08:41:15.340+0000 INFO [o.n.k.i.s.f.RecordFormatSelector] Format not configured. Selected format from the store: RecordFormat:StandardV3_4[v0.A.9]

然后我得到几千个这样的:

2018-07-20 08:42:49.837+0000 ERROR [o.n.c.ConsistencyCheckService] The referenced relationship group record is not in use.
    Node[145800979,used=true,group=8661147,prop=275750014,labels=Inline(0x1000000000:[0]),light,secondaryUnitId=-1]
    Inconsistent with: RelationshipGroup[8661147,type=0,out=0,in=0,loop=0,prev=-1,next=0,used=false,owner=0,secondaryUnitId=-1]

然后继续:

...  10%
....................  20%
................2018-07-20 08:49:01.023+0000 ERROR [o.n.c.ConsistencyCheckService] This record should be the first in the source chain, but the source node does not reference this record.

现在它永远运行并出现之前描述的错误,如下所示:

Inconsistent with: Node[6577082,used=true,rel=329016678,prop=11682171,labels=Inline(0x1000000000:[0]),light,secondaryUnitId=-1]
2018-07-20 09:07:05.171+0000 ERROR [o.n.c.ConsistencyCheckService] This record should be the first in the target chain, but the target node does not reference this record.
    Relationship[314188818,used=true,source=140353187,target=78456590,type=4,sPrev=314188819,sNext=314188812,tCount=32,tNext=301551374,prop=-1,secondaryUnitId=-1,!sFirst, tFirst]

还有这个:

2018-07-20 09:08:14.715+0000 ERROR [o.n.c.ConsistencyCheckService] The next record in the target chain does not have this record as its previous record.
    Relationship[192261,used=true,source=28336,target=5180,type=4,sPrev=192264,sNext=192260,tPrev=191008,tNext=184760,prop=-1,secondaryUnitId=-1,!sFirst,!tFirst]
    Inconsistent with: Relationship[184760,used=true,source=24761,target=5180,type=4,sPrev=184750,sNext=184761,tPrev=184738,tNext=192261,prop=-1,secondaryUnitId=-1,!sFirst,!tFirst]

这对我的数据库意味着什么,我该如何修复它?

看起来数据库已损坏。这通常是由于 运行 磁盘不足 space 而 Neo4j 是 运行 (现在应该在最新版本中得到缓解),或者是由于复制数据库(文件复制,而不是使用 neo4j-admin backup) 的热备份功能或在 Neo4j 为 运行.

时修改文件

您应该备份数据库(禁用一致性检查,您将不再需要它)并使用 store copy utils 从备份重建数据库,然后恢复实例(或集群) ) 来自重建的数据存储。

重建存储会跳过所有损坏的记录,因此您可能希望在操作完成后检查数据的完整性。

我可以在我的一个测试中重现这个错误,只需在单个事务上从 2 个线程调用遍历即可。因此,根据有关事务的 neo4j 文档,不鼓励使用这种访​​问模式。

https://neo4j.com/docs/java-reference/4.1/javadocs/org/neo4j/graphdb/Transaction.html

Note that transactions should be used by a single thread only. It is generally not safe to use a transaction from multiple threads. Doing so will lead to undefined behavior.

或者,如果您的遍历陷入无限循环或可能正在等待锁定(检查您的线程转储),那么这也可能表明 运行 遍历具有多个线程的单个事务或者在另一个事务中使用来自其他未提交事务的Nodes/Relationships。