Package com.sleepycat.je.dbi

Examples of com.sleepycat.je.dbi.DatabaseImpl


    private void checkTreeUsingExistingNodes(byte[] dupKey,
                                             boolean requireExactMatch)
        throws DatabaseException {

        /* Start at the root. */
        DatabaseImpl database = DbInternal.dbGetDatabaseImpl(db);
        Tree tree = database.getTree();

        if (DEBUG) {
            tree.dump();
        }

View Full Code Here


     * recovery type processing and cleaning.
     */
    private void checkTreeUsingPotentialNodes()
        throws DatabaseException {

        DatabaseImpl database = DbInternal.dbGetDatabaseImpl(db);
        Tree tree = database.getTree();

        /*
         * Make an IN with the key "ab". Its potential parent should be the
         * first level 2 IN.
         */
 
View Full Code Here

  /**
   * Mark all refs from the IN's to the BIN's as "known deleted".  Start
   * at the root.
   */
        DatabaseImpl database = DbInternal.dbGetDatabaseImpl(db);
        Tree tree = database.getTree();

        rootIN = tree.withRootLatched
      (new GetRoot(DbInternal.dbGetDatabaseImpl(db)));
  
        /* Second and third level. */
 
View Full Code Here

                                           Locker locker,
                                           boolean retainNonTxnLocks,
                                           boolean readCommittedIsolation)
        throws DatabaseException {
       
        DatabaseImpl dbImpl = DbInternal.dbGetDatabaseImpl(dbHandle);
        if (!dbImpl.isTransactional() &&
            locker != null &&
            locker.isTransactional()) {
            throw new DatabaseException
                ("A Transaction cannot be used because the" +
                 " database was opened" +
View Full Code Here

          }

          /* Lock the MapLN for the database. */
          DatabaseId fooId =
        DbInternal.dbGetDatabaseImpl(db).getId();
          DatabaseImpl fooDb = dbTree.getDb(fooId, 500000L);
          assert fooDb != null;

          sequence++;

          /* Wait for tester2. */
 
View Full Code Here

                          int expectMapLNs)
      throws DatabaseException {
        EnvironmentImpl envImpl = DbInternal.envGetEnvironmentImpl(env);

        /* check number of LNs in the id mapping tree. */
        DatabaseImpl mapDbImpl =
            envImpl.getDbMapTree().getDb(DbTree.ID_DB_ID);
        // mapDbImpl.getTree().dump();
        BtreeStats mapStats =
            (BtreeStats) mapDbImpl.stat(new StatsConfig());
        assertEquals(expectMapLNs,
                     (mapStats.getLeafNodeCount()));

        /* check number of LNs in the naming tree. */
        DatabaseImpl nameDbImpl =
            envImpl.getDbMapTree().getDb(DbTree.NAME_DB_ID);
        BtreeStats nameStats =
            (BtreeStats) nameDbImpl.stat(new StatsConfig());
        assertEquals(expectNameLNs,
                     (nameStats.getLeafNodeCount()));
    }
View Full Code Here

            cursor = exampleDb.openCursor(null, null);
            // XXX doSimpleVerification(cursor);
            cursor.close();

            /* Check debug name. */
            DatabaseImpl dbImpl = DbInternal.dbGetDatabaseImpl(exampleDb);
            assertEquals(newDatabaseName, dbImpl.getDebugName());
            exampleDb.close();
            try {
                exampleDb = env1.openDatabase(null, databaseName, dbConfig);
                fail("didn't get db not found exception");
            } catch (DatabaseException DBE) {
View Full Code Here

        throws DatabaseException {

        boolean ret = false;
        boolean setNewIdKey = false;
        boolean anyLocksDenied = false;
  DatabaseImpl db = getDatabase();
        BasicLocker lockingTxn = new BasicLocker(db.getDbEnvironment());

        try {
            for (int i = 0; i < getNEntries(); i++) {

    /*
     * We have to be able to lock the LN before we can compress the
     * entry.  If we can't, then, skip over it.
     *
     * We must lock the LN even if isKnownDeleted is true, because
     * locks protect the aborts. (Aborts may execute multiple
     * operations, where each operation latches and unlatches. It's
     * the LN lock that protects the integrity of the whole
     * multi-step process.)
                 *
                 * For example, during abort, there may be cases where we have
     * deleted and then added an LN during the same txn.  This
     * means that to undo/abort it, we first delete the LN (leaving
     * knownDeleted set), and then add it back into the tree.  We
     * want to make sure the entry is in the BIN when we do the
     * insert back in.
     */
                boolean deleteEntry = false;
                long obsoleteLsn = DbLsn.NULL_LSN;
                if (binRef == null ||
        isEntryPendingDeleted(i) ||
                    isEntryKnownDeleted(i) ||
                    binRef.hasDeletedKey(new Key(getKey(i)))) {

                    Node n = null;
                    if (canFetch) {
                        n = fetchTarget(i);
                    } else {
                        n = getTarget(i);
                        if (n == null) {
                            /* Punt, we don't know the state of this child. */
                            continue;
                        }
                    }

                    if (n == null) {
                        /* Cleaner deleted the log file.  Compress this LN. */
                        deleteEntry = true;
                    } else if (isEntryKnownDeleted(i)) {
                        LockGrantType lockRet =
                            lockingTxn.nonBlockingReadLock(n.getNodeId(), db);
                        if (lockRet == LockGrantType.DENIED) {
                            anyLocksDenied = true;
                            continue;
                        }

                        deleteEntry = true;
                    } else {
                        if (!n.containsDuplicates()) {
                            LN ln = (LN) n;
                            LockGrantType lockRet =
                                lockingTxn.nonBlockingReadLock(ln.getNodeId(),
                     db);
                            if (lockRet == LockGrantType.DENIED) {
                                anyLocksDenied = true;
                                continue;
                            }

                            if (ln.isDeleted()) {
                                deleteEntry = true;
                            }
                        }
                    }

                    if (deleteEntry && n instanceof LN) {
                        obsoleteLsn = getLsn(i);
                    }

                    /* Remove key from BINReference in case we requeue it. */
                    if (binRef != null) {
                        binRef.removeDeletedKey(new Key(getKey(i)));
                    }
                }

                /* At this point, we know we can delete. */
                if (deleteEntry) {
                    Comparator userComparisonFcn = getKeyComparator();
                    boolean entryIsIdentifierKey =
                        (userComparisonFcn == null ?
                         Key.compareKeys(getKey(i), getIdentifierKey()) :
                         userComparisonFcn.compare
       (getKey(i), getIdentifierKey()))
                        == 0;
                    if (entryIsIdentifierKey) {

                        /*
                         * We're about to remove the entry with the idKey so
                         * the node will need a new idkey.
                         */
                        setNewIdKey = true;
                    }

                    boolean deleteSuccess = deleteEntry(i, true);
                    assert deleteSuccess;

                    /*
                     * Since we're deleting the current entry, bump the current
                     * index back down one.
                     */
                    i--;
                }
            }
        } finally {
            if (lockingTxn != null) {
                lockingTxn.operationEnd();
            }
        }

        if (anyLocksDenied && binRef != null) {
            db.getDbEnvironment().addToCompressorQueue(binRef, false);
            ret = true;
        }

        if (getNEntries() != 0 && setNewIdKey) {
            setIdentifierKey(getKey(0));
View Full Code Here

                      final DbState newState,
                      final OperationFailureException preemptedException)
        throws DatabaseException {

        StringBuffer 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 StringBuffer();
                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) {
                        handleLocker.setHandleLockOwner(true, this, true);
                        handleLocker.operationEnd(true);
                    } else {
                        handleLocker.operationEnd(false);
                    }
                }
            }
        }

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

        throws DatabaseException {

        /* Get the last full version of this BIN. */
        BIN fullBIN =
            (BIN) env.getLogManager().getEntryHandleFileNotFound(lastFullLsn);
        DatabaseImpl db = env.getDbTree().getDb(dbId);
        try {

            /*
             * In effect, call fullBIN.postFetchInit(db) here.  But we don't
             * want to do that since it will put fullBIN on the INList.  Since
View Full Code Here

TOP

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

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.