Package com.sleepycat.je

Examples of com.sleepycat.je.Database


      File location = verifyOrCreateEnvironmentDirectory(new File(cfg.getLocation()));
      try {
         env = factory.createEnvironment(location, cfg.readEnvironmentProperties());
         cacheDb = factory.createDatabase(env, cfg.getCacheDbName());
         Database catalogDb = factory.createDatabase(env, cfg.getCatalogDbName());
         expiryDb = factory.createDatabase(env, cfg.getExpiryDbName());
         catalog = factory.createStoredClassCatalog(catalogDb);
         cacheMap = factory.createStoredMapViewOfDatabase(cacheDb, catalog, marshaller);
         expiryMap = factory.createStoredSortedMapForKeyExpiry(expiryDb, catalog, marshaller);
      } catch (DatabaseException e) {
View Full Code Here


        /* Make key entry. */
        DatabaseEntry keyEntry = new DatabaseEntry();
        index.getKeyBinding().objectToEntry(key, keyEntry);

        /* Use keys database if available. */
        Database db = index.getKeysDatabase();
        if (db == null) {
            db = index.getDatabase();
        }

        /* Add condition. */
 
View Full Code Here

        openDatabaseInternal(Map<String,Database> databaseHandleCache,
                             String dbName,
                             DatabaseConfig config)
        throws DatabaseException {

        Database db;
        if (config.getExclusiveCreate()) {
            db = env.openDatabase(null, dbName, config);
            databaseHandleCache.put(dbName, db);
        } else {
            db = databaseHandleCache.get(dbName);
            if (db == null) {
                db = env.openDatabase(null, dbName, config);
                databaseHandleCache.put(dbName, db);
            } else {
                DbInternal.validate(config, db.getConfig());
            }
        }
        return db;
    }
View Full Code Here

    private void removeDatabaseFromCache(Map<String,Database> cache,
                                         String dbName)
        throws DatabaseException {

        synchronized (cache) {
            Database db = cache.get(dbName);
            if (db == null) {
                return;
            }
            db.close();
            cache.remove(dbName);
        }
    }
View Full Code Here

        synchronized (cache) {
            Iterator<Database> iter = cache.values().iterator();

            while (iter.hasNext()) {
                Database db = iter.next();
                db.close();
            }
        }
    }
View Full Code Here

        DatabaseEntry foundData = new DatabaseEntry();

        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setReadOnly(true);
        DbInternal.setUseExistingConfig(dbConfig, true);
        Database db;
        try {
            db = env.openDatabase(null, dbName, dbConfig);
        } catch (DatabaseExistsException e) {
            /* Should never happen, ExclusiveCreate is false. */
            throw EnvironmentFailureException.unexpectedException(e);
        }
        dupSort = db.getConfig().getSortedDuplicates();

        printHeader(outputFile, dupSort, formatUsingPrintable);

        Cursor cursor = db.openCursor(null, null);
        while (cursor.getNext(foundKey, foundData, LockMode.DEFAULT) ==
               OperationStatus.SUCCESS) {
            dumpOne(outputFile, foundKey.getData(), formatUsingPrintable);
            dumpOne(outputFile, foundData.getData(), formatUsingPrintable);
        }
        cursor.close();
        db.close();
        outputFile.println("DATA=END");

        LoggerUtils.envLogMsg(Level.INFO, DbInternal.getEnvironmentImpl(env),
                              "DbDump.dump of " + dbName + " ending");
    }
View Full Code Here

        final byte[] keyBytes = new byte[(nodeAvg <= 0xFF) ? 1 : 2];
        final DatabaseEntry keyEntry = new DatabaseEntry();
        final DatabaseEntry dataEntry = new DatabaseEntry();

        /* Insert nodeAvg records into a single BIN. */
        final Database db = openDatabase(env, true);
        for (int i = 0; i < nodeAvg; i += 1) {
            if (keyBytes.length == 1) {
                keyBytes[0] = (byte) i;
            } else {
                assert keyBytes.length == 2;
                keyBytes[0] = (byte) (i >> 8);
                keyBytes[1] = (byte) i;
            }
            setKeyData(keyBytes, keyPrefix, keyEntry, dataEntry);

            final OperationStatus status;
            if (duplicates) {
                status = db.putNoDupData(null, keyEntry, dataEntry);
            } else {
                status = db.putNoOverwrite(null, keyEntry, dataEntry);
            }
            if (status != OperationStatus.SUCCESS) {
                throw new IllegalStateException(status.toString());
            }
        }

        /* Position a cursor to the first record. */
        final Cursor cursor = db.openCursor(null, null);
        OperationStatus status = cursor.getFirst(keyEntry, dataEntry, null);
        assert status == OperationStatus.SUCCESS;

        /*
         * Calculate BIN size including LNs/data. The recalcKeyPrefix and
         * compactMemory methods are called to simulate normal operation.
         * Normally prefixes are recalculated when a IN is split, and
         * compactMemory is called after fetching a IN or evicting an LN.
         */
        final BIN bin = DbInternal.getCursorImpl(cursor).getBIN();
        bin.recalcKeyPrefix();
        bin.compactMemory();
        minBinSizeWithData = bin.getInMemorySize();

        /* Evict all LNs. */
        for (int i = 0; i < nodeAvg; i += 1) {
            assert status == OperationStatus.SUCCESS;
            final CursorImpl cursorImpl = DbInternal.getCursorImpl(cursor);
            assert bin == cursorImpl.getBIN();
            assert duplicates ?
                (bin.getTarget(i) == null) :
                (bin.getTarget(i) != null);
            if (!duplicates) {
                cursorImpl.evict();
            }
            status = cursor.getNext(keyEntry, dataEntry, null);
        }
        assert status == OperationStatus.NOTFOUND;
        cursor.close();

        /*
         * Calculate BIN size without LNs/data. The clearLsnCompaction method
         * is called to artificially remove LSN compaction savings.  The amount
         * saved by LSN compaction is currently the only difference between the
         * min and max memory sizes.
         */
        bin.compactMemory();
        minBinSize = bin.getInMemorySize();
        bin.clearLsnCompaction();
        maxBinSize = bin.getInMemorySize();
        final long lsnSavings = maxBinSize - minBinSize;
        maxBinSizeWithData = minBinSizeWithData + lsnSavings;

        /*
         * To calculate IN size, get parent/root IN and artificially fill the
         * slots with nodeAvg entries.
         */
        final IN in = DbInternal.getDatabaseImpl(db).
                                 getTree().
                                 getRootINLatchedExclusive(CacheMode.DEFAULT);
        assert bin == in.getTarget(0);
        for (int i = 1; i < nodeAvg; i += 1) {
            final ChildReference child =
                new ChildReference(bin, bin.getKey(i), bin.getLsn(i));
            final int result = in.insertEntry1(child);
            assert (result & IN.INSERT_SUCCESS) != 0;
            assert i == (result & ~IN.INSERT_SUCCESS);
        }
        in.recalcKeyPrefix();
        in.compactMemory();
        in.releaseLatch();
        minInSize = in.getInMemorySize();
        maxInSize = minInSize + lsnSavings;

        db.close();
    }
View Full Code Here

     */
    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 {

View Full Code Here

            DatabaseConfig dbConfig = new DatabaseConfig();
            dbConfig.setReadOnly(true);
            dbConfig.setAllowCreate(false);
            DbInternal.setUseExistingConfig(dbConfig, true);
            Database db;
            try {
                db = env.openDatabase(null, targetDb, dbConfig);
            } catch (DatabaseNotFoundException e) {
                /* DB was removed after getting names -- ignore it. */
                continue;
            } catch (DatabaseExistsException e) {
                /* Should never happen, ExclusiveCreate is false. */
                throw EnvironmentFailureException.unexpectedException(e);
            }

            try {
                if (!verifyOneDbImpl(DbInternal.getDatabaseImpl(db),
                                     targetDb,
                                     verifyConfig,
                                     out)) {
                    ret = false;
                }
            } finally {
                if (db != null) {
                    db.close();
                }
                LoggerUtils.envLogMsg(Level.INFO, envImpl,
                                   "DbVerify.verify of " + targetDb +
                                   " ending");
            }
View Full Code Here

            DatabaseConfig dbConfig = new DatabaseConfig();
            dbConfig.setReadOnly(true);
            dbConfig.setAllowCreate(false);
            DbInternal.setUseExistingConfig(dbConfig, true);
            Database db;
            try {
                db = env.openDatabase(null, dbName, dbConfig);
            } catch (DatabaseExistsException e) {
                /* Should never happen, ExclusiveCreate is false. */
                throw EnvironmentFailureException.unexpectedException(e);
            }

            StatsConfig statsConfig = new StatsConfig();
            if (progressInterval > 0) {
                statsConfig.setShowProgressInterval(progressInterval);
                statsConfig.setShowProgressStream(out);
            }

            DatabaseStats stats = db.getStats(statsConfig);
            out.println(stats);

            db.close();
            LoggerUtils.envLogMsg(Level.INFO, DbInternal.getEnvironmentImpl(env),
                               "DbStat.stats of " + dbName + " ending");
        } catch (DatabaseException DE) {
            return false;
        }
View Full Code Here

TOP

Related Classes of com.sleepycat.je.Database

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.