对于我的数据导入,我突然收到以下错误:
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 的最后一部分(StackOverflow 不允许更多):
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$1.apply(ApplySlottedPipe.scala:34)
at scala.collection.Iterator$$anon$12.nextCur(Iterator.scala:435)
at scala.collection.Iterator$$anon$12.hasNext(Iterator.scala:441)
at scala.collection.Iterator$$anon$11.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$1.apply(BuildInterpretedExecutionPlan.scala:97)
at org.neo4j.cypher.internal.compatibility.v3_4.runtime.BuildInterpretedExecutionPlan$$anonfun$getExecutionPlanFunction$1.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$1.apply(LatestRuntimeVariablePlannerCompatibility.scala:128)
at org.neo4j.cypher.internal.compatibility.LatestRuntimeVariablePlannerCompatibility$ExecutionPlanWrapper$$anonfun$run$1.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$1.start(TransactionStateMachineSPI.java:144)
at org.neo4j.bolt.v1.runtime.TransactionStateMachine$State.startExecution(TransactionStateMachine.java:446)
at org.neo4j.bolt.v1.runtime.TransactionStateMachine$State$2.run(TransactionStateMachine.java:343)
at org.neo4j.bolt.v1.runtime.TransactionStateMachine.run(TransactionStateMachine.java:81)
at org.neo4j.bolt.v1.runtime.BoltStateMachine$State$2.run(BoltStateMachine.java:456)
at org.neo4j.bolt.v1.runtime.BoltStateMachine.run(BoltStateMachine.java:222)
at org.neo4j.bolt.v1.messaging.BoltMessageRouter.lambda$onRun$3(BoltMessageRouter.java:93)
at org.neo4j.bolt.runtime.MetricsReportingBoltConnection.lambda$enqueue$0(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$0(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)
运行一致性检查后:
$ "$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]
这对我的数据库意味着什么?我该如何修复它?
数据库似乎已损坏。这种情况通常是由于 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.
或者,如果您的遍历陷入无限循环或可能等待锁(检查线程转储),那么这也可能表明在具有多个线程的单个事务上运行遍历或使用来自其他未提交的节点/关系交易在另一笔交易中。
我在从 4.4.37 升级到 5 时遇到了类似的问题。似乎所有关系都是 BTREE,需要在点、范围或文本中创建。 使用 apoc 使用以下脚本
// Step 1: Retrieve all BTREE indexes
CALL db.indexes() YIELD name, labelsOrTypes, properties
WHERE type = "BTREE"
WITH name, labelsOrTypes, properties
// Step 2: Iterate over the indexes and determine property type
UNWIND labelsOrTypes AS label
UNWIND properties AS property
CALL apoc.meta.type("MATCH (n:" + label + ") RETURN n." + property) YIELD value AS propertyType
// Step 3: Drop the existing BTREE index
CALL apoc.cypher.run("
DROP INDEX " + name + ";
", {}) YIELD value
// Step 4: Recreate the index based on the property type
CALL apoc.cypher.run("
CALL {
WITH '" + propertyType + "' AS type, '" + label + "' AS label, '" + property + "' AS property
CALL apoc.do.case(
[
type STARTS WITH 'STRING', 'CREATE TEXT INDEX FOR (n:' + label + ') ON (n.' + property + ')',
type STARTS WITH 'INT', 'CREATE RANGE INDEX FOR (n:' + label + ') ON (n.' + property + ')',
type STARTS WITH 'FLOAT', 'CREATE RANGE INDEX FOR (n:' + label + ') ON (n.' + property + ')',
type STARTS WITH 'POINT', 'CREATE POINT INDEX FOR (n:' + label + ') ON (n.' + property + ')'
],
'RETURN null'
) YIELD value
RETURN value
}
", {}) YIELD value; ```