写批处理py2neo.neo4j.BatchOperationFailedException时出现py2neo错误

时间:2013-12-30 15:56:33

标签: neo4j py2neo

我正在运行下面的代码,以便更新neo4j数据库中的项目。如果项目存在(搜索不是批处理),我删除它的所有关系并更新它的属性。否则,我用新属性创建节点。 最后,我创建了节点所需的所有关系。

    #search if the 'item' already exist in DB
    update=0
    found_items = self.Index.get("name", item["catId"])  #using node_auto_index


    for f_item in found_items:
        if ("index" not in f_item):
            update=1
            node = f_item
        elif f_item["index"] ==  item["index"]:
            print "found item : " + str(f_item._id)

            #delete all current relationships to allow updating relationships
            rels = f_item.match();
            for rel in rels:
                self.batch.delete(rel);
            update=1
            node = f_item





    updateProperties = {"name": str(item["catId"]),
                                "type":"item"}

    #CREATE node in the Graph DB if doesn't exist
    if update == 0:
          #print item
          node = self.batch.create(updateProperties)
          #print "new item : " + str(node.id)
    else:      
        #Update all properties
        self.batch.set_properties(node,updateProperties)




    #connect item to all properties nodes
    for pr in prop_nodes: 
        self.batch.create((node,pr["rel"],pr["node"]))      


    xlItem["ITEM_BRAND"] = [item['company']]
    #print defaults
    self.batch.create((node,"ITEM_BRAND",self.brand_node))     

每5件事,我这样做:

self.batch.submit()

代码通常有效(更新或创建),但是,对于特定数据,它在submit()上失败。尽管如此,我还没有找到识别错误的方法。 追溯:

Traceback (most recent call last):
File "crawlerAPI.py", line 199, in <module>
    AddItemOb.insertBatch()
 File "/home/shaika/Workspace/git/DondeSrv/DondeSrv/Crawler_APIs/AddItemNeoDBBatch.py",  line 302, in insertBatch
    res = self.batch.submit()    
   File "/usr/local/lib/python2.7/dist-packages/py2neo-1.6.1-py2.7.egg/py2neo/neo4j.py", line 2594, in submit
    responses = self._execute()
   File "/usr/local/lib/python2.7/dist-packages/py2neo-1.6.1-py2.7.egg/py2neo/neo4j.py", line 2565, in _execute
raise CustomBatchError(e)
py2neo.neo4j.BatchOperationFailedException

我正在使用py2neo 1.6.1和neo4j 1.9.2

修改

在neo4j日志中发现以下错误:

13:07:07.228 [1619084319@qtp-1813233625-226] ERROR org.mortbay.log - /db/data/relationship/259221
java.lang.IllegalStateException: Unable to delete relationship[259221] since it is already deleted.
    at org.neo4j.kernel.impl.nioneo.xa.WriteTransaction.relDelete(WriteTransaction.java:668) ~[neo4j-kernel-1.9.2.jar:1.9.2]
    at org.neo4j.kernel.impl.persistence.PersistenceManager.relDelete(PersistenceManager.java:171) ~[neo4j-kernel-1.9.2.jar:1.9.2]
    at org.neo4j.kernel.impl.core.NodeManager.deleteRelationship(NodeManager.java:1140) ~[neo4j-kernel-1.9.2.jar:1.9.2]
    at org.neo4j.kernel.impl.core.RelationshipImpl.delete(RelationshipImpl.java:138) ~[neo4j-kernel-1.9.2.jar:1.9.2]
    at org.neo4j.kernel.impl.core.RelationshipProxy.delete(RelationshipProxy.java:62) ~[neo4j-kernel-1.9.2.jar:1.9.2]
    at org.neo4j.server.rest.web.DatabaseActions.deleteRelationship(DatabaseActions.java:557) ~[neo4j-server-1.9.2.jar:1.9.2]
    at org.neo4j.server.rest.web.RestfulGraphDatabase.deleteRelationship(RestfulGraphDatabase.java:465) ~[neo4j-server-1.9.2.jar:1.9.2]
    at sun.reflect.GeneratedMethodAccessor119.invoke(Unknown Source) ~[na:na]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_25]
    at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_25]
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699) ~[jersey-server-1.9.jar:1.9]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) ~[servlet-api-2.5-20081211.jar:na]
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) ~[jetty-6.1.25.jar:6.1.25]
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) ~[jetty-6.1.25.jar:6.1.25]
    at org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112) ~[neo4j-server-1.9.2.jar:1.9.2]
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) ~[jetty-6.1.25.jar:6.1.25]
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) [jetty-6.1.25.jar:6.1.25]
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) ~[jetty-6.1.25.jar:6.1.25]
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) ~[jetty-6.1.25.jar:6.1.25]
    at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) ~[jetty-6.1.25.jar:6.1.25]
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) ~[jetty-6.1.25.jar:6.1.25]
    at org.neo4j.server.web.Jetty6WebServer.invokeDirectly(Jetty6WebServer.java:302) ~[neo4j-server-1.9.2.jar:1.9.2]
    at org.neo4j.server.rest.batch.NonStreamingBatchOperations.invoke(NonStreamingBatchOperations.java:55) ~[neo4j-server-1.9.2.jar:1.9.2]
    at org.neo4j.server.rest.batch.BatchOperations.performRequest(BatchOperations.java:188) ~[neo4j-server-1.9.2.jar:1.9.2]
    at org.neo4j.server.rest.batch.BatchOperations.parseAndPerform(BatchOperations.java:159) ~[neo4j-server-1.9.2.jar:1.9.2]
    at org.neo4j.server.rest.batch.NonStreamingBatchOperations.performBatchJobs(NonStreamingBatchOperations.java:48) ~[neo4j-server-1.9.2.jar:1.9.2]
    at org.neo4j.server.rest.web.BatchOperationService.batchProcess(BatchOperationService.java:117) ~[neo4j-server-1.9.2.jar:1.9.2]
    at org.neo4j.server.rest.web.BatchOperationService.performBatchOperations(BatchOperationService.java:72) ~[neo4j-server-1.9.2.jar:1.9.2]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_25]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_25]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_25]
    at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_25]
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) ~[jersey-server-1.9.jar:1.9]
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699) ~[jersey-server-1.9.jar:1.9]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) ~[servlet-api-2.5-20081211.jar:na]
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) ~[jetty-6.1.25.jar:6.1.25]
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) ~[jetty-6.1.25.jar:6.1.25]
    at org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112) ~[neo4j-server-1.9.2.jar:1.9.2]
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) ~[jetty-6.1.25.jar:6.1.25]
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) [jetty-6.1.25.jar:6.1.25]
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) ~[jetty-6.1.25.jar:6.1.25]
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) ~[jetty-6.1.25.jar:6.1.25]
    at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) ~[jetty-6.1.25.jar:6.1.25]
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) ~[jetty-6.1.25.jar:6.1.25]
    at org.mortbay.jetty.Server.handle(Server.java:326) ~[jetty-6.1.25.jar:6.1.25]
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) ~[jetty-6.1.25.jar:6.1.25]
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943) ~[jetty-6.1.25.jar:6.1.25]
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756) ~[jetty-6.1.25.jar:6.1.25]
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) ~[jetty-6.1.25.jar:6.1.25]
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) ~[jetty-6.1.25.jar:6.1.25]
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410) ~[jetty-6.1.25.jar:6.1.25]
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) ~[jetty-util-6.1.25.jar:6.1.25]

0 个答案:

没有答案