Examples of Bin


Examples of com.sleepycat.je.tree.BIN

     * @return true if an unaccounted for insertion happened.
     */
    private boolean checkForInsertion(final GetMode getMode,
                                      final CursorImpl origCursor,
                                      final CursorImpl dupCursor) {
        final BIN origBIN = origCursor.getBIN();
        final BIN dupBIN = dupCursor.getBIN();

        /* If fetchTarget returns null below, a deleted LN was cleaned. */

        boolean forward = getMode.isForward();
        boolean ret = false;
View Full Code Here

Examples of com.sleepycat.je.tree.BIN

         * 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();
View Full Code Here

Examples of com.sleepycat.je.tree.BIN

     */
    private static VLSN getVLSN(Cursor cursor, LogManager logManager)
        throws Exception {

        CursorImpl cursorImpl = DbInternal.getCursorImpl(cursor);
        BIN bin = cursorImpl.getBIN();
        int index = cursorImpl.getIndex();
        final long lsn = bin.getLsn(index);

        WholeEntry entry = logManager.getLogEntryAllowInvisible(lsn);

        VLSN vlsn = entry.getHeader().getVLSN();
        if (vlsn == null) {
View Full Code Here

Examples of com.sleepycat.je.tree.BIN

        boolean lockDenied = false;   // The LN lock was denied.
        boolean obsolete = false;     // The LN is no longer in use.
        boolean completed = false;    // This method completed.

        BasicLocker locker = null;
        BIN bin = null;
        try {
            nPendingLNsProcessed.increment();

            /*
             * If the DB is gone, this LN is obsolete.  If delete cleanup is in
             * progress, put the DB into the DB pending set; this LN will be
             * declared deleted after the delete cleanup is finished.
             */
            if (db == null || db.isDeleted()) {
                addPendingDB(db);
                nLNsDead.increment();
                obsolete = true;
                completed = true;
                return;
            }

            Tree tree = db.getTree();
            assert tree != null;

            /*
             * Get a non-blocking read lock on the original log LSN.  If this
             * fails, then the original LSN is still write-locked.  We may have
             * to lock again, if the LSN has changed in the BIN, but this
             * initial check prevents a Btree lookup in some cases.
             */
            locker = BasicLocker.createBasicLocker(env, false /*noWait*/);
            /* Don't allow this short-lived lock to be preempted/stolen. */
            locker.setPreemptable(false);
            LockResult lockRet =
                locker.nonBlockingLock(originalLsn, LockType.READ,
                                       false /*jumpAheadOfWaiters*/, db);
            if (lockRet.getLockGrant() == LockGrantType.DENIED) {
                /* Try again later. */
                nPendingLNsLocked.increment();
                lockDenied = true;
                completed = true;
                return;
            }

            /*
             * Search down to the bottom most level for the parent of this LN.
             */
            parentFound = tree.getParentBINForChildLN
                (location, key, false /*splitsAllowed*/,
                 true /*findDeletedEntries*/, UPDATE_GENERATION);
            bin = location.bin;
            int index = location.index;

            if (!parentFound) {
                nLNsDead.increment();
                obsolete = true;
                completed = true;
                return;
            }

            /* Migrate an LN. */
            processedHere = false;
            migrateLN
                (db, bin.getLsn(index), bin, index,
                 true,           // wasCleaned
                 true,           // isPending
                 originalLsn,
                 true,           // backgroundIO
                 CLEAN_PENDING_LN);
            completed = true;
        } catch (DatabaseException DBE) {
            DBE.printStackTrace();
            LoggerUtils.traceAndLogException
                (env, "com.sleepycat.je.cleaner.Cleaner",
                 "processLN", "Exception thrown: ", DBE);
            throw DBE;
        } finally {
            if (bin != null) {
                bin.releaseLatch();
            }

            if (locker != null) {
                locker.operationEnd();
            }
View Full Code Here

Examples of com.sleepycat.je.tree.BIN

         * is fetched)[#15704]
         */
        ChildReference newLNRef =
            new ChildReference(null, location.lnKey, logLsn);

        BIN parentBIN = location.bin;
        int entryIndex = parentBIN.insertEntry1(newLNRef);

        if ((entryIndex & IN.INSERT_SUCCESS) == 0) {

            /*
             * Insertion was not successful.
             */
            entryIndex &= ~IN.EXACT_MATCH;

            boolean canOverwrite = false;
            if (parentBIN.isEntryKnownDeleted(entryIndex)) {
                canOverwrite = true;
            } else {

                /*
                 * Read the LN that's in this slot to check for deleted
                 * status.  No need to lock, since this is recovery.  If
                 * fetchTarget returns null, a deleted LN was cleaned.
                 */
                LN currentLN = (LN) parentBIN.fetchTarget(entryIndex);

                if (currentLN == null || currentLN.isDeleted()) {
                    canOverwrite = true;
                }

                /*
                 * Evict the target again manually, to reduce memory
                 * consumption while the evictor is not running.
                 */
                parentBIN.updateNode(entryIndex, null /*node*/,
                                     null /*lnSlotKey*/);
            }

            if (canOverwrite) {

                /*
                 * Note that the LN must be left null to ensure the key in the
                 * BIN slot is transactionally correct (keys are updated if
                 * necessary when the LN is fetched).  [#15704]
                 */
                parentBIN.updateEntry(entryIndex, null, logLsn,
                                      location.lnKey);
                parentBIN.clearKnownDeleted(entryIndex);
                parentBIN.clearPendingDeleted(entryIndex);
                location.index = entryIndex;
                return true;
            }
            return false;
        }
View Full Code Here

Examples of com.sleepycat.je.tree.BIN

        DatabaseImpl db = env.getDbTree().getDb(dbId);

        /*
         * Search down to the bottom most level for the parent of this LN.
         */
        BIN bin = null;
        try {
            /*
             * The whole database is gone, so this LN is obsolete. No need
             * to worry about delete cleanup; this is just verification and
             * no cleaning is done.
             */
            if (db == null || db.isDeleted()) {
                return true;
            }

            entry.postFetchInit(db);

            Tree tree = db.getTree();
            TreeLocation location = new TreeLocation();
            boolean parentFound = tree.getParentBINForChildLN
                (location, entry.getKey(), false /*splitsAllowed*/,
                 true /*findDeletedEntries*/, CacheMode.UNCHANGED);
            bin = location.bin;
            int index = location.index;

            /* Is bin latched ? */
            if (!parentFound) {
                return true;
            }

            /*
             * Now we're at the BIN parent for this LN.  If knownDeleted, LN is
             * deleted and can be purged.
             */
            if (bin.isEntryKnownDeleted(index)) {
                return true;
            }

            if (bin.getLsn(index) != lsn) {
                return true;
            }

            /* Oh no -- this lsn is in the tree. */
            /* should print, or trace? */
            System.err.println("lsn " + DbLsn.getNoFormatString(lsn)+
                               " was found in tree.");
            return false;
        } finally {
            env.getDbTree().releaseDb(db);
            if (bin != null) {
                bin.releaseLatch();
            }
        }
    }
View Full Code Here

Examples of com.sleepycat.je.tree.BIN

        /* Status variables are used to generate debug tracing info. */
        boolean processedHere = true; // The LN was cleaned here.
        boolean obsolete = false;     // The LN is no longer in use.
        boolean completed = false;    // This method completed.

        BIN bin = null;
        try {
            Tree tree = db.getTree();
            assert tree != null;

            /* Find parent of this LN. */
            boolean parentFound = tree.getParentBINForChildLN
                (location, key, false /*splitsAllowed*/,
                 true /*findDeletedEntries*/, Cleaner.UPDATE_GENERATION);
            bin = location.bin;
            int index = location.index;

            if (!parentFound) {

                nLNsDeadThisRun++;
                obsolete = true;
                completed = true;
                return;
            }

            /*
             * Now we're at the BIN parent for this LN.  If knownDeleted, LN is
             * deleted and can be purged.
             */
            if (bin.isEntryKnownDeleted(index)) {
                nLNsDeadThisRun++;
                obsolete = true;
                completed = true;
                return;
            }

            /* Process this LN that was found in the tree. */
            processedHere = false;
            processFoundLN(info, logLsn, bin.getLsn(index), bin, index);
            completed = true;

            /*
             * For all other non-deleted LNs in this BIN, lookup their LSN
             * in the LN queue and process any matches.
             */
            for (int i = 0; i < bin.getNEntries(); i += 1) {
                long binLsn = bin.getLsn(i);
                if (i != index &&
                    !bin.isEntryKnownDeleted(i) &&
                    !bin.isEntryPendingDeleted(i) &&
                    DbLsn.getFileNumber(binLsn) == fileNum.longValue()) {

                    Long myOffset = Long.valueOf(DbLsn.getFileOffset(binLsn));
                    LNInfo myInfo = lookAheadCache.remove(myOffset);

                    /* If the offset is in the cache, it's a match. */
                    if (myInfo != null) {
                        nLNQueueHitsThisRun++;
                        nLNsCleanedThisRun++;
                        processFoundLN(myInfo, binLsn, binLsn, bin, i);
                    }
                }
            }
            return;

        } finally {
            if (bin != null) {
                bin.releaseLatch();
            }

            if (processedHere) {
                cleaner.logFine(Cleaner.CLEAN_LN, ln, logLsn,
                                completed, obsolete, false /*migrated*/);
 
View Full Code Here

Examples of com.sleepycat.je.tree.BIN

         * this), then fetch the delta, then reconstitute BIN using the inClone
         * if indeed it is a delta and its lastFullVersion is LTE the log LSN.
         * This avoids fetching a BIN that not need migration.
         */
        final byte[] searchKey = deltaClone.getSearchKey();
        final BIN treeBin = (BIN) db.getTree().search
            (searchKey, Tree.SearchType.NORMAL, null /*binBoundary*/,
             Cleaner.UPDATE_GENERATION, null /*searchComparator*/);

        if (treeBin == null) {
            /* BIN for this delta is no longer in the tree. */
            nBINDeltasDeadThisRun++;
            return;
        }

        /* Tree BIN is non-null and latched. */
        try {
            final long treeLsn = treeBin.getLastLoggedVersion();

            if (treeLsn == DbLsn.NULL_LSN) {
                /* Current version was never logged. */
                nBINDeltasDeadThisRun++;
                return;
            }

            final int cmp = DbLsn.compareTo(treeLsn, logLsn);

            if (cmp > 0) {
                /* Log entry is obsolete. */
                nBINDeltasDeadThisRun++;
                return;
            }

            /*
             * Log entry is same or newer than what's in the tree.  Dirty the
             * BIN and let the checkpoint write it out.  There is no need to
             * prohibit a delta when the BIN is next logged (as is done when
             * migrating full INs) because logging a new delta will obsolete
             * this delta.
             */
            treeBin.setDirty(true);
            nBINDeltasMigratedThisRun++;

        } finally {
            treeBin.releaseLatch();
        }
    }
View Full Code Here

Examples of com.sleepycat.je.tree.BIN

                    /* keysOnly => no dups, so BINs only, not DBINs. */
                    if (childType != LogEntryType.LOG_BIN) {
                        return;
                    }
                    BIN bin = (BIN) node;
                    for (int i = 0; i < bin.getNEntries(); i += 1) {

                        if (bin.isEntryPendingDeleted(i) ||
                            bin.isEntryKnownDeleted(i)) {
                            continue;
                        }

                        Node child = bin.getTarget(i);
                        if (child == null || child.isLN()) {
                            byte[] lnKey = bin.getKey(i);
                            try {
                                KeyAndData e = new KeyAndData(lnKey);
                                while (!queue.offer(e, offerTimeout,
                                                    TimeUnit.MILLISECONDS)) {

View Full Code Here

Examples of com.sleepycat.je.tree.BIN

        boolean lockDenied = false;// The LN lock was denied.
        boolean completed = false; // This method completed.

        long nodeId = ln.getNodeId();
        BasicLocker locker = null;
        BIN bin = null;
        DIN parentDIN = null;      // for DupCountLNs
        try {
            nLNsCleanedThisRun++;

            /* The whole database is gone, so this LN is obsolete. */
            if (db == null || db.getIsDeleted()) {
                nLNsDeadThisRun++;
                completed = true;
                return;
            }

            Tree tree = db.getTree();
            assert tree != null;

            /*
       * Search down to the bottom most level for the parent of this LN.
       */
            boolean parentFound = tree.getParentBINForChildLN
                (location, key, dupKey, ln,
                 false,  // splitsAllowed
                 true,   // findDeletedEntries
                 false,  // searchDupTree
                 false); // updateGeneration
            bin = location.bin;
            int index = location.index;

            if (!parentFound) {
                nLNsDeadThisRun++;
                completed = true;
    return;
            }

      /*
       * Now we're at the parent for this LN, whether BIN, DBIN or DIN.
       * If knownDeleted, LN is deleted and can be purged.
       */
      if (bin.isEntryKnownDeleted(index)) {
    nLNsDeadThisRun++;
    obsolete = true;
    completed = true;
                return;
      }

            /*
             * Determine whether the parent is the current BIN, or in the case
             * of a DupCountLN, a DIN.  Get the tree LSN in either case.
             */
            boolean lnIsDupCountLN = ln.containsDuplicates();
            long treeLsn;
      if (lnIsDupCountLN) {
    parentDIN = (DIN) bin.fetchTarget(index);
    parentDIN.latch(false);
                ChildReference dclRef = parentDIN.getDupCountLNRef();
                treeLsn = dclRef.getLsn();
      } else {
                treeLsn = bin.getLsn(index);
      }

      /*
             * Check to see whether the LN being migrated is locked elsewhere.
             * Do that by attempting to lock it.  We can hold the latch on the
             * BIN (and DIN) since we always attempt to acquire a non-blocking
             * read lock.  Holding the latch ensures that the INs won't change
             * underneath us because of splits or eviction.
       */
      locker = new BasicLocker(env);
      LockGrantType lock = locker.nonBlockingReadLock(nodeId, db);
      if (lock == LockGrantType.DENIED) {

    /*
     * LN is currently locked by another Locker, so we can't assume
      * anything about the value of the LSN in the bin.  However,
                 * we can check whether the lock owner's abort LSN is greater
                 * than the log LSN; if so, the log LSN is obsolete.  Before
                 * doing this we must release all latches to avoid a deadlock.
     */
                if (parentDIN != null) {
                    parentDIN.releaseLatch();
                    parentDIN = null;
                }
                bin.releaseLatch();
    long abortLsn = locker.getOwnerAbortLsn(nodeId);
    if (abortLsn != DbLsn.NULL_LSN &&
        DbLsn.compareTo(abortLsn, logLsn) > 0) {
        nLNsDeadThisRun++;
        obsolete = true;
    } else {
        nLNsLockedThisRun++;
                    lockDenied = true;
    }
                completed = true;
                return;
      }

      /*
       * We were able to lock this LN in the tree.  Try to migrate this
       * LN to the end of the log file so we can throw away the old log
       * entry.
             *
             * 1. If the LSN in the tree and in the log are the same,
             * we can migrate it, or discard it if the LN is deleted.
             *
             * 2. If the LSN in the tree is < the LSN in the log, the
             * log entry is obsolete, because this LN has been rolled
             * back to a previous version by a txn that aborted.
             *
             * 3. If the LSN in the tree is > the LSN in the log, the
             * log entry is obsolete, because the LN was advanced
             * forward by some now-committed txn.
             */
            if (treeLsn == logLsn) {
                if (ln.isDeleted()) {

                    /*
                     * If the LN is deleted, we must set knownDeleted to
                     * prevent fetching it later.  This could occur when
                     * scanning over deleted entries that have not been
                     * compressed away [10553].
                     */
                    assert !lnIsDupCountLN;
                    bin.setKnownDeletedLeaveTarget(index);
                    nLNsDeadThisRun++;
                    obsolete = true;
                } else {
                    if (lnIsDupCountLN) {

                        /*
                         * Migrate the DupCountLN now to avoid having to
                         * process the migrate flag for DupCountLNs in all
                         * other places.
                         */
                        long newLNLsn = ln.log
                            (env, db.getId(), key, logLsn, locker);

                        parentDIN.updateDupCountLNRef(newLNLsn);
                        nLNsMigratedThisRun++;
                    } else {

                        /*
                         * Set the migrate flag and dirty the BIN.  The evictor
                         * or checkpointer will migrate the LN later.
                         */
                        bin.setMigrate(index, true);

                        /*
                         * Update the generation so that the BIN is not evicted
                         * immediately.  This allows the cleaner to fill in as
                         * many entries as possible before eviction, as
                         * to-be-cleaned files are processed.
                         */
                        bin.setGeneration();

                        /*
                         * Set the target node so it does not have to be
                         * fetched when it is migrated. Must call postFetchInit
                         * to initialize MapLNs that have not been fully
       * initialized yet [#13191].
                         */
                        if (bin.getTarget(index) == null) {
           ln.postFetchInit(db, logLsn);
                            bin.updateEntry(index, ln);
                        }

                        nLNsMarkedThisRun++;
                    }
                    migrated = true;
                }
            } else {
                /* LN is obsolete and can be purged. */
                nLNsDeadThisRun++;
                obsolete = true;
            }
            completed = true;
            return;
        } finally {
            if (parentDIN != null) {
                parentDIN.releaseLatchIfOwner();
            }

            if (bin != null) {
                bin.releaseLatchIfOwner();
            }

            if (locker != null) {
                locker.operationEnd();
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.