Examples of DIN


Examples of com.sleepycat.je.tree.DIN

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

Examples of com.sleepycat.je.tree.DIN

         * If wasCleaned is false we don't count statistics unless we migrate
         * the LN.  This avoids double counting.
         */
        BasicLocker locker = null;
        LN ln = null;
        DIN parentDIN = null;      // for DupCountLNs

        try {

            /*
             * Fetch the node, if necessary.  If it was not resident and it is
             * an evictable LN, we will clear it after we migrate it.
             */
      Node node = null;
      if (!bin.isEntryKnownDeleted(index)) {
                node = bin.getTarget(index);
                if (node == null) {
                    /* If fetchTarget returns null, a deleted LN was cleaned.*/
                    node = bin.fetchTarget(index);
                    clearTarget = node instanceof LN &&
                        !db.getId().equals(DbTree.ID_DB_ID);
                }
            }

      /* Don't migrate knownDeleted or deleted cleaned LNs.  */
            if (node == null) {
                if (wasCleaned) {
                    nLNsDead++;
                }
                obsolete = true;
                completed = true;
                return;
      }

            /* Determine whether this is a DupCountLN or a regular LN. */
            boolean lnIsDupCountLN = node.containsDuplicates();
      if (lnIsDupCountLN) {
    parentDIN = (DIN) node;
    parentDIN.latch(false);
                ChildReference dclRef = parentDIN.getDupCountLNRef();
                lsn = dclRef.getLsn();
                ln = (LN) dclRef.fetchTarget(db, parentDIN);
            } else {
                ln = (LN) node;
            }

            /*
             * Get a non-blocking read lock on the LN.  A pending node is
             * already locked, but that node ID may be different than the
             * current LN's node if a slot is reused.  We must lock the current
             * node to guard against aborts.
             */
            if (lockedPendingNodeId != ln.getNodeId()) {
                locker = new BasicLocker(env);
                LockGrantType lock = locker.nonBlockingReadLock
                    (ln.getNodeId(), 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.
                     */
                    if (wasCleaned) {
                        nLNsLocked++;
                    }
                    lockDenied = true;
                    completed = true;
                    return;
                }
            }

      /* Don't migrate deleted LNs.  */
            if (ln.isDeleted()) {
                assert !lnIsDupCountLN;
                bin.setKnownDeletedLeaveTarget(index);
                if (wasCleaned) {
                    nLNsDead++;
                }
                obsolete = true;
                completed = true;
                return;
            }

            /*
             * Once we have a lock, check whether the current LSN needs to be
             * migrated.  There is no need to migrate it if the LSN no longer
             * qualifies for cleaning.  Although redundant with
             * isFileCleaningInProgress, check toBeCleanedFiles first because
             * it is unsynchronized.
             */
            Long fileNum = new Long(DbLsn.getFileNumber(lsn));
            if (!toBeCleanedFiles.contains(fileNum) &&
                !fileSelector.isFileCleaningInProgress(fileNum)) {
                completed = true;
                if (wasCleaned) {
                    nLNsDead++;
                }
                return;
            }

            /* Migrate the LN. */
            byte[] key = getLNMainKey(bin, index);
            long newLNLsn = ln.log(env, db.getId(), key, lsn, locker);
      if (lnIsDupCountLN) {
                parentDIN.updateDupCountLNRef(newLNLsn);
            } else {
                bin.updateEntry(index, newLNLsn);
            }
            nLNsMigrated++;
            migrated = true;
            completed = true;
            return;
        } finally {
            if (parentDIN != null) {
                parentDIN.releaseLatchIfOwner();
            }

            if (isPending) {
                if (completed && !lockDenied) {
                    fileSelector.removePendingLN(lockedPendingNodeId);
View Full Code Here

Examples of com.sleepycat.je.tree.DIN

            bin.releaseLatch();

            /*
             * DINs
             */
            DIN din = new DIN(database,
                              new byte[] {1,0,0,1},
                              7,
                              new byte[] {0,1,1,0},
                              new ChildReference(null,
                                                 new byte[] {1,0,0,1},
                                                 DbLsn.makeLsn(10, 100)),
                              5);
            din.insertEntry(new ChildReference(null,
                                               new byte[] {1,0,1,0},
                                               DbLsn.makeLsn(12, 200)));
            din.insertEntry(new ChildReference(null,
                                               new byte[] {1,1,1,0},
                                               DbLsn.makeLsn(29, 300)));
            din.insertEntry(new ChildReference(null,
                                               new byte[] {0,0,1,0},
                                               DbLsn.makeLsn(35, 400)));

            /* Write it. */
            DIN dinFromLog = new DIN();
            writeAndRead(buffer, din, dinFromLog);

            /*
             * DBINs
             */
 
View Full Code Here

Examples of com.sleepycat.je.tree.DIN

        /*
         * This is a dupCountLN. It's ok if there's no DIN parent
         * for it. [#11307].
         */
        DIN duplicateRoot = (DIN)
      location.bin.fetchTarget(location.index);
        if (DbLsn.compareTo(logLsn, location.childLsn) >= 0) {
      /* DupCountLN needs replacing. */
      duplicateRoot.updateDupCountLNRefAndNullTarget(logLsn);
        }
                }
            } else {
                if (found) {

View Full Code Here

Examples of com.sleepycat.je.tree.DIN

                /*
     * This is a dupCountLN. It's ok if there's no DIN parent
     * for it. [#11307].
     */
                if (found) {
        DIN duplicateRoot = (DIN)
      location.bin.fetchTarget(location.index);
        if (DbLsn.compareTo(logLsn, location.childLsn) == 0) {
      /* DupCountLN needs replacing. */
      duplicateRoot.
          updateDupCountLNRefAndNullTarget(abortLsn);
      replaced = true;
        }
    }
            } else {
View Full Code Here

Examples of com.sleepycat.je.tree.DIN

      BIN bin = null;
      try {
    bin = (BIN) DbInternal.dbGetDatabaseImpl(exampleDb)
        .getTree()
        .getFirstNode();
    DIN dupRoot = (DIN) bin.fetchTarget(0);
    bin.releaseLatch();
    bin = null;
    dupRoot.latch();
    bin = (BIN) DbInternal.dbGetDatabaseImpl(exampleDb)
        .getTree()
        .getFirstNode(dupRoot);
    bin.compress(null, true);
    bin.releaseLatch();
View Full Code Here

Examples of com.sleepycat.je.tree.DIN

            -1,
                                                null,
                                                true);
  assertNotNull(bin);
  int idx = bin.findEntry("cfhaa".getBytes(), false, true);
  DIN din = (DIN) bin.getTarget(idx);
  assertNotNull(din);
  idx = din.findEntry("yrhwlvlgvq".getBytes(), false, true);
  DBIN dbin = (DBIN) din.getTarget(idx);
  Key.DUMP_BINARY = false;
  dbin.log(envImpl.getLogManager());
  din.log(envImpl.getLogManager());
  bin.releaseLatch();
  env.compress();
  bin.log(envImpl.getLogManager());
    }
View Full Code Here

Examples of com.sleepycat.je.tree.DIN

        if (dupKey == null) {
            return (BIN) in;
        }

        /* We need to descend down into a duplicate tree. */
        DIN duplicateRoot = null;
        DBIN duplicateBin = null;
        BIN bin = (BIN) in;
        try {
            int index = bin.findEntry(mainKey, false, true);
            if (index >= 0) {
                Node node = null;
    if (!bin.isEntryKnownDeleted(index)) {
                    /* If fetchTarget returns null, a deleted LN was cleaned. */
                    node = bin.fetchTarget(index);
                }
                if (node == null) {
        bin.releaseLatch();
        return null;
    }
                if (node.containsDuplicates()) {
                    /* It's a duplicate tree. */
                    duplicateRoot = (DIN) node;
                    duplicateRoot.latch();
                    bin.releaseLatch();
                    duplicateBin = (DBIN) tree.searchSubTree
                        (duplicateRoot, dupKey, SearchType.NORMAL, -1, null,
                         false /*updateGeneration*/);

                    return duplicateBin;
                } else {
                    /* We haven't migrated to a duplicate tree yet.
                     * XXX, isn't this taken care of above? */
                    return bin;
                }
            } else {
                bin.releaseLatch();
                return null;
            }
        } catch (DatabaseException DBE) {
            if (bin != null) {
                bin.releaseLatchIfOwner();
            }
            if (duplicateRoot != null) {
                duplicateRoot.releaseLatchIfOwner();
            }

      /*
       * FindBugs whines about Redundent comparison to null below, but
       * for stylistic purposes we'll leave it in.
View Full Code Here

Examples of com.sleepycat.je.tree.DIN

        int dupRootCount = 1;

        /* If fetchTarget returns null, a deleted LN was cleaned. */
        Node n = bin.fetchTarget(index);
        if (n != null && n.containsDuplicates()) {
            DIN dupRoot = (DIN) n;
            /* Latch couple down the tree. */
            dupRoot.latch();
      releaseBIN();
            DupCountLN dupCountLN = (DupCountLN)
                dupRoot.getDupCountLNRef().fetchTarget(database, dupRoot);
            /* We can't hold latches when we acquire locks. */
            dupRoot.releaseLatch();
            getReadLock(dupCountLN, LockType.READ);
            dupRootCount = dupCountLN.getDupCount();
        } else {
      releaseBIN();
        }
View Full Code Here

Examples of com.sleepycat.je.tree.DIN

        /* Check LN deleted status under the protection of a write lock. */
        if (ln == null) {
            return OperationStatus.KEYEMPTY;
        }

  DIN dupRoot = null;

  /*
         * Between the release of the BIN latch and acquiring the write lock
         * any number of operations may have executed which would result in a
         * new abort LSN for this record. Therefore, wait until now to get the
         * abort LSN.
         */
  latchBIN();
  isDup = (dupBin != null);
  if (isDup) {

      /*
       * We can't call latchBINs here because that would latch both BIN
       * and DBIN.  Subsequently we'd have to latch the dupRoot which is
       * higher in the tree than the DBIN which would be latching up the
       * tree.  So we have to latch in BIN, dupRoot, DBIN order.
       */
            /* Latch couple with the DupRoot. */
            dupRoot = (DIN) bin.fetchTarget(index);
            dupRoot.latch();

            latchDBIN();
  }
  setTargetBin();
        long oldLsn = targetBin.getLsn(targetIndex);
        byte[] lnKey = targetBin.getKey(targetIndex);
        long nodeId = targetBin.getNodeId();
        lockResult.setAbortLsn(oldLsn,
             targetBin.isEntryKnownDeleted(targetIndex));

        long oldLNSize = ln.getMemorySizeIncludedByParent();
        long newLsn = ln.delete(database, lnKey, dupKey, oldLsn, locker);
        long newLNSize = ln.getMemorySizeIncludedByParent();

        targetBin.updateEntry(targetIndex, newLsn, oldLNSize, newLNSize);
        targetBin.setPendingDeleted(targetIndex);
  releaseBINs();

        /*
         * Now update the parent of the LN (be it BIN or DBIN) to correctly
         * reference the LN and adjust the memory sizing.  Latch again and
         * reset BINs in case they changed during unlatched time. Be sure to do
         * this update of the LSN before updating the dup count LN. In case we
         * encounter problems there we need the LSN to match the latest version
         * to ensure that undo works.
         */
        if (isDup) {

            /*
             * Save a reference to the affected parent of this LN to place on
             * the delete info queue when the txn commits. If this is a
             * duplicate tree, we also have to update the duplicate tree count.
             */
            ChildReference dupCountRef = dupRoot.getDupCountLNRef();
            DupCountLN dcl = (DupCountLN)
                dupCountRef.fetchTarget(database, dupRoot);
            dupRoot.releaseLatch();
            LockResult dclGrantAndInfo = locker.lock
                (dcl.getNodeId(), LockType.WRITE, database);
            /*
             * The write lock request might have blocked while waiting for a
             * transaction that changed the oldLsn.  Re-get the reference to
             * the LN and get the old (abort) LSN out of it.
             */
            latchBIN();
            dupRoot = (DIN) bin.fetchTarget(index);
            dupRoot.latch();
            releaseBIN();
            dupCountRef = dupRoot.getDupCountLNRef();
            long oldDclLsn = dupCountRef.getLsn();
            dclGrantAndInfo.setAbortLsn(oldDclLsn,
                                        dupCountRef.isKnownDeleted());
            dcl = (DupCountLN) dupCountRef.fetchTarget(database, dupRoot);
            dcl.decDupCount();
      assert dcl.getDupCount() >= 0;
            EnvironmentImpl envImpl = database.getDbEnvironment();
            long dupCountLsn =
                dcl.log(envImpl, database.getId(), dupKey, oldDclLsn, locker);
            dupRoot.updateDupCountLNRef(dupCountLsn);
            dupRoot.releaseLatch();

            locker.addDeleteInfo(dupBin, new Key(lnKey));
        } else {
            locker.addDeleteInfo(bin, new Key(lnKey));
        }
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.