Package com.sleepycat.je.tree

Examples of com.sleepycat.je.tree.IN


                public void testBody() {

                    try {
                        /* Create two initial elements. */
                        for (int i = 0; i < 2; i++) {
                            IN in = new IN(dbImpl, null, 1, 1);
                            inList1.add(in);
                        }

                        /*
                         * Acquire the major latch in preparation for an
                         * iteration.
                         */
                        inList1.latchMajor();

                        /* Wait for tester2 to try to acquire the
                           /* minor latch */
                        sequencer = 1;
                        while (sequencer <= 1) {
                            Thread.yield();
                        }

                        /*
                         * Sequencer is now 2. There should only be
                         * two elements in the list right now even
                         * though thread 2 added a third one.
                         */
                        int count = 0;
                        Iterator iter = inList1.iterator();
                        while (iter.hasNext()) {
                            IN in = (IN) iter.next();
                            count++;
                        }

                        assertEquals(2, count);

                        /*
                         * Allow thread2 to run again.  It will
                         * add another element and throw control
                         * back to thread 1.
                         */
                        sequencer++;   // now it's 3
                        while (sequencer <= 3) {
                            Thread.yield();
                        }

                        /*
                         * Thread2 has exited.  Release the major
                         * latch so that the addedINs can be added
                         * into the main in set.
                         */
                        inList1.releaseMajorLatch();

                        /*
                         * Check that the entry added by tester2 was really
                         * added.
                         */
                        inList1.latchMajor();
                        count = 0;
                        iter = inList1.iterator();
                        while (iter.hasNext()) {
                            IN in = (IN) iter.next();
                            count++;
                        }

                        assertEquals(4, count);
                        inList1.releaseMajorLatch();
                    } catch (Throwable T) {
                        T.printStackTrace(System.out);
                        fail("Thread 1 caught some Throwable: " + T);
                    }
                }
            };

        JUnitThread tester2 =
            new JUnitThread("testMajorMinorLatching-Thread2") {
                public void testBody() {

                    try {
                        /* Wait for tester1 to start */
                        while (sequencer < 1) {
                            Thread.yield();
                        }

                        assertEquals(1, sequencer);

                        /*
                         * Acquire the minor latch in preparation for some
                         * concurrent additions.
                         */
                        inList1.add(new IN(dbImpl, null, 1, 1));
                        sequencer++;

                        /* Sequencer is now 2. */

                        while (sequencer < 3) {
                            Thread.yield();
                        }

                        assertEquals(3, sequencer);
                        /* Add one more element. */
                        inList1.add(new IN(dbImpl, null, 1, 1));
                        sequencer++;
                    } catch (Throwable T) {
                        T.printStackTrace(System.out);
                        fail("Thread 2 caught some Throwable: " + T);
                    }
View Full Code Here


        throws Exception {

        Set expectedNodes = new HashSet();

        /* Create 3 initial elements. */
        IN startIN = null;
        for (int i = 0; i < 3; i++) {
            startIN = new IN(dbImpl, null, 1, 1);
            inList1.add(startIN);
            expectedNodes.add(startIN);
        }

        inList1.latchMajor();
        try {
            /* Get an iterator ready */
            Iterator iter = inList1.iterator();

            /* Add two more nodes; they should go onto the minor list. */
            IN inA = new IN(dbImpl, null, 1, 1);
            inList1.add(inA);
            IN inB = new IN(dbImpl, null, 1, 1);
            inList1.add(inB);

            /* We should see the original 3 items. */
            checkContents(expectedNodes);

View Full Code Here

        throws Exception {

        Set seen = new HashSet();
        Iterator iter = inList1.iterator();
        while (iter.hasNext()) {
            IN foo = (IN)iter.next();
            assertTrue(expectedNodes.contains(foo));
            assertTrue(!seen.contains(foo));
            seen.add(foo);
        }
        assertEquals(expectedNodes.size(), seen.size());
View Full Code Here

        inList.latchMajor();
        long total = 0;
        try {
            Iterator iter = inList.iterator();
            while (iter.hasNext()) {
                IN in = (IN) iter.next();
                in.latch();
                try {
                    assert in.verifyMemorySize():
                        "in nodeId=" + in.getNodeId() +
                        ' ' + in.getClass().getName();
                    total += in.getInMemorySize();
                } finally {
                    in.releaseLatch();
                }
            }
        } finally {
            inList.releaseMajorLatch();
        }
View Full Code Here

        bin.latch();
        SearchResult result = tree.getParentINForChildIN(bin, true, true);
        assert result.parent != null;
        result.parent.releaseLatch();
        assert result.exactParentFound;
        IN in = result.parent;
        long binLsn = logIN(env, bin, true, in);
        in.updateEntry(result.index, bin, binLsn);
        long inLsn = logIN(env, in, false, null);
    }
View Full Code Here

    private BIN searchForBIN(DatabaseImpl db, byte[] mainKey, byte[] dupKey)
        throws DatabaseException {

        /* Search for this IN */
        Tree tree = db.getTree();
        IN in = tree.search
            (mainKey, SearchType.NORMAL, -1, null, false /*updateGeneration*/);

        /* Couldn't find a bin, return null */
        if (in == null) {
            return null;
View Full Code Here

    public boolean positionFirstOrLast(boolean first, DIN duplicateRoot)
        throws DatabaseException {

        assert assertCursorState(false) : dumpToString(true);

        IN in = null;
        boolean found = false;
        try {
            if (duplicateRoot == null) {
                removeCursorBIN();
                if (first) {
                    in = database.getTree().getFirstNode();
                } else {
                    in = database.getTree().getLastNode();
                }

                if (in != null) {

                    assert (in instanceof BIN);

                    dupBin = null;
                    dupIndex = -1;
                    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 {

                        /*
                         * See if we need to descend further.  If fetchTarget
                         * returns null, a deleted LN was cleaned.
                         */
                        Node n = null;
                        if (!in.isEntryKnownDeleted(index)) {
                            n = in.fetchTarget(index);
                        }

                        if (n != null && n.containsDuplicates()) {
                            DIN dupRoot = (DIN) n;
                            dupRoot.latch();
                            in.releaseLatch();
                            in = null;
                            found = positionFirstOrLast(first, dupRoot);
                        } else {

                            /*
                             * Even if the entry is deleted, just leave our
                             * position here and return.
                             */
                            if (treeStatsAccumulator != null) {
                                if (n == null || ((LN) n).isDeleted()) {
                                    treeStatsAccumulator.
                                        incrementDeletedLNCount();
                                } else {
                                    treeStatsAccumulator.
                                        incrementLNCount();
                                }
                            }
                            found = true;
                        }
                    }
                }
            } else {
                removeCursorDBIN();
                if (first) {
                    in = database.getTree().getFirstNode(duplicateRoot);
                } else {
                    in = database.getTree().getLastNode(duplicateRoot);
                }

                if (in != null) {

        /*
         * An IN was found. Even if it's empty, let Cursor handle
         * moving to the first non-deleted entry.
         */
        assert (in instanceof DBIN);

        dupBin = (DBIN) in;
                    dupIndex = (first ? 0 : (dupBin.getNEntries() - 1));
        addCursor(dupBin);
        found = true;
                }
            }
            status = CURSOR_INITIALIZED;
            return found;
        } catch (DatabaseException e) {
            /* Release latch on error. */
            if (in != null) {
                in.releaseLatch();
            }
            throw e;
        }
    }
View Full Code Here

        inList.latchMajor();
        try {
            Iterator iter = inList.iterator();
            while (iter.hasNext()) {
                IN in = (IN) iter.next();
                long size = in.getInMemorySize();
                totalSize += size;
            }
        } finally {
            inList.releaseMajorLatch();
        }
View Full Code Here

            (EnvironmentParams.EVICTOR_LRU_ONLY);

        INList inList = envImpl.getInMemoryINs();
        inList.latchMajor();

        IN nextNode = evictor.getNextNode();
        if (nextNode == null) {
            nextNode = (IN) inList.first();
        }
        Iterator inIter = inList.tailSet(nextNode).iterator();

        long targetGeneration = Long.MAX_VALUE;
        int targetLevel = Integer.MAX_VALUE;
        boolean targetDirty = true;
        IN target = null;
       
        boolean wrapped = false;
        int nScanned = 0;
        int nCandidates = 0;
        while (nCandidates < scanSize) {

            if (!inIter.hasNext()) {
                if (wrapped) {
                    break;
                } else {
                    inIter = inList.tailSet(inList.first()).iterator();
                    wrapped = true;
                }
            }

            IN in = (IN) inIter.next();
            nScanned += 1;

            if (in.getDatabase() == null || in.getDatabase().getIsDeleted()) {
                continue;
            }

            if (in.getDatabase().getId().equals(DbTree.ID_DB_ID)) {
                continue;
            }

            int evictType = in.getEvictionType();
            if (evictType == IN.MAY_NOT_EVICT) {
                continue;
            }

            if (evictByLruOnly) {
                if (in.getGeneration() < targetGeneration) {
                    targetGeneration = in.getGeneration();
                    target = in;
                }
            } else {
                int level = evictor.normalizeLevel(in, evictType);
                if (targetLevel != level) {
                    if (targetLevel > level) {
                        targetLevel = level;
                        targetDirty = in.getDirty();
                        targetGeneration = in.getGeneration();
                        target = in;
                    }
                } else if (targetDirty != in.getDirty()) {
                    if (targetDirty) {
                        targetDirty = false;
                        targetGeneration = in.getGeneration();
                        target = in;
                    }
                } else {
                    if (targetGeneration > in.getGeneration()) {
                        targetGeneration = in.getGeneration();
                        target = in;
                    }
                }
            }
View Full Code Here

        INList inList = DbInternal.envGetEnvironmentImpl(env).getInMemoryINs();
        inList.latchMajor();
        try {
            Iterator iter = inList.iterator();
            while (iter.hasNext()) {
                IN in = (IN) iter.next();
                if (in instanceof BIN) {
                    in.compress(null, true);
                }
            }
        } finally {
            inList.releaseMajorLatch();
        }
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.