2 Replies Latest reply: Oct 4, 2012 12:39 AM by 958983 RSS

    Writing log files in different subdirectories


      Is there a way to write the logs in different sub-directories. I want to write records by type or class. Example putting the records of dogs in one directory, cats in another directory. But the same environment, an Animal environment as the main environment. Can you give me a sample code for this example if it is possible.

      Thanks in advance.
        • 1. Re: Writing log files in different subdirectories
          "Andrei Costache, Oracle-Oracle"

          It would be worth we first make sure there is a clear understanding of how JE stores data. JE uses a log-based approach to storing data. There are no separate database files, that is, database records and transaction logs are stored together is a single sequential log consisting of multiple log files. These JE log files are append-only with records insertions, deletions and updates being added at the end of the current log file (the JE log files are the NNNNNNNN.jdb files). More info is here.

          There is a way to spread the JE log files across multiple directories which allows to improve throughput by distributing disk I/O across multiple disks or file systems. See the Multiple Environment Subdirectories documentation section. However, this does not mean that your databases, enclosed in the JE log files, will also be spread across these directories.

          In order to separate the data sets the way you want, by type or class (e.g. Animal/Dog, Animal/Cat etc), you will need to use multiple JE environments -- each environment will correspond to the type of Animal data you will store. Though, there is an important down side to using multiple environments; a single transaction cannot span/include changes made in more than one environment.
          You'll also want to look into using a shared cache for these multiple environments, in order to make much more efficient use of memory rather than using private caches.
          See the Multiple Environments and Configuring a Shared Cache for Multiple Environments documentation sections. Bellow is a snippet of code showing how you would open multiple environment using a shared cache:
          // Environment references as needed (dog, cats, horses etc)
          Environment dogEnv = null;
          Environment catEnv = null;
          Environment horseEnv = null;
          // Open the Animal subtypes environments (the directories needs to exist)
          try {
               EnvironmentConfig envConfig = new EnvironmentConfig();
               dogEnv = new Environment(new File("/test/animal/dog"), envConfig);
               catEnv = new Environment(new File("/test/animal/cat"), envConfig);
               horseEnv = new Environment(new File("/test/animal/horse"), envConfig);
          } catch (DatabaseException dbe) {