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?
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.