Package com.sleepycat.je.tree

Examples of com.sleepycat.je.tree.IN


            while ((evictBytes < maxEvictBytes) &&
                   (numNodesScannedThisBatch <= maxINsPerBatch) &&
                   arbiter.stillNeedsEviction()) {
               
                ScanInfo scanInfo = selector.selectIN(maxINsPerBatch);
                IN target = scanInfo.target;
                numNodesScannedThisBatch += scanInfo.numNodesScanned;

                if (target == null) {
                    break;
                }

                numBatchTargets[source.ordinal()].incrementAndGet();

                assert TestHookExecute.doHookIfSet(evictProfile, target);

                /*
                 * 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
View Full Code Here


            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;
            }
        }
View Full Code Here

            /*
             * Get a new reference to the child, in case the reference
             * saved in the selection list became out of date because of
             * changes to that parent.
             */
            IN renewedChild = (IN) parent.getTarget(index);

            if (renewedChild == null) {
                return evictBytes;
            }
           
            boolean inline = (source == EvictionSource.CACHEMODE);
            if (!inline && renewedChild.getGeneration() > oldGenerationCount) {
                return evictBytes;
            }

            /*
             * See the evictIN() method in this class for an explanation for
             * calling latchNoWait().
             */
            if (inline) {
                renewedChild.latch(CacheMode.UNCHANGED);
            } else {
                if (!renewedChild.latchNoWait(CacheMode.UNCHANGED)) {
                    return evictBytes;
                }
            }
            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.
                 */
                long renewedChildLsn = DbLsn.NULL_LSN;
                boolean newChildLsn = false;
                if (renewedChild.getDirty()) {
                    if (!useEnvImpl.isReadOnly()) {
                        boolean logProvisional =
                            coordinateWithCheckpoint(renewedChild, parent);

                        /*
                         * Log a full version (no deltas) and with cleaner
                         * migration allowed.  Allow compression of deleted
                         * slots in full version BINs.
                         */
                        renewedChildLsn = renewedChild.log
                            (useEnvImpl.getLogManager(),
                             allowBinDeltas,
                             true /*allowCompress*/,
                             logProvisional,
                             backgroundIO,
                             parent);
                        newChildLsn = true;
                    }
                } else {
                    renewedChildLsn = parent.getLsn(index);
                }

                if (renewedChildLsn != DbLsn.NULL_LSN) {
                    /* Take this off the inlist. */
                    useEnvImpl.getInMemoryINs().remove(renewedChild);

                    evictBytes = renewedChild.getBudgetedMemorySize();
                    if (newChildLsn) {

                        /*
                         * Update the parent so its reference is
                         * null and it has the proper LSN.
                         */
                        parent.updateNode
                            (index, null /*node*/, renewedChildLsn,
                             null /*lnSlotKey*/);
                    } else {

                        /*
                         * Null out the reference, but don't dirty
                         * the node since only the reference
                         * changed.
                         */
                        parent.updateNode
                            (index, (Node) null /*node*/,
                             null /*lnSlotKey*/);
                    }

                    /* Stats */
                    nNodesEvicted.increment();
                    renewedChild.incEvictStats(source);
                }
            } finally {
                renewedChild.releaseLatch();
            }
        } finally {
            parent.releaseLatch();
        }

View Full Code Here

        }

        public IN doWork(ChildReference root)
            throws DatabaseException {

            IN rootIN = (IN) root.fetchTarget(db, null);
            rootLevel = rootIN.getLevel();
            return null;
        }
View Full Code Here

                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
View Full Code Here

    public boolean positionFirstOrLast(boolean first)
        throws DatabaseException {

        assert assertCursorState(false) : dumpToString(true);

        IN in = null;
        boolean found = false;
        try {
            removeCursor();
            if (first) {
                in = databaseImpl.getTree().getFirstNode(cacheMode);
            } else {
                in = databaseImpl.getTree().getLastNode(cacheMode);
            }

            if (in != null) {

                assert (in instanceof BIN);

                bin = (BIN) in;
                index = (first ? 0 : (bin.getNEntries() - 1));
                addCursor(bin);

                TreeWalkerStatsAccumulator treeStatsAccumulator =
                    getTreeStatsAccumulator();

                if (bin.getNEntries() == 0) {

                    /*
                     * An IN was found. Even if it's empty, let Cursor
                     * handle moving to the first non-deleted entry.
                     */
                    found = true;
                } else {

                    if (treeStatsAccumulator != null &&
                        !bin.isEntryKnownDeleted(index) &&
                        !bin.isEntryPendingDeleted(index)) {
                        treeStatsAccumulator.incrementLNCount();
                    }

                    /*
                     * Even if the entry is deleted, just leave our
                     * position here and return.
                     */
                    found = true;
                }
            }
            setInitialized();
            return found;
        } catch (DatabaseException e) {
            /* Release latch on error. */
            if (in != null) {
                in.releaseLatch();
            }
            throw e;
        }
    }
View Full Code Here

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

     * children.
     */
    private void processRootLSN(DatabaseImpl dbImpl,
                                LSNAccumulator pendingLSNs,
                                long rootLsn) {
        IN root = getOrFetchRootIN(dbImpl, rootLsn);
        if (root != null) {
            try {
                accumulateLSNs(root, pendingLSNs);
            } finally {
                releaseRootIN(root);
View Full Code Here

            (lsn, (!nodeInCache ?
                   LogEntryType.LOG_INS_LN /* Any LN type will do */ :
                   node.getGenericLogType()),
             node, lnKey);
        if (nodeInCache && node.isIN()) {
            IN nodeAsIN = (IN) node;
            try {
                nodeAsIN.latch(CacheMode.UNCHANGED);
                accumulateLSNs(nodeAsIN, pendingLSNs);
            } finally {
                nodeAsIN.releaseLatch();
            }
        }
    }
View Full Code Here

        Node node = fetchLSNHandleExceptions(lsn, lnKeyEntry, pendingLSNs);
        if (node == null) {
            return;
        }
        boolean isIN = (node instanceof IN);
        IN in = null;
        try {
            if (isIN) {
                in = (IN) node;
                in.latch(CacheMode.UNCHANGED);
            }
            callProcessLSNHandleExceptions
                (lsn, node.getGenericLogType(), node, lnKeyEntry.getData());

            if (isIN) {
                accumulateLSNs(in, pendingLSNs);
            }
        } finally {
            if (isIN) {
                in.releaseLatch();
            }
        }
    }
View Full Code Here

TOP

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

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.