Package com.sleepycat.je

Examples of com.sleepycat.je.Environment


        if (binMaxEntries <= 0) {
            binMaxEntries = nodeMaxEntries;
        }

        final Environment env = openCalcEnvironment(true);
        boolean success = false;
        try {
            envOverhead = env.getStats(null).getCacheTotalBytes();

            final int density = orderedInsertion ?
                ORDERED_DENSITY :
                DEFAULT_DENSITY;
   
            final int nodeAvg = (nodeMaxEntries * density) / 100;
            final int binAvg = (binMaxEntries * density) / 100;
            final long nBinNodes = (records + binAvg - 1) / binAvg;
            calcTreeSizes(env, nodeAvg, binAvg);

            /* Bottom level. */
            numLevel[0] = nBinNodes;
            minLevel[0] = nBinNodes * minBinSize;
            maxLevel[0] = nBinNodes * maxBinSize;
            btreeLevels = 1;

            /* Upper levels. */
            for (long nodes = (long) (nBinNodes / nodeAvg);; nodes /= nodeAvg) {
                if (btreeLevels >= MAX_LEVELS) {
                    throw new IllegalArgumentException
                        ("Maximum levels (" + MAX_LEVELS + ") exceeded.");
                }
                if (nodes == 0) {
                    nodes = 1; // root
                }
                numLevel[btreeLevels] = nodes;
                minLevel[btreeLevels] = nodes * minInSize;
                maxLevel[btreeLevels] = nodes * maxInSize;
                btreeLevels += 1;
                if (nodes == 1) {
                    break;
                }
            }

            /* Totals without data. */
            minBtreeSize = 0;
            maxBtreeSize = 0;
            for (int level = 0; level < btreeLevels; level += 1) {
                minBtreeSize += minLevel[level];
                maxBtreeSize += maxLevel[level];
            }

            /* Totals with data. */
            minBtreeSizeWithData = nBinNodes * minBinSizeWithData;
            maxBtreeSizeWithData = nBinNodes * maxBinSizeWithData;
            for (int level = 1; level < btreeLevels; level += 1) {
                minBtreeSizeWithData += minLevel[level];
                maxBtreeSizeWithData += maxLevel[level];
            }
            success = true;
        } finally {

            /*
             * Do not propgate exception thrown by Environment.close if another
             * exception is currently in flight.
             */
            try {
                env.close();
            } catch (RuntimeException e) {
                if (success) {
                    throw e;
                }
            }
View Full Code Here


     * For testing, insert the specified data set and initialize the
     * measuredBtreeSize and measuredBtreeSizeWithData fields.
     */
    void measure(final PrintStream out) {

        Environment env = openMeasureEnvironment(true);
        try {
            Database db = openDatabase(env, true);

            if (out != null) {
                out.println("\nMeasuring with cache size: " +
                            INT_FORMAT.format(env.getConfig().getCacheSize()));
            }
            insertRecords(out, env, db);
            measuredBtreeSize = getStats(out, env, "Stats after insert");

            db.close();
            db = null;
            env.close();
            env = null;

            env = openMeasureEnvironment(false);
            db = openDatabase(env, false);

            if (out != null) {
                out.println("\nPreloading with cache size: " +
                            INT_FORMAT.format(env.getConfig().getCacheSize()));
            }
            PreloadStatus status = preloadRecords(out, db, false /*loadLNs*/);
            getStats
                (out, env, "Stats for internal nodes only after preload (" +
                 status + ")");
            if (dataSize >= 0) {
                status = preloadRecords(out, db, true /*loadLNs*/);
                measuredBtreeSizeWithData = getStats
                    (out, env, "Stats for all nodes after preload (" +
                     status + ")");
            }
            db.close();
            db = null;
            env.close();
            env = null;
        } finally {

            /*
             * Do not propgate exception thrown by Environment.close if another
             * exception is currently in flight.
             */
            if (env != null) {
                try {
                    env.close();
                } catch (RuntimeException ignore) {
                }
            }
        }
    }
View Full Code Here

            if (!repParams.isEmpty()) {
                throw new IllegalArgumentException
                    ("Cannot set replication params in a standalone " +
                     "environment.  May add -replicated.");
            }
            return new Environment(tempDir, config);
        }
    }
View Full Code Here

        DbSpace space = new DbSpace();
        space.parseArgs(argv);

        EnvironmentConfig envConfig = new EnvironmentConfig();
        envConfig.setReadOnly(true);
        Environment env = new Environment(space.envHome, envConfig);
        space.initEnv(DbInternal.getEnvironmentImpl(env));

        try {
            space.print(System.out);
            System.exit(0);
        } catch (Throwable e) {
            e.printStackTrace(System.err);
            System.exit(1);
        } finally {
            try {
                env.close();
            } catch (Throwable e) {
                e.printStackTrace(System.err);
                System.exit(1);
            }
        }
View Full Code Here

        throws Exception {

        if (env == null) {
            EnvironmentConfig envConfig = new EnvironmentConfig();
            envConfig.setReadOnly(openReadOnly);
            env = new Environment(envHome, envConfig);
        }
    }
View Full Code Here

         EnvironmentConfig envConfig = new EnvironmentConfig();
         envConfig.setAllowCreate(true);
         envConfig.setTransactional(true);
         envConfig.setLockTimeout(1000 * cache.getConfiguration().getLockAcquisitionTimeout()); // these are in nanos
         if (log.isTraceEnabled()) log.trace("Creating JE environment with home dir " + homeDir);
         env = new Environment(homeDir, envConfig);
         if (log.isDebugEnabled()) log.debug("Created JE environment " + env + " for cache loader " + this);
         /* Open cache and catalog databases. */
         openDatabases();
      }
      catch (Exception e)
View Full Code Here

      loader.setConfig(config);
      loader.create();
      loader.start();

      /* Verify the database name by trying to open it. */
      Environment env = new Environment(new File(envHome), null);
      DatabaseConfig dbConfig = new DatabaseConfig();
      dbConfig.setTransactional(transactional);
      Database db = env.openDatabase(null, dbName, dbConfig);
      db.close();
      env.close();
   }
View Full Code Here

        EnvironmentConfig envConfig = new EnvironmentConfig();
        envConfig.setReadOnly(true);
        envConfig.setTransactional(true);
        envConfig.setAllowCreate(false);
        Environment env = new Environment(envDir, envConfig);
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setReadOnly(true);
        dbConfig.setTransactional(true);
        dbConfig.setAllowCreate(false);
        Transaction txn = env.beginTransaction(null, null);
        Database db = env.openDatabase(txn, DbType.REP_GROUP.getInternalName(),
                                       dbConfig);

        DatabaseEntry groupEntry = new DatabaseEntry();
        OperationStatus status =
            db.get(txn, groupKeyEntry, groupEntry, LockMode.READ_COMMITTED);
        if (status != OperationStatus.SUCCESS) {
            throw new IllegalStateException
                ("Group entry not found " + status);
        }
        GroupBinding groupBinding = new GroupBinding();
        RepGroupImpl group = groupBinding.entryToObject(groupEntry);

        group = fetchGroup(group.getName(),
                           DbInternal.getDatabaseImpl(db),
                           DbInternal.getTxn(txn));
        txn.commit();
        db.close();
        env.close();
        return group;
    }
View Full Code Here

     * nested transactions are not supported by the environment.
     */
    public final Transaction beginTransaction(TransactionConfig config)
        throws DatabaseException {

        Environment env = getEnvironment();
        Trans trans = (Trans) localTrans.get();
        if (trans != null) {
            if (trans.txn != null) {
                if (!DbCompat.NESTED_TRANSACTIONS) {
                    throw new IllegalStateException
                        ("Nested transactions are not supported");
                }
                Transaction parentTxn = trans.txn;
                trans = new Trans(trans, config);
                trans.txn = env.beginTransaction(parentTxn, config);
                localTrans.set(trans);
            } else {
                trans.txn = env.beginTransaction(null, config);
                trans.config = config;
            }
        } else {
            trans = new Trans(null, config);
            trans.txn = env.beginTransaction(null, config);
            localTrans.set(trans);
        }
        return trans.txn;
    }
View Full Code Here

         * Initialize an environment configuration, and create an environment.
         */
        EnvironmentConfig envConfig = new EnvironmentConfig();
        envConfig.setReadOnly(true);
        envConfig.setAllowCreate(false);
        Environment env = new Environment(envHome, envConfig);

        List<String> databaseNames = new LinkedList<String>();
        databaseNames.addAll(env.getDatabaseNames());
        for (String dbName : databaseNames) {

            DatabaseConfig dbCfg = new DatabaseConfig();
            dbCfg.setAllowCreate(false);
            dbCfg.setReadOnly(true);
            DbInternal.setUseExistingConfig(dbCfg, true);

            Database db = env.openDatabase(null, dbName, dbCfg);
            out.println("Database: " + dbName + ", Count: " + db.count());
            db.close();
        }

        env.close();
    }
View Full Code Here

TOP

Related Classes of com.sleepycat.je.Environment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.