删除然后使用事务Neo4j REST API并行创建节点时的Neo.ClientError.Statement.EntityNotFound

时间:2014-12-09 13:49:05

标签: neo4j cypher

当我使用事务性REST API和自动提交模式并行删除然后在Neo4j数据库(v2.1.6,Ubuntu)中创建节点时,我会收到类似这样的错误

{"results":[],"errors":[{"code":"Neo.ClientError.Statement.EntityNotFound","message":"Node with id 35275"}]}

对于每个节点,我运行查询:

curl -X POST -d @data http://localhost:7474/db/data/transaction/commit -H "Content-Type:application/json; charset=UTF-8" -H Accept:application/json  >out$i  

以下陈述

{
    "statements": [
    {
        "statement": "MATCH (k:Keyword {kwId: \"1\"}) DELETE k",
        "parameters": {}
    },
    {
        "statement": "CREATE (k:Keyword {props}) RETURN k",
        "parameters": {
            "props": {
                "kwId": "1"
            }
        }
    }
    ]
}

每个查询的kwId值都不同。

当我按顺序执行查询时,一切都很好

当我并行运行查询时,我得到一些查询的错误响应(20个查询的~5个错误响应)

{"results":[],"errors":[{"code":"Neo.ClientError.Statement.EntityNotFound","message":"Node with id 35275"}]}

这是一个Neo4j问题还是我错了?

重现问题的脚本:

#!/bin/bash
NEO4J_URL=http://localhost:7474
TOTAL_QUERIES=20

# Create temp JSON files tmp1.json, tmp2.json, ....
for (( i=1; i<$TOTAL_QUERIES; i++ ))
do
  JSON=tmp$i.json
  cat > $JSON << END_OF_JSON
{
    "statements": [
    {
            "statement": "MATCH (k:Keyword {kwId: \"$i\"}) DELETE k",
            "parameters": {}
    },
        {
            "statement": "CREATE (k:Keyword {props}) RETURN k",
            "parameters": {
                "props": {
                    "kwId": "$i"
                }
            }
        }
    ]
}
END_OF_JSON
done

for (( i=1; i<$TOTAL_QUERIES; i++ ))
do
  JSON=tmp$i.json
  if [ "$1" = "sync" ]; then
    curl --silent -X POST -d @$JSON $NEO4J_URL/db/data/transaction/commit -H "Content-Type:application/json; charset=UTF-8" -H Accept:application/json  >out$i  
  else
    curl --silent -X POST -d @$JSON $NEO4J_URL/db/data/transaction/commit -H "Content-Type:application/json; charset=UTF-8" -H Accept:application/json  >out$i &
  fi
done

wait
awk 'FNR==1{print ""}1' out* > result
grep "\"errors\":\[.*\]" result
rm out* tmp*.json result

更新:使用旧版REST API时,错误消息更好

  "message" : "Node with id 35970",
  "exception" : "EntityNotFoundException",
  "fullname" : "org.neo4j.cypher.EntityNotFoundException",
  "stacktrace" : [ "org.neo4j.cypher.internal.spi.v2_1.TransactionBoundQueryContext$NodeOperations.getById(TransactionBoundQueryContext.scala:160)", "org.neo4j.cypher.internal.spi.v2_1.TransactionBoundQueryContext$$anonfun$getNodesByLabel$1.apply(TransactionBoundQueryContext.scala:135)", "org.neo4j.cypher.internal.spi.v2_1.TransactionBoundQueryContext$$anonfun$getNodesByLabel$1.apply(TransactionBoundQueryContext.scala:135)", "org.neo4j.cypher.internal.helpers.JavaConversionSupport$$anon$2.next(JavaConversionSupport.scala:33)", "scala.collection.Iterator$$anon$11.next(Iterator.scala:328)", "scala.collection.Iterator$$anon$13.next(Iterator.scala:372)", "scala.collection.Iterator$$anon$14.hasNext(Iterator.scala:389)", "scala.collection.Iterator$class.foreach(Iterator.scala:727)", "scala.collection.AbstractIterator.foreach(Iterator.scala:1157)", "scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:48)", "scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:176)", "scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:45)", "scala.collection.TraversableOnce$class.to(TraversableOnce.scala:273)", "scala.collection.AbstractIterator.to(Iterator.scala:1157)", "scala.collection.TraversableOnce$class.toList(TraversableOnce.scala:257)", "scala.collection.AbstractIterator.toList(Iterator.scala:1157)", "org.neo4j.cypher.internal.compiler.v2_1.pipes.EagerPipe.internalCreateResults(EagerPipe.scala:32)", "org.neo4j.cypher.internal.compiler.v2_1.pipes.PipeWithSource.createResults(Pipe.scala:105)", "org.neo4j.cypher.internal.compiler.v2_1.pipes.PipeWithSource.createResults(Pipe.scala:102)", "org.neo4j.cypher.internal.compiler.v2_1.pipes.PipeWithSource.createResults(Pipe.scala:102)", "org.neo4j.cypher.internal.compiler.v2_1.pipes.PipeWithSource.createResults(Pipe.scala:102)", "org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionPlanBuilder$$anonfun$getExecutionPlanFunction$1$$anonfun$apply$2.apply(ExecutionPlanBuilder.scala:120)", "org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionPlanBuilder$$anonfun$getExecutionPlanFunction$1$$anonfun$apply$2.apply(ExecutionPlanBuilder.scala:119)", "org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionWorkflowBuilder.runWithQueryState(ExecutionPlanBuilder.scala:168)", "org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionPlanBuilder$$anonfun$getExecutionPlanFunction$1.apply(ExecutionPlanBuilder.scala:118)", "org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionPlanBuilder$$anonfun$getExecutionPlanFunction$1.apply(ExecutionPlanBuilder.scala:103)", "org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionPlanBuilder$$anon$1.execute(ExecutionPlanBuilder.scala:68)", "org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionPlanBuilder$$anon$1.execute(ExecutionPlanBuilder.scala:67)", "org.neo4j.cypher.internal.ExecutionPlanWrapperForV2_1.execute(CypherCompiler.scala:159)", "org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:76)", "org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:71)", "org.neo4j.cypher.javacompat.ExecutionEngine.execute(ExecutionEngine.java:84)", "org.neo4j.server.rest.web.CypherService.cypher(CypherService.java:114)", "java.lang.reflect.Method.invoke(Method.java:606)", "org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)", "java.lang.Thread.run(Thread.java:745)" ],

3 个答案:

答案 0 :(得分:0)

不确定这是否有帮助,但我注意到了一个随机的事情:你正在使用CREATE的参数而不是DELETE。我不知道/为什么这可能导致竞争条件,但值得检查

答案 1 :(得分:0)

做这两个查询似乎有点奇怪。也许有一些机密的东西你被剥夺了,但我认为你可以这样做:

MATCH (k:Keyword) WHERE k.kwId IN ({kw_ids}) DELETE k WITH k.kwId AS kwId CREATE (:Keyword:  {kwId: kwId})

答案 2 :(得分:0)

在属性kwId上创建新索引似乎可以解决我案例中的错误

CREATE INDEX ON :Keyword(kwId)