Package com.sleepycat.je.tree

Examples of com.sleepycat.je.tree.Tree


                          BINReference binRef,
                          byte[] idKey,
                          LocalUtilizationTracker localTracker) {

        try {
            Tree tree = dbImpl.getTree();
            tree.delete(idKey, localTracker);
            processedBinsThisRun++;
        } catch (NodeNotEmptyException NNEE) {

            /*
             * Something was added to the node since the point when the
View Full Code Here


                                getNextLocalDbId());

            DatabaseImpl newDb = oldDb.cloneDatabase();
            newDb.incrementUseCount();
            newDb.setId(newId);
            newDb.setTree(new Tree(newDb));

            /*
             * Insert the new MapLN into the id tree. Do not use a transaction
             * on the id database, because we can not hold long term locks on
             * the mapLN.
View Full Code Here

                              long maxCount,
                              RangeConstraint rangeConstraint,
                              CursorImpl finalPositionCursor) {

        /* Start with the entry at the cursor position. */
        final Tree tree = databaseImpl.getTree();
        BIN curBin = latchBIN();
        int prevIndex = getIndex();
        long count = 0;

        try {
            while (true) {
                /* Skip entries in the current BIN. */
                count = skipEntries
                    (forward, maxCount, rangeConstraint, finalPositionCursor,
                     curBin, prevIndex, count);
                if (count < 0) {
                    return (- count);
                }

                /*
                 * Get the parent IN at level two.  The BIN is unlatched by
                 * getParentINForChildIN.  Before releasing the BIN latch, get
                 * the search key for the last entry.
                 */
                final byte[] idKey = (curBin.getNEntries() == 0) ?
                    curBin.getIdentifierKey() :
                    (forward ?
                     curBin.getKey(curBin.getNEntries() - 1) :
                     curBin.getKey(0));
                final BIN binToFind = curBin;
                curBin = null; // BIN latch will be released.

                final SearchResult result = tree.getParentINForChildIN
                    (binToFind, true /*requireExactMatch*/,
                     CacheMode.UNCHANGED);

                final IN parent = result.parent;
                boolean fetchOrWait = false;

                try {
                    if (!result.exactParentFound) {
                        throw EnvironmentFailureException.unexpectedState
                            ("Cannot get parent of BIN id=" +
                             binToFind.getNodeId() + " key=" +
                             Arrays.toString(idKey));
                    }

                    /*
                     * Find previous child BIN by matching idKey rather than
                     * using result.index, as in getNextBinInternal (see
                     * comments there).
                     */
                    int parentIndex = parent.findEntry(idKey, false, false);
                    if (forward ?
                        (parentIndex == parent.getNEntries() - 1) :
                        (parentIndex == 0)) {

                        /*
                         * This is the last entry in the parent.  Fetch and
                         * latch it, in preparation for getNextBin below.
                         */
                        curBin = (BIN) parent.fetchTargetWithExclusiveLatch
                            (parentIndex);
                        curBin.latch();
                    } else {

                        /*
                         * Skip entries for child BINs that are resident and
                         * can be latched no-wait.
                         */
                        final int incr = forward ? 1 : (-1);
                        for (parentIndex += incr;; parentIndex += incr) {
                            if (fetchOrWait ||
                                (forward ?
                                 (parentIndex >= parent.getNEntries()) :
                                 (parentIndex < 0))) {
                                break;
                            }
                            /* Release previous child BIN. */
                            if (curBin != null) {
                                curBin.releaseLatch();
                                curBin = null;
                            }
                            /* Fetch and latch next child BIN. */
                            curBin = (BIN) parent.getTarget(parentIndex);
                            if (curBin == null) {
                                fetchOrWait = true;
                                curBin =
                                    (BIN) parent.fetchTargetWithExclusiveLatch
                                    (parentIndex);
                            }
                            if (!curBin.latchNoWait(CacheMode.UNCHANGED)) {
                                fetchOrWait = true;
                                curBin.latch();
                            }
                            /* Position at new BIN to prevent compression. */
                            setPosition(curBin, -1);
                            /* Skip entries in new child BIN. */
                            count = skipEntries
                                (forward, maxCount, rangeConstraint,
                                 finalPositionCursor, curBin,
                                 forward ? (-1) : curBin.getNEntries(), count);
                            if (count < 0) {
                                return (- count);
                            }
                        }
                    }
                } finally {
                    if (parent != null) {
                        parent.releaseLatch();
                    }
                }

                /*
                 * Continue after releasing the parent latch.  The current BIN
                 * is still latched.
                 */
                if (fetchOrWait) {

                    /*
                     * A child BIN was not resident or we could not get a
                     * no-wait latch.  Skip over the current BIN, which has
                     * already been processed, and continue the loop within the
                     * same parent IN.
                     */
                    prevIndex = forward ? (curBin.getNEntries() - 1) : 0;
                } else {

                    /*
                     * There are no more entries in the parent IN.  Move to the
                     * next BIN, which will be in the next parent IN, and
                     * continue at the beginning of that BIN.
                     */
                    curBin = forward ?
                        tree.getNextBin(curBin, CacheMode.UNCHANGED) :
                        tree.getPrevBin(curBin, CacheMode.UNCHANGED);

                    if (curBin == null) {
                        return count;
                    }
                    prevIndex = forward ? (-1) : curBin.getNEntries();
View Full Code Here

        /* Call test hook when we reach the max level. */
        assert (currentLevel < maxFlushLevel) ||
            TestHookExecute.doHookIfSet(maxFlushLevelHook);

        Tree tree = db.getTree();
        boolean targetWasRoot = false;
        if (targetRef.isDbRoot) {

            /* We're trying to flush the root. */
            RootFlusher flusher =
                new RootFlusher(db, logManager, targetRef.nodeId);
            tree.withRootLatchedExclusive(flusher);
            boolean flushed = flusher.getFlushed();

            /*
             * If this target isn't the root anymore, we'll have to handle it
             * like a regular node.
             */
            targetWasRoot = flusher.stillRoot();

            /*
             * Update the tree's owner, whether it's the env root or the
             * dbmapping tree.
             */
            if (flushed) {
                DbTree dbTree = envImpl.getDbTree();
                dbTree.modifyDbRoot(db);
                fstats.nFullINFlushThisRun++;
                fstats.nFullINFlush++;
            }
        }

        /*
         * The following attempt to flush applies to two cases:
         *
         * (1) the target was not ever the root
         *
         * (2) the target was the root, when the checkpoint dirty set was
         * assembled but is not the root now.
         */
        if (!targetWasRoot) {

            /*
             * The "isRoot" param is used to stop a search in
             * BIN.descendOnParentSearch and is passed as false (never stop).
             */
            SearchResult result =
                tree.getParentINForChildIN(targetRef.nodeId,
                                           false,  // isRoot
                                           targetRef.treeKey,
                                           false,  // requireExactMatch
                                           CacheMode.UNCHANGED,
                                           -1,     // targetLevel
View Full Code 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;

View Full Code Here

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

        BasicLocker locker = null;
        try {
            Tree tree = db.getTree();
            assert tree != null;

            /*
             * If the tree and log LSNs are equal, then we can be fairly
             * certain that the log entry is current; in that case, it is
View Full Code Here

        boolean completed = false;

        try {
            nINsCleanedThisRun++;

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

            IN inInTree = findINInTree(tree, db, inClone, logLsn);

            if (inInTree == null) {
View Full Code Here

                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;

View Full Code Here

     */
    private void replaceOrInsertRoot(DatabaseImpl db, IN inFromLog, long lsn)
        throws DatabaseException {

        boolean success = true;
        Tree tree = db.getTree();
        RootUpdater rootUpdater = new RootUpdater(tree, inFromLog, lsn);
        try {
            /* Run the root updater while the root latch is held. */
            tree.withRootLatchedExclusive(rootUpdater);

            /* Update the mapLN if necessary */
            if (rootUpdater.updateDone()) {

                /*
 
View Full Code Here

                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;

View Full Code Here

TOP

Related Classes of com.sleepycat.je.tree.Tree

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.