2 Replies Latest reply on Mar 22, 2013 1:07 PM by 998288

    Bug with setAllowCreate of Environment

    998288
      Hi,

      Maybe I missunderstand something, but setAllowCreate(true) of Environment class doesn't work properly. I don't want to pre create the folder for my db, so i set allowCreate to true and let sleepycat create it for me if the folder doesn't exist. But that doesn't work and i have not seen any mkdirs() to create the folder in the source code:

      class EnvironmentImpl line 453:

      fileManager = new FileManager(this, envHome, isReadOnly); // the exception is thrown here because "envHome" doesn't exist.

      if (!envConfig.getAllowCreate() && !fileManager.filesExist()) {
      throw new EnvironmentNotFoundException
      (this, "Home directory: " + envHome);
      }

      Moreover, the line "fileManager = new FileManager(this, envHome, isReadOnly);" should be after the "if", so if the "envHome" doesn't exists, it would be checked in the the "if" just after, and if getAllowCreate return true, it should create the folder, so the "fileManager" could be instatiated correctly. I see it smth like this :

      if (envConfig.getAllowCreate() && !envHome.exists()) {
      if(!envHome.mkdirs()) {
      throw new IllegalStateException("Unable to create folder "+envHome.getAbsolutePath());
      }
      }

      fileManager = new FileManager(this, envHome, isReadOnly);



      My config:

      je-5.0.73 version
      Spring 3.1.3


      To resolve this problem our team has extended the Environment class like this :


      public class FixEnvironment extends Environment {
           public FixEnvironment(File envHome, EnvironmentConfig envConfig,
                     boolean openIfNeeded, RepConfigProxy repConfigProxy,
                     EnvironmentImpl envImplParam) {
                super(envHome, envConfig, openIfNeeded, repConfigProxy, envImplParam);
           }

           public FixEnvironment(File envHome, EnvironmentConfig configuration,
                     RepConfigProxy repConfigProxy, EnvironmentImpl envImplParam) {
                super(envHome, configuration, repConfigProxy, envImplParam);
           }

           public FixEnvironment(File envHome, EnvironmentConfig configuration)
                     throws EnvironmentNotFoundException, EnvironmentLockedException,
                     VersionMismatchException, DatabaseException,
                     IllegalArgumentException {
                super(envHome, configuration);
           }

           protected EnvironmentImpl makeEnvironmentImpl(File envHome,
                     EnvironmentConfig envConfig, boolean openIfNeeded,
                     RepConfigProxy repConfigProxy) {

                if (envConfig.getAllowCreate() && !envHome.exists()) {
                     if(!envHome.mkdirs()) {
                          throw new IllegalStateException("Unable to create folder "+envHome.getAbsolutePath());
                     }
                }

                return super.makeEnvironmentImpl(envHome, envConfig, openIfNeeded,
                          repConfigProxy);
           }

      }


      So instead of using the native sleepycat Environment class, we now use the FixEnvironment and that does the trick.

      Edited by: 995285 on 21 mars 2013 03:06

      Edited by: 995285 on 21 mars 2013 03:07