Neo4j 频繁导入数据导致DeadLock的问题

2018-01-04:补充说明

如下的解决方案还是会偶尔蹦出几个DeadLock的问题,在运维查看了neo4j的内存占用时发现一个问题,neo4j十分吃swap,导致执行效率十分低下,再次仔细查阅官网发现缺少了一个很重要的内存配置参数,

dbms.memory.pagecache.size=1g

The amount of memory to use for mapping the store files, in bytes (or
kilobytes with the 'k' suffix, megabytes with 'm' and gigabytes with 'g').
If Neo4j is running on a dedicated server, then it is generally recommended
to leave about 2-4 gigabytes for the operating system, give the JVM enough
heap to hold all your transaction state and query context, and then leave the
rest for the page cache.
The default page cache memory assumes the machine is dedicated to running
Neo4j, and is heuristically set to 50% of RAM minus the max Java heap size.


 {"results":[],"errors":[{"code":"Neo.TransientError.Transaction.DeadlockDetected","message":"LockClient[6092] can't wait on resource RWLock[NODE(133321815), hash=1215661247] since => LockClient[6092] <-[:HELD_BY]- RWLock[NODE(38473669), hash=1470152465] <-[:WAITING_FOR]- LockClient[6091] <-[:HELD_BY]- RWLock[NODE(133321815), hash=1215661247]","stackTrace":"org.neo4j.kernel.DeadlockDetectedException: LockClient[6092] can't wait on resource RWLock[NODE(133321815), hash=1215661247] since => LockClient[6092] <-[:HELD_BY]- RWLock[NODE(38473669), hash=1470152465] <-[:WAITING_FOR]- LockClient[6091] <-[:HELD_BY]- RWLock[NODE(133321815), hash=1215661247]\n\tat org.neo4j.kernel.impl.locking.community.RagManager.checkWaitOnRecursive(RagManager.java:198)\n\tat org.neo4j.kernel.impl.locking.community.RagManager.checkWaitOnRecursive(RagManager.java:225)\n\tat org.neo4j.kernel.impl.locking.community.RagManager.checkWaitOn(RagManager.java:165)\n\tat org.neo4j.kernel.impl.locking.community.RWLock.acquireWriteLock(RWLock.java:396)\n\tat org.neo4j.kernel.impl.locking.community.LockManagerImpl.getWriteLock(LockManagerImpl.java:67)\n\tat org.neo4j.kernel.impl.locking.community.CommunityLockClient.acquireExclusive(CommunityLockClient.java:147)\n\tat org.neo4j.kernel.impl.api.LockingStatementOperations.exclusiveOptimisticLock(LockingStatementOperations.java:539)\n\tat org.neo4j.kernel.impl.api.LockingStatementOperations.acquireExclusiveNodeLock(LockingStatementOperations.java:500)\n\tat org.neo4j.kernel.impl.api.LockingStatementOperations.lockRelationshipNodes(LockingStatementOperations.java:307)\n\tat org.neo4j.kernel.impl.api.LockingStatementOperations.relationshipCreate(LockingStatementOperations.java:286)\n\tat org.neo4j.kernel.impl.api.OperationsFacade.relationshipCreate(OperationsFacade.java:854)\n\tat org.neo4j.cypher.internal.spi.v3_3.TransactionBoundQueryContext.createRelationship(TransactionBoundQueryContext.scala:109)\n\tat org.neo4j.cypher.internal.spi.v3_3.TransactionBoundQueryContext.createRelationship(TransactionBoundQueryContext.scala:70)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.ExceptionTranslatingQueryContext$$anonfun$createRelationship$2.apply(ExceptionTranslatingQueryContext.scala:200)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.ExceptionTranslatingQueryContext$$anonfun$createRelationship$2.apply(ExceptionTranslatingQueryContext.scala:200)\n\tat org.neo4j.cypher.internal.spi.v3_3.ExceptionTranslationSupport$class.translateException(ExceptionTranslationSupport.scala:32)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.ExceptionTranslatingQueryContext.translateException(ExceptionTranslatingQueryContext.scala:39)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.ExceptionTranslatingQueryContext.createRelationship(ExceptionTranslatingQueryContext.scala:200)\n\tat org.neo4j.cypher.internal.spi.v3_3.UpdateCountingQueryContext.createRelationship(UpdateCountingQueryContext.scala:92)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.runtime.pipes.BaseRelationshipPipe.org$neo4j$cypher$internal$compatibility$v3_3$runtime$pipes$BaseRelationshipPipe$$createRelationship(CreateRelationshipPipe.scala:47)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.runtime.pipes.BaseRelationshipPipe$$anonfun$internalCreateResults$1.apply(CreateRelationshipPipe.scala:41)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.runtime.pipes.BaseRelationshipPipe$$anonfun$internalCreateResults$1.apply(CreateRelationshipPipe.scala:41)\n\tat scala.collection.Iterator$$anon$11.next(Iterator.scala:410)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.runtime.pipes.EmptyResultPipe.internalCreateResults(EmptyResultPipe.scala:29)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.runtime.pipes.PipeWithSource.createResults(Pipe.scala:62)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.runtime.pipes.PipeWithSource.createResults(Pipe.scala:59)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.runtime.executionplan.DefaultExecutionResultBuilderFactory$ExecutionWorkflowBuilder.createResults(DefaultExecutionResultBuilderFactory.scala:102)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.runtime.executionplan.DefaultExecutionResultBuilderFactory$ExecutionWorkflowBuilder.build(DefaultExecutionResultBuilderFactory.scala:74)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.runtime.BuildInterpretedExecutionPlan$$anonfun$getExecutionPlanFunction$1.apply(BuildInterpretedExecutionPlan.scala:111)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.runtime.BuildInterpretedExecutionPlan$$anonfun$getExecutionPlanFunction$1.apply(BuildInterpretedExecutionPlan.scala:94)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.runtime.BuildInterpretedExecutionPlan$$anon$1.run(BuildInterpretedExecutionPlan.scala:62)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.Compatibility$ExecutionPlanWrapper$$anonfun$run$1.apply(Compatibility.scala:182)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.Compatibility$ExecutionPlanWrapper$$anonfun$run$1.apply(Compatibility.scala:178)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.exceptionHandler$runSafely$.apply(exceptionHandler.scala:90)\n\tat org.neo4j.cypher.internal.compatibility.v3_3.Compatibility$ExecutionPlanWrapper.run(Compatibility.scala:178)\n\tat org.neo4j.cypher.internal.PreparedPlanExecution.execute(PreparedPlanExecution.scala:29)\n\tat org.neo4j.cypher.internal.ExecutionEngine.execute(ExecutionEngine.scala:116)\n\tat org.neo4j.cypher.internal.ExecutionEngine.execute(ExecutionEngine.scala:111)\n\tat org.neo4j.cypher.internal.javacompat.ExecutionEngine.executeQuery(ExecutionEngine.java:76)\n\tat org.neo4j.server.rest.transactional.TransactionHandle.safelyExecute(TransactionHandle.java:371)\n\tat org.neo4j.server.rest.transactional.TransactionHandle.executeStatements(TransactionHandle.java:323)\n\tat org.neo4j.server.rest.transactional.TransactionHandle.commit(TransactionHandle.java:157)\n\tat org.neo4j.server.rest.web.TransactionalService.lambda$executeStatementsAndCommit$1(TransactionalService.java:218)\n\tat com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:71)\n\tat com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:57)\n\tat com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:302)\n\tat com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1510)\n\tat com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)\n\tat com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)\n\tat com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)\n\tat com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)\n\tat com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:790)\n\tat org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)\n\tat org.neo4j.server.rest.dbms.AuthorizationDisabledFilter.doFilter(AuthorizationDisabledFilter.java:49)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)\n\tat org.neo4j.server.rest.web.CollectUserAgentFilter.doFilter(CollectUserAgentFilter.java:69)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)\n\tat org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\n\tat org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)\n\tat org.eclipse.jetty.server.Server.handle(Server.java:499)\n\tat org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)\n\tat org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:258)\n\tat org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)\n\tat java.lang.Thread.run(Thread.java:748)\n"}]}

并发导入数据到neo4j时,时常给出这个LockDead的错误,官方没有明确的给出解决方案,但是有相关介绍【官方说deadlock】 ,上线前,想使用错误重试方案来补救并减少这中LockDead的出现几率,没有时间测试和实施(跟上头说,上头也是含糊其辞……不爽),只好强制将规则矩阵由并发改为串行,大量的体力活(因为商户数量众多,大概十家,这样的改动导致上线步骤繁琐,各种体力活)。
今天抽出空,大体跑了一下使用错误恢复补救方案,效果还可以,编码思路很简单,前期测试阶段给出三次重新错误重试次数,间隔步长为7、8、11秒,但是仍然会有极小的几率出现,是不是要改成无限重试的?还得继续观察。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,456评论 5 477
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,370评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,337评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,583评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,596评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,572评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,936评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,595评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,850评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,601评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,685评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,371评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,951评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,934评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,167评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 43,636评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,411评论 2 342

推荐阅读更多精彩内容