今天用Neo4j导入数据的时候报错了
Import error: Maximum id limit for RELATIONSHIP_TYPE_TOKEN has been reached. Generated id 92840 is out of permitted range [0, 65535].
Caused by:Maximum id limit for RELATIONSHIP_TYPE_TOKEN has been reached. Generated id 92840 is out of permitted range [0, 65535].
org.neo4j.kernel.impl.store.id.validation.IdCapacityExceededException: Maximum id limit for RELATIONSHIP_TYPE_TOKEN has been reached. Generated id 92840 is out of permitted range [0, 65535].
at org.neo4j.kernel.impl.store.id.validation.IdValidator.assertIdWithinCapacity(IdValidator.java:90)
at org.neo4j.kernel.impl.store.id.validation.IdValidator.assertValidId(IdValidator.java:68)
at org.neo4j.kernel.impl.store.CommonAbstractStore.updateRecord(CommonAbstractStore.java:1114)
at org.neo4j.kernel.impl.store.TokenStore.updateRecord(TokenStore.java:122)
at org.neo4j.kernel.impl.store.TokenStore.updateRecord(TokenStore.java:46)
at org.neo4j.unsafe.batchinsert.internal.DirectRecordAccess$DirectRecordProxy.store(DirectRecordAccess.java:205) at org.neo4j.unsafe.batchinsert.internal.DirectRecordAccess.commit(DirectRecordAccess.java:239)
at org.neo4j.unsafe.batchinsert.internal.DirectRecordAccess.close(DirectRecordAccess.java:225)
at org.neo4j.unsafe.impl.batchimport.store.BatchingTokenRepository.flush(BatchingTokenRepository.java:193)
at org.neo4j.unsafe.impl.batchimport.store.BatchingNeoStores.flushAndForce(BatchingNeoStores.java:472)
at com.neo4j.unsafe.impl.batchimport.RestartableParallelBatchImporter.writeState(RestartableParallelBatchImporter.java:241)
at com.neo4j.unsafe.impl.batchimport.RestartableParallelBatchImporter.runRemainingStates(RestartableParallelBatchImporter.java:235)
at com.neo4j.unsafe.impl.batchimport.RestartableParallelBatchImporter.doImport(RestartableParallelBatchImporter.java:115)
at org.neo4j.tooling.ImportTool.doImport(ImportTool.java:581)
at org.neo4j.tooling.ImportTool.main(ImportTool.java:482)
at org.neo4j.tooling.ImportTool.main(ImportTool.java:379)
Suppressed: org.neo4j.kernel.impl.store.id.validation.IdCapacityExceededException: Maximum id limit for RELATIONSHIP_TYPE_TOKEN has been reached. Generated id 92840 is out of permitted range [0, 65535].
at org.neo4j.kernel.impl.store.id.validation.IdValidator.assertIdWithinCapacity(IdValidator.java:90)
at org.neo4j.kernel.impl.store.id.validation.IdValidator.assertValidId(IdValidator.java:68)
at org.neo4j.kernel.impl.store.CommonAbstractStore.updateRecord(CommonAbstractStore.java:1114)
at org.neo4j.kernel.impl.store.TokenStore.updateRecord(TokenStore.java:122)
at org.neo4j.kernel.impl.store.TokenStore.updateRecord(TokenStore.java:46)
at org.neo4j.unsafe.batchinsert.internal.DirectRecordAccess$DirectRecordProxy.store(DirectRecordAccess.java:205)
at org.neo4j.unsafe.batchinsert.internal.DirectRecordAccess.commit(DirectRecordAccess.java:239)
at org.neo4j.unsafe.batchinsert.internal.DirectRecordAccess.close(DirectRecordAccess.java:225)
at org.neo4j.unsafe.impl.batchimport.store.BatchingTokenRepository.flush(BatchingTokenRepository.java:193)
at org.neo4j.unsafe.impl.batchimport.store.BatchingNeoStores.flushAndForce(BatchingNeoStores.java:472)
at org.neo4j.unsafe.impl.batchimport.store.BatchingNeoStores.close(BatchingNeoStores.java:378)
at com.neo4j.unsafe.impl.batchimport.RestartableParallelBatchImporter.doImport(RestartableParallelBatchImporter.java:118)
... 3 more
WARNING Import failed. The store files in D:\Neo4jDesktop\neo4jDatabases\database-33f40f7d-7210-41ac-b6a9-8d17c0490379\installation-3.5.6\data\databases\graph.db are left as they are, although they are likely in an unusable state.
Starting a database on these store files will likely fail or observe inconsistent records so start at your own risk or delete the store manually
后来在网上找到这里。
大概翻译一下:
在运行创建新关系类型的语句时,例如:
MERGE (n1:Person {id:1})-[r:knows]->(n2:Person {id:2})
可能会遇到一个错误,错误日志记录:
2017-10-30 17:08:29.741+0000 ERROR [o.n.b.v.r.ErrorReporter] Client triggered an unexpected error [UnknownError]: Could not create token, reference 63c2e7ef-6f5b-4834-b2a8-fe74cac3a50a. Could not create token org.neo4j.graphdb.TransactionFailureException: Could not create token at org.neo4j.kernel.impl.core.DelegatingTokenHolder.getOrCreateId(DelegatingTokenHolder.java:85) at org.neo4j.kernel.impl.api.store.StorageLayer.relationshipTypeGetOrCreateForName(StorageLayer.java:376) at org.neo4j.kernel.impl.api.StateHandlingStatementOperations.relationshipTypeGetOrCreateForName(StateHandlingStatementOperations.java:1384) at org.neo4j.kernel.impl.api.DataIntegrityValidatingStatementOperations.relationshipTypeGetOrCreateForName(DataIntegrityValidatingStatementOperations.java:86) at org.neo4j.kernel.impl.api.OperationsFacade.relationshipTypeGetOrCreateForName(OperationsFacade.java:774) at org.neo4j.cypher.internal.spi.v3_3.TransactionBoundQueryContext.getOrCreateRelTypeId(TransactionBoundQueryContext.scala:114) at org.neo4j.cypher.internal.compatibility.v3_3.ExceptionTranslatingQueryContext$$anonfun$getOrCreateRelTypeId$1.apply$mcI$sp(ExceptionTranslatingQueryContext.scala:203) ... ..... ........ at org.neo4j.bolt.v1.runtime.concurrent.RunnableBoltWorker.run(RunnableBoltWorker.java:96) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) at org.neo4j.helpers.NamedThreadFactory$2.run(NamedThreadFactory.java:109) Caused by: org.neo4j.kernel.impl.store.id.validation.IdCapacityExceededException: Record id 65536 is out of range [0, 65535] at org.neo4j.kernel.impl.store.id.validation.IdValidator.assertIdWithinCapacity(IdValidator.java:88) at org.neo4j.kernel.impl.store.id.validation.IdValidator.assertValidId(IdValidator.java:67) at org.neo4j.kernel.impl.store.id.IdGeneratorImpl.nextId(IdGeneratorImpl.java:143) at org.neo4j.kernel.impl.core.DefaultRelationshipTypeCreator.createKey(DefaultRelationshipTypeCreator.java:40) at org.neo4j.kernel.impl.core.IsolatedTransactionTokenCreator.getOrCreate(IsolatedTransactionTokenCreator.java:59) at org.neo4j.kernel.impl.core.DelegatingTokenHolder.createToken(DelegatingTokenHolder.java:103) at org.neo4j.kernel.impl.core.DelegatingTokenHolder.getOrCreateId(DelegatingTokenHolder.java:76) ... 49 more
上方记录的关键部分是ID 65536 超出了区间 [0, 65535]
因为超出了graph.db的最大关系类型数,导致这个错误发生。当前最大关系类型数是65536。注意,这只是用来限制“关系类型”的数量,而不是节点之间的关系数或图中的总关系数。
遇到这个错误时,运行:
call db.relationshipTypes() yield relationshipType return count(relationshipType) as numRelTypes;
结果返回:
+-------------+ | numRelTypes | +-------------+ | 65536 | +-------------+
解决这个问题的方法,就是删除不再使用的关系类型。目前Cypher语句无法完成这个任务。可以运行copy-store.sh,这个命令将读取一个离线的graph.db并写入一个新的graph.db,但排除所有不再使用的关系类型/属性。
看完之后,发现错误原因,就是我的数据关系类型数超出了65536。
只能重新处理一下数据集,尽量减少关系类型。