Is it possible to force a neo4j transaction to timeout?

断了今生、忘了曾经 提交于 2020-01-06 14:59:07

问题


This might be typical Java 7 boilerplate for accessing some Neo4j data.

Is there any mechanism in existence whereby you can set up the transaction to automatically fail and rollback based upon a timeout?

try (Transaction tx = graphdb.beginTx()) {
    Node node = // Get some Nodes ...
    Iterable<Relationship> rels = node.getRelationships(...);
    for (Relationship rel : rels) {
        // Oh no! This is a super-node with a billion Relationships!
    }
    tx.success();
    return data;
} 

I guess just have int count = 0 and increment each iteration, and then:

if(count > XYZ) throw TakingTooLongException(count)

?


回答1:


You can also just check with node.getDegree() upfront before your loop, which is a constant time operation for dense nodes and a small counter for all others (<50 rels).

Otherwise there is also an execution guard, but I'm not sure for how long it will survive.

You can just return from the tx without calling tx.success() and it should be rolled back.



来源:https://stackoverflow.com/questions/33745865/is-it-possible-to-force-a-neo4j-transaction-to-timeout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!