【问题标题】:Is it possible to force a neo4j transaction to timeout?是否可以强制 Neo4j 事务超时?
【发布时间】:2015-11-16 22:30:35
【问题描述】:

这可能是用于访问一些 Neo4j 数据的典型 Java 7 样板。

是否存在任何机制,您可以将事务设置为根据超时自动失败和回滚?

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 并增加每次迭代,然后:

if(count > XYZ) throw TakingTooLongException(count)

?

【问题讨论】:

    标签: performance transactions neo4j


    【解决方案1】:

    您也可以在循环之前预先检查node.getDegree(),这是密集节点的恒定时间操作和所有其他节点的小计数器(

    要不然也有行刑守卫,不过不知道能活多久。

    你可以直接从 tx 返回而不调用tx.success(),它应该被回滚。

    【讨论】:

    • 我要试试这个。该代码最近从1.9.8 升级,所以新功能是,嗯,新...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多