更新节点

时间:2017-02-15 00:52:57

标签: java neo4j py2neo graphaware

编辑: 现在发现了一个丑陋的绑定修复程序,但仍然需要帮助解决该错误。问题末尾的详细信息。

我目前正在使用py2neo在neo4j和flask之间开发db / site。我正在开发一个通知系统,在X操作时,用户会收到X发生的通知。要做到这一点,我要创建一个新的"更新"合并DB中的节点。

但事情是,如果类似的动作Y以相同的方式发生,我想要而不是创建新的更新节点,更新旧的更新节点。通常合并对于此可以正常工作,因为它应该在创建新属性之前检测具有这些属性的节点是否已经存在。我遇到的问题是该节点的属性发生了变化,例如" date_time"财产每次都会有所不同。因此,它为相同类型的操作创建了第二个更新节点,而不是简单地更新date_time。

为避免这种情况,我会执行以下操作:

update = Node('Update',  updateUUID = other_node['uuid'])
graph.merge(update)

update['date_time'] = new_date_time
graph.push(update) ## Same error if I use update.push()

rel = Relationship(other_node, 'has_update', update)
graph.create(rel)

这是其他人建议更新现有节点的方法。具体来说,仅使用节点的唯一属性调用merge,然后使用push调用将其他数据分别推送到它。

如果有问题的节点已提前存在,则此方法非常有效。实际上,如果我尝试这样做,它只会在第一次尝试时失败,因为节点会在失败之前部分创建。如果我第二次重复操作X,则更新节点会成功更改,并使用新属性覆盖第一个未完成的节点。

最后,这是我得到的实际错误。如上所述,运行上述操作的结果将最初创建节点并成功进行合并,但无法执行更新,从而在数据库中留下了几乎空白的节点。

2017-02-15 00:40:25.636+0000 WARN  /db/data/batch Transaction was marked as successful, but unable to commit transaction so rolled back.
org.neo4j.graphdb.TransactionFailureException: Transaction was marked as successful, but unable to commit transaction so rolled back.
    at org.neo4j.kernel.impl.coreapi.TopLevelTransaction.close(TopLevelTransaction.java:101)
    at org.neo4j.server.rest.transactional.CommitOnSuccessfulStatusCodeRepresentationWriteHandler.closeTransaction(CommitOnSuccessfulStatusCodeRepresentationWriteHandler.java:65)
    at org.neo4j.server.rest.transactional.CommitOnSuccessfulStatusCodeRepresentationWriteHandler.onRepresentationFinal(CommitOnSuccessfulStatusCodeRepresentationWriteHandler.java:60)
    at org.neo4j.server.rest.web.BatchOperationService$1.write(BatchOperationService.java:137)
    at com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:71)
    at com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:57)
    at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:302)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1510)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)
    at org.neo4j.server.rest.dbms.AuthorizationEnabledFilter.doFilter(AuthorizationEnabledFilter.java:122)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
    at org.neo4j.server.rest.web.CollectUserAgentFilter.doFilter(CollectUserAgentFilter.java:69)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:497)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.neo4j.kernel.api.exceptions.TransactionFailureException: 
    at org.neo4j.kernel.impl.api.KernelTransactionImplementation.commit(KernelTransactionImplementation.java:553)
    at org.neo4j.kernel.impl.api.KernelTransactionImplementation.closeTransaction(KernelTransactionImplementation.java:484)
    at org.neo4j.kernel.api.KernelTransaction.close(KernelTransaction.java:135)
    at org.neo4j.kernel.impl.coreapi.TopLevelTransaction.close(TopLevelTransaction.java:79)
    ... 35 more
Caused by: org.neo4j.kernel.api.exceptions.TransactionHookException: Transaction handler failed.
    at org.neo4j.kernel.impl.api.TransactionHooks$TransactionHooksState.add(TransactionHooks.java:102)
    at org.neo4j.kernel.impl.api.TransactionHooks.beforeCommit(TransactionHooks.java:61)
    at org.neo4j.kernel.impl.api.KernelTransactionImplementation.commit(KernelTransactionImplementation.java:549)
    ... 38 more
Caused by: com.graphaware.runtime.module.DeliberateTransactionRollbackException: You are not allowed to remove the uuid property
    at com.graphaware.module.uuid.UuidModule.beforeCommit(UuidModule.java:143)
    at com.graphaware.module.uuid.UuidModule.beforeCommit(UuidModule.java:40)
    at com.graphaware.runtime.manager.BaseTxDrivenModuleManager.beforeCommit(BaseTxDrivenModuleManager.java:193)
    at com.graphaware.runtime.TxDrivenRuntime.beforeCommit(TxDrivenRuntime.java:76)
    at com.graphaware.runtime.TxDrivenRuntime.beforeCommit(TxDrivenRuntime.java:39)
    at org.neo4j.kernel.internal.TransactionEventHandlers.beforeCommit(TransactionEventHandlers.java:128)
    at org.neo4j.kernel.internal.TransactionEventHandlers.beforeCommit(TransactionEventHandlers.java:50)
    ... 40 more

经过初步研究,我一直认为这是由于缺乏堆空间,这是有道理的,因为我当时处于一个非常弱的系统。但是,在迁移到新系统(并且几乎从头开始安装数据库,使用新的配置文件,确保没有使用任何堆限制设置)之后,我仍然遇到同样的问题。

我在这里有点不知所措,所以如果有人建议如何解决这个问题,或者以不同的方式执行我想要做的事情以避免这个问题,那么非常感谢。

更新:如上所述,错误仅在我第一次创建的节点上抛出。因此,作为临时工作,直到找到真正的解决方案,我只是模仿必要的行为,使其表现得像现有的"节点,即使它是全新的。又名..

graph.merge(update_node)
graph.merge(update_node)

添加第二次合并调用可以避免现在的错误......即使它有点脏。

更新2:

根据要求,这是我的graphaware设置

com.graphaware.runtime.enabled=true   

com.graphaware.module.UIDM.1=com.graphaware.module.uuid.UuidBootstrapper

com.graphaware.module.UIDM.uuidProperty=uuid

com.graphaware.module.UIDM.stripHyphens=false

com.graphaware.module.UIDM.uuidIndex=uuidIndex

com.graphaware.module.UIDM.uuidRelationshipIndex=uuidRelIndex

更新3: 继续调试,这就是用简单的&ubeid'替换updateUUID的结果,属性graphaware通常自己创建和分配。

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/Flask-0.11.1-py2.7.egg/flask/app.py", line 2000, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/Flask-0.11.1-py2.7.egg/flask/app.py", line 1991, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/usr/local/lib/python2.7/dist-packages/Flask-0.11.1-py2.7.egg/flask/app.py", line 1567, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/Flask-0.11.1-py2.7.egg/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/Flask-0.11.1-py2.7.egg/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/Flask-0.11.1-py2.7.egg/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/Flask-0.11.1-py2.7.egg/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/Flask-0.11.1-py2.7.egg/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File ".../views.py", line 608, in updateMem
    answer = mem.update(results)
  File ".../models.py", line 363, in update
    graph.merge(update)
  File "/usr/local/lib/python2.7/dist-packages/py2neo/database/__init__.py", line 639, in merge
    self.begin(autocommit=True).merge(subgraph, label, *property_keys)
  File "/usr/local/lib/python2.7/dist-packages/py2neo/database/__init__.py", line 1169, in merge
    subgraph.__db_merge__(self, primary_label, primary_key)
  File "/usr/local/lib/python2.7/dist-packages/py2neo/types.py", line 443, in __db_merge__
    tx.run(statement, parameters)
  File "/usr/local/lib/python2.7/dist-packages/py2neo/database/__init__.py", line 1277, in run
    self.finish()
  File "/usr/local/lib/python2.7/dist-packages/py2neo/database/__init__.py", line 1296, in finish
    self._sync()
  File "/usr/local/lib/python2.7/dist-packages/py2neo/database/__init__.py", line 1286, in _sync
    connection.fetch()
  File "/usr/local/lib/python2.7/dist-packages/py2neo/packages/neo4j/v1/bolt.py", line 344, in fetch
    handler(*fields)
  File "/usr/local/lib/python2.7/dist-packages/py2neo/database/__init__.py", line 961, in on_failure
    raise GraphError.hydrate(metadata)
ClientError:  [Neo.ClientError.Transaction.TransactionHookFailed]

0 个答案:

没有答案