Search code examples
javaxodus

Using a shared / mounted block storage with Xodus


Is it safe to use mounted block storage as the Xodus database path? The idea is to run the application that uses Xodus in several different hosts. So each Xodus-based application is pointing to the same mounted path (e.g /mnt/xodus)

In this case, each application opens the Xodus environment like in the code below. If we open the environment like this:

  @Override
  public Environment getEnvironment(String xodusRoot, String instance) {
    Environment environment = environmentMap.get(xodusRoot + instance);
    if (environment == null) {
      EnvironmentConfig config = new EnvironmentConfig();
      config.setLogCacheShared(false);
      Environment env = Environments.newInstance(xodusRoot + instance, config);
      environmentMap.put(xodusRoot + instance, env);
    }
    Environment e = environmentMap.get(xodusRoot + instance);
    return e;
  }

Is it safe for multiple Xodus instances to point to a mounted path?


Solution

  • It depends on what particular block storage do you use. E.g., Xodus runs on Amazon EBS quite well, but EBS won't allow to share database files. If a block storage is shareable, then any opened Environment will be locked, so you have to somehow "shard" environment paths among hosts in order to prevent open conflicts. Probably, one can try to open Environments in read-only listening mode, but it would work only if the block storage can produce suitable file system events.

    In addition, setting config.setLogCacheShared(false) would result in OOME if using several environments within single JVM.