检查 Xodus 环境中的活动事务?

huangapple go评论64阅读模式
英文:

Check active Transactions within a Xodus environment?

问题

以下是翻译好的内容:

如何检查 Xodus 环境中是否有活动事务?

因此,如果您有以下代码:

Environment environment = environmentCache.get(databasePath);

如何知道此环境中是否有活动事务?

英文:

What's the way to check if there are active transactions in a Xodus Environment?

So if you have this:

Environment environment = environmentCache.get(databasePath);

How do you get to know if there are active transactions in this environment?

答案1

得分: 1

为了在负载下安全关闭环境,请使用以下代码:

// 在初始化阶段:
env.getEnvironmentConfig().setEnvCloseForcedly(true);

// 关闭环境的方法:
env.executeTransactionSafeTask(() -> {
    env.executeInExclusiveTransaction(t -> {
        env.close();
    });
});

该代码被提取为一个测试。关闭环境的方式不是立即的,它会等待当前已启动的事务完成,然后在独占事务中关闭环境,以确保没有其他写事务可以并行启动。仍然可以存在并行的只读事务,但它们可以被忽略。

将代码作为远程方法暴露,以便远程控制环境。在调用方法之后,远程端可以立即尝试在相同位置上使用相当长的锁定超时(EnvironmentConfig.setLogLockTimeout(..))打开环境,例如,1分钟。

英文:

To safely close Environment under load, use the following code:

// on init stage:
env.getEnvironmentConfig().setEnvCloseForcedly(true);

// method that closes environment:
env.executeTransactionSafeTask(() -> {
    env.executeInExclusiveTransaction(t -> {
        env.close();
    });
});

The code is extracted as a test. This way of closing Environment is not immediate, it waits until currently started transactions finish and then closes the environment in an exclusive transaction in order to make sure that no other writing transaction can be started in parallel. There still can be parallel read-only transactions, but they obviously can be ignored.

Expose the code as a remote method to control Environment remotely. After calling the method, remote end can immediately try to open Environment above the same location with reasonably long lock timeout (EnvironmentConfig.setLogLockTimeout(..)), say, 1 minute.

huangapple
  • 本文由 发表于 2020年10月5日 13:57:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/64203125.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定