Package com.sleepycat.je.dbi

Examples of com.sleepycat.je.dbi.DatabaseImpl$ObsoleteProcessor


                      final DbState newState,
                      final OperationFailureException preemptedException)
        throws DatabaseException {

        StringBuilder errors = null;
        DatabaseImpl dbClosed = null;

        synchronized (this) {
            checkEnv();

            /* Do nothing if handle was previously closed. */
            if (state != DbState.OPEN) {
                return;
            }

            /*
             * The state should be changed ASAP during close, so that
             * addCursor and removeCursor will see the updated state ASAP.
             */
            state = newState;
            preemptedCause = preemptedException;

            /*
             * Throw a DatabaseException if there are open cursors while
             * closing a Database.
             */
            if (newState == DbState.CLOSED &&
                openCursors.get() != 0) {
                errors = new StringBuilder();
                errors.append("Database still has " + openCursors.get() +
                              " open cursors while trying to close.");
            }

            trace(Level.FINEST, "Database.close: ", null, null);

            /* Disassociate triggers before closing. */
            removeAllTriggers();

            envHandle.removeReferringHandle(this);

            if (databaseImpl != null) {
                dbClosed = databaseImpl;
                databaseImpl.removeReferringHandle(this);
                envHandle.getEnvironmentImpl().
                    getDbTree().releaseDb(databaseImpl);

                /*
                 * Database.close may be called after an abort.  By setting the
                 * databaseImpl field to null we ensure that close won't call
                 * releaseDb or endOperation. [#13415]
                 */
                databaseImpl = null;

                if (handleLocker != null) {

                    /*
                     * If the handle was preempted, we mark the locker as
                     * only-abortable with the DatabasePreemptedException.  If
                     * the handle locker is a user txn, this causes the
                     * DatabasePreemptedException to be thrown if the user
                     * attempts to commit, or continue to use, the txn, rather
                     * than throwing a LockConflictException.  [#17015]
                     */
                    if (newState == DbState.PREEMPTED) {
                        handleLocker.setOnlyAbortable(preemptedException);
                    }

                    /*
                     * Tell our protecting txn that we're closing. If this type
                     * of transaction doesn't live beyond the life of the
                     * handle, it will release the db handle lock.
                     */
                    if (newState == DbState.CLOSED) {
                        if (isWritable() &&
                            (dbClosed.noteWriteHandleClose() == 0)) {
                            TriggerManager.runCloseTriggers(handleLocker,
                                                            dbClosed);
                        }
                        handleLocker.operationEnd(true);
                    } else {
                        handleLocker.operationEnd(false);
                    }

                    /* Null-out indirect reference to environment. */
                    handleLocker = null;
                }
            }
        }

        /*
         * Notify the database when a handle is closed.  This should not be
         * done while synchronized since it may perform database removal or
         * sync.  Statements above are synchronized but this section must not
         * be.
         */
        if (dbClosed != null) {
            dbClosed.handleClosed(doSyncDw, deleteTempDb);
        }

        if (errors != null) {
            throw new IllegalStateException(errors.toString());
        }
View Full Code Here


                                           Database dbHandle,
                                           Locker locker,
                                           boolean readCommittedIsolation)
        throws DatabaseException {

        DatabaseImpl dbImpl = DbInternal.getDatabaseImpl(dbHandle);
        if (!dbImpl.isTransactional() &&
            locker != null &&
            locker.isTransactional()) {
            throw new IllegalArgumentException
                ("A Transaction cannot be used because the" +
                 " database was opened non-transactionally");
View Full Code Here

        validateDbConfigAgainstEnv(dbConfig, databaseName, isInternalDb);

        /* Perform eviction before each operation that allocates memory. */
        envImpl.criticalEviction(false /*backgroundIO*/);

        DatabaseImpl database = null;
        boolean operationOk = false;
        HandleLocker handleLocker = null;
        final Locker locker = LockerFactory.getWritableLocker
            (this, txn, isInternalDb, dbConfig.getTransactional(),
             autoTxnIsReplicated, null);
        try {

            /*
             * Create the handle locker and lock the NameLN of an existing
             * database.  A read lock on the NameLN is acquired for both locker
             * and handleLocker.  Note: getDb may return a deleted database.
             */
            handleLocker = newDb.initHandleLocker(envImpl, locker);
            database = envImpl.getDbTree().getDb(locker, databaseName,
                                                 handleLocker);

            boolean dbCreated = false;
            final boolean databaseExists =
                (database != null) && !database.isDeleted();

            if (databaseExists) {
                if (dbConfig.getAllowCreate() &&
                    dbConfig.getExclusiveCreate()) {
                    throw new DatabaseExistsException
View Full Code Here

        checkEnv();
        checkWritable();

        final boolean autoTxnIsReplicated = envImpl.isReplicated();
        Locker locker = null;
        DatabaseImpl dbImpl = null;
        try {

            /*
             * Note: use env level isTransactional as proxy for the db
             * isTransactional.
 
View Full Code Here

        checkHandleIsValid();
        checkEnv();
        checkWritable();

        Locker locker = null;
        DatabaseImpl dbImpl = null;
        try {

            /*
             * Note: use env level isTransactional as proxy for the db
             * isTransactional.
 
View Full Code Here

        for (int i = 0; i < entries.size(); i += 2) {
            final ExtendedFileSummary summary =
                (ExtendedFileSummary) entries.get(i);
            final LNLogEntry lnEntry = (LNLogEntry) entries.get(i + 1);
            final DatabaseId dbId = lnEntry.getDbId();
            final DatabaseImpl dbImpl =
                dbTree.getDb(dbId, -1 /*timeout*/, dbCache);
            final int size = lnEntry.getLastLoggedSize();

            summary.totalLNCount += 1;
            summary.totalLNSize += size;

            if (!commit ||
                lnEntry.isDeleted() ||
                dbImpl == null ||
                dbImpl.isDeleteFinished()) {

                /* Count immediately obsolete LN. */
                summary.obsoleteLNCount += 1;
                summary.recalcObsoleteLNSize += size;
            }
            if (commit && dbImpl != null) {
                /* Count committed LN. */
                lnEntry.postFetchInit(dbImpl);
                final CompareSlot slot = new CompareSlot(dbImpl, lnEntry);
                countObsoleteLN(slot);
                if (dbImpl.isDeleteFinished() || lnEntry.isDeleted()) {
                    activeLNs.remove(slot);
                } else {
                    putActiveLN(slot, size, summary,
                                lnEntry.getDbId().getId());
                }
View Full Code Here

                /*
                 * Check to make sure the DB was not deleted after selecting
                 * it, and prevent the DB from being deleted while we're
                 * working with it.
                 */
                DatabaseImpl targetDb = target.getDatabase();
                DbTree dbTree = targetDb.getDbEnvironment().getDbTree();
                DatabaseImpl refreshedDb = null;
                try {
                    refreshedDb = dbTree.getDb(targetDb.getId());
                    if (refreshedDb != null && !refreshedDb.isDeleted()) {
                        if (target.isDbRoot()) {
                            evictBytes += evictRoot(target, backgroundIO);
                        } else {
                            evictBytes +=
                                evictIN(target, backgroundIO, source);
                        }
                    } else {

                        /*
                         * We don't expect to see an IN that is resident on
                         * the INList with a database that has finished
                         * delete processing, because it should have been
                         * removed from the INList during post-delete
                         * cleanup.  It may have been returned by the
                         * INList iterator after being removed from the
                         * INList (because we're using ConcurrentHashMap),
                         * but then IN.getInListResident should return false.
                         */
                        if (targetDb.isDeleteFinished() &&
                            target.getInListResident()) {
                            String inInfo =
                                " IN type=" + target.getLogType() + " id=" +
                                target.getNodeId() + " not expected on INList";
                            String errMsg = (refreshedDb == null) ?
                                inInfo :
                                ("Database " + refreshedDb.getDebugName() +
                                 " id=" + refreshedDb.getId() + " rootLsn=" +
                                 DbLsn.getNoFormatString
                                 (refreshedDb.getTree().getRootLsn()) +
                                  ' ' + inInfo);
                            throw EnvironmentFailureException.
                                unexpectedState(errMsg);
                        }
                    }
View Full Code Here

     */
    private long evictRoot(final IN target,
                           final boolean backgroundIO)
        throws DatabaseException {

        final DatabaseImpl db = target.getDatabase();
        /* SharedEvictor uses multiple envs, do not use superclass envImpl. */
        final EnvironmentImpl useEnvImpl = db.getDbEnvironment();
        final INList inList = useEnvImpl.getInMemoryINs();

        class RootEvictor implements WithRootLatched {

            boolean flushed = false;
            long evictBytes = 0;

            public IN doWork(ChildReference root)
                throws DatabaseException {

                IN rootIN = (IN) root.fetchTarget(db, null);
                rootIN.latch(CacheMode.UNCHANGED);
                try {
                    /* Re-check that all conditions still hold. */
                    boolean isDirty = rootIN.getDirty();
                    if (rootIN == target &&
                        rootIN.isDbRoot() &&
                        rootIN.isEvictable() &&
                        !(useEnvImpl.isReadOnly() && isDirty)) {
                        boolean logProvisional =
                            coordinateWithCheckpoint(rootIN, null /*parent*/);

                        /* Flush if dirty. */
                        if (isDirty) {
                            long newLsn = rootIN.log
                                (useEnvImpl.getLogManager(),
                                 false, // allowDeltas
                                 false, // allowCompress
                                 logProvisional,
                                 backgroundIO,
                                 null); // parent
                            root.setLsn(newLsn);
                            flushed = true;
                        }

                        /* Take off the INList and adjust memory budget. */
                        inList.remove(rootIN);
                        evictBytes = rootIN.getBudgetedMemorySize();

                        /* Evict IN. */
                        root.clearTarget();

                        /* Stats */
                        nRootNodesEvicted.increment();
                    }
                } finally {
                    rootIN.releaseLatch();
                }

                return null;
            }
        }

        /* Attempt to evict the DB root IN. */
        RootEvictor evictor = new RootEvictor();
        db.getTree().withRootLatchedExclusive(evictor);

        /* If the root IN was flushed, write the dirtied MapLN. */
        if (evictor.flushed) {
            useEnvImpl.getDbTree().modifyDbRoot(db);
        }
View Full Code Here

     * @return number of bytes evicted.
     */
    private long evictIN(IN target, boolean backgroundIO, EvictionSource source)
        throws DatabaseException {

        DatabaseImpl db = target.getDatabase();
        /* SharedEvictor uses multiple envs, do not use superclass envImpl. */
        EnvironmentImpl useEnvImpl = db.getDbEnvironment();
        long evictedBytes = 0;

        /*
         * Non-BIN INs are evicted by detaching them from their parent.  For
         * BINS, the first step is to remove deleted entries by compressing
         * the BIN. The evictor indicates that we shouldn't fault in
         * non-resident children during compression. After compression,
         * LN logging and LN stripping may be performed.
         *
         * If LN stripping is used, first we strip the BIN by logging any dirty
         * LN children and detaching all its resident LN targets.  If we make
         * progress doing that, we stop and will not evict the BIN itself until
         * possibly later.  If it has no resident LNs then we evict the BIN
         * itself using the "regular" detach-from-parent routine.
         *
         * If the cleaner is doing clustering, we don't do BIN stripping if we
         * can write out the BIN.  Specifically LN stripping is not performed
         * if the BIN is dirty AND the BIN is evictable AND cleaner
         * clustering is enabled.  In this case the BIN is going to be written
         * out soon, and with clustering we want to be sure to write out the
         * LNs with the BIN; therefore we don't do stripping.
         */

        /*
         * Use latchNoWait because if it's latched we don't want the cleaner
         * to hold up eviction while it migrates an entire BIN.  Latched INs
         * have a high generation value, so not evicting makes sense.  Pass
         * false because we don't want to change the generation during the
         * eviction process.
         */
        boolean inline = (source == EvictionSource.CACHEMODE);
        if (inline) {
            target.latch(CacheMode.UNCHANGED);
        } else {
            if (!target.latchNoWait(CacheMode.UNCHANGED)) {
                return evictedBytes;
            }
        }
        boolean targetIsLatched = true;
        boolean success = false;
        try {
            if (target instanceof BIN) {

                /*
                 * Strip any resident LN targets right now. This may dirty
                 * the BIN if dirty LNs were written out. Note that
                 * migrated BIN entries cannot be stripped.
                 */
                evictedBytes = ((BIN) target).evictLNs();
                if (evictedBytes > 0) {
                    nBINsStripped.increment();
                }
            }

            /*
             * If we were able to free any memory by LN stripping above,
             * then we postpone eviction of the BIN until a later pass.
             * The presence of migrated entries would have inhibited LN
             * stripping. In that case, the BIN can still be evicted,
             * but the marked entries will have to be migrated. That would
             * happen when the target is logged in evictIN.
             */
            if (!inline && evictedBytes != 0) {
                success = true;
                return evictedBytes;
            }
            if (!target.isEvictable()) {
                success = true;
                return evictedBytes;
            }
            /* Regular eviction. */
            Tree tree = db.getTree();

            /*
             * Unit testing.  The target is latched and we are about to release
             * that latch and search for the parent.  Make sure that other
             * operations, such as dirtying an LN in the target BIN, can occur
View Full Code Here

            try {
                if (!renewedChild.isEvictable()) {
                    return evictBytes;
                }

                DatabaseImpl db = renewedChild.getDatabase();
                /* Do not use superclass envImpl. */
                EnvironmentImpl useEnvImpl = db.getDbEnvironment();

                /*
                 * Log the child if dirty and env is not r/o. Remove
                 * from IN list.
                 */
 
View Full Code Here

TOP

Related Classes of com.sleepycat.je.dbi.DatabaseImpl$ObsoleteProcessor

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.