是否可以迫使neo4j事务超时? [英] Is it possible to force a neo4j transaction to timeout?

查看:265
本文介绍了是否可以迫使neo4j事务超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是访问某些Neo4j数据的典型Java 7样板.

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;
} 

我想只有int count = 0并在每次迭代中递增,然后:

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

if(count > XYZ) throw TakingTooLongException(count)

?

推荐答案

您还可以在循环之前先进行node.getDegree()检查,这对于密集型节点而言是恒定时间操作,对于其他所有节点而言都是小计数器(< 50 rels.

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.

您可以不打tx.success()就从tx返回,应该回滚.

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

这篇关于是否可以迫使neo4j事务超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆