Examples of LockResult


Examples of com.sleepycat.je.txn.LockResult

            }

            addCursor(bin);
       
            /* Lock LN (will unlatch).  */
            LockResult lockResult = lockLN(ln, lockType);
      ln = lockResult.getLN();

            if (ln == null) {
                return null;
            }

View Full Code Here

Examples of com.sleepycat.je.txn.LockResult

                            foundSomething = true;
                            if (!containsDuplicates && exactSearch) {
        /* Lock LN (will unlatch), check if deleted. */
        LN ln = (LN) n;
        long oldLsn = bin.getLsn(index);
        LockResult lockResult = lockLN(ln, lockType);
        ln = lockResult.getLN();
        latchBIN();

        if (ln == null) {
            foundSomething = false;
        }
View Full Code Here

Examples of com.sleepycat.je.txn.LockResult

        } else {
      /* Not a duplicate, but checking for both key and data match. */
            LN ln = (LN) n;

      /* Lock LN (will unlatch), check if deleted. */
      LockResult lockResult = lockLN(ln, lockType);
      ln = lockResult.getLN();
      latchBIN();

      if (ln == null) {
                found = !exactSearch;
      } else {
View Full Code Here

Examples of com.sleepycat.je.txn.LockResult

        /*
         * Lock the LN (will unlatch).  For dirty-read, the data of the LN can
         * be set to null at any time.  Cache the data in a local variable so
         * its state does not change before calling setDbt further below.
         */
  LockResult lockResult = lockLN(ln, lockType);
  ln = lockResult.getLN();
        byte[] lnData = (ln != null) ? ln.getData() : null;
        if (ln == null || lnData == null) {
            if (treeStatsAccumulator != null) {
                treeStatsAccumulator.incrementDeletedLNCount();
            }
View Full Code Here

Examples of com.sleepycat.je.txn.LockResult

  throws DatabaseException {

        /* For dirty-read, there is no need to fetch the node. */
        if (lockType == LockType.NONE) {
      releaseBINs();
            LockResult lockResult = new LockResult
                (LockGrantType.NONE_NEEDED, null);
            if (!ln.isDeleted()) {
                lockResult.setLN(ln);
            }
            return lockResult;
        }

  while (true) {

            /* Save the node ID we're locking and request a lock. */
      long nodeId = ln.getNodeId();
      releaseBINs();
      LockResult lockResult = getReadLock(ln, lockType);

            /* Fetch the current node after locking. */
      latchBINs();
      setTargetBin();
      ln = (LN) targetBin.fetchTarget(targetIndex);

            /* If the node ID changed, revert the lock and try again. */
            if (ln != null && nodeId != ln.getNodeId()) {
                revertLock(nodeId, lockResult.getLockGrant());
                continue;
            }

      if (ln == null ||
                ln.isDeleted() ||
                targetBin.isEntryKnownDeleted(targetIndex)) {
                /* Return a null LN if the LN was cleaned or is deleted. */
    revertLock(nodeId, lockResult.getLockGrant());
    releaseBINs();
    return new LockResult(null, null);
      } else {
                /* Return the LN for the node ID we successfully locked. */
                lockResult.setLN(ln);
                releaseBINs();
                return lockResult;
      }
  }
    }
View Full Code Here

Examples of com.sleepycat.je.txn.LockResult

    private void insertAndRetrieveDuplicate(byte[] key, LN ln, NullCursor cursor)
  throws DatabaseException {

        TestUtils.checkLatchCount();
        assertTrue(tree.insert(ln, key, true, cursor,
             new LockResult(null, null)));
        TestUtils.checkLatchCount();
        assertTrue(retrieveDuplicateLN(key, ln) == ln);
    }
View Full Code Here

Examples of com.sleepycat.je.txn.LockResult

            maxKey = key;
        }

        TestUtils.checkLatchCount();
        assertTrue(tree.insert(ln, key, false, cursor,
             new LockResult(null, null)));
        TestUtils.checkLatchCount();
        assertTrue(retrieveLN(key) == ln);
    }
View Full Code Here

Examples of com.sleepycat.je.txn.LockResult

             * writers in the tree. TODO: This seems unnecessary now, revisit.
             */
            ChildReference dclRef = duplicateRoot.getDupCountLNRef();
            dcl = (DupCountLN) dclRef.fetchTarget(database, duplicateRoot);

            LockResult lockResult = locker.nonBlockingLock(dcl.getNodeId(),
                                                           LockType.READ,
                                                           database);
            if (lockResult.getLockGrant() == LockGrantType.DENIED) {
                throw CursorsExistException.CURSORS_EXIST;
            }

            /*
             * We don't release the latch on bin before we search the
View Full Code Here

Examples of com.sleepycat.je.txn.LockResult

                    isDup = true;
                }

                /* If an LN is present, lock it and check deleted-ness. */
                boolean isDeleted = false;
                LockResult currentLock = null;

                if (!isDup) {
                    if (currentLN == null) {
                        /* The LN was cleaned. */
                        isDeleted = true;
                    } else {
                        currentLock = cursor.lockLNDeletedAllowed
                            (currentLN, LockType.WRITE);
                        currentLN = currentLock.getLN();
                        /* The BIN/index may have changed while locking. */
                        bin = cursor.getBIN();
                        index = cursor.getIndex();
                        if (cursor.getDupBIN() != null) {

                            /*
                             * A dup tree appeared during locking.  We will
                             * position to a different dup tree entry later in
                             * insertDuplicate, so we must remove the cursor
                             * from this dup tree entry.  This is a rare case
                             * so performance is not an issue.
                             */
                            cursor.clearDupBIN(true /*alreadyLatched*/);
                            isDup = true;
                        } else if (bin.isEntryKnownDeleted(index) ||
                                   currentLN == null ||
                                   currentLN.isDeleted()) {
                            /* The current LN is deleted/cleaned. */
                            isDeleted = true;
                        }
                    }
                }

                if (isDeleted) {

                    /*
                     * Set the abort LSN to that of the lock held on the
                     * current LN, if the current LN was previously locked by
                     * this txn.  This is needed when we change the node ID of
                     * this slot.
                     *
                     * If reusing a slot with a deleted LN deleted in a prior
                     * transaction (the LockGrantType is NEW or UPGRADE),
                     * always set abortKnownDeleted=true.  It may be that the
                     * existing slot is PENDING_DELETED, but we restore to
                     * KNOWN_DELETED in the event of an abort.
                     */
                    long abortLsn = bin.getLsn(index);
                    boolean abortKnownDeleted = true;
                    if (currentLN != null &&
                        currentLock.getLockGrant() == LockGrantType.EXISTING) {
                        long nodeId = currentLN.getNodeId();
                        Locker locker = cursor.getLocker();
                        WriteLockInfo info = locker.getWriteLockInfo(nodeId);
                        abortLsn = info.getAbortLsn();
                        abortKnownDeleted = info.getAbortKnownDeleted();
View Full Code Here

Examples of com.sleepycat.je.txn.LockResult

                CacheMode cacheMode = cursor.getCacheMode();
                dupRoot = (DIN) n;
                dupRoot.latch(cacheMode);

                /* Lock the DupCountLN before logging any LNs. */
                LockResult dclLockResult =
                    cursor.lockDupCountLN(dupRoot, LockType.WRITE);
                /* The BIN/index may have changed during locking. */
                bin = cursor.getBIN();
                index = cursor.getIndex();

                /*
                 * Do not proceed if duplicates are not allowed and there are
                 * one or more duplicates already present.  Note that if the
                 * dup count is zero, we allow the insert.
                 */
                if (!allowDuplicates) {

                    /*
                     * dupRoot could have been changed during the dcl lock so
                     * we need to grab it again here so that we release the
                     * latch on the correct dupRoot in the finally below.
                     */
                    dupRoot = (DIN) bin.fetchTarget(index);
                    DupCountLN dcl = (DupCountLN) dclLockResult.getLN();
                    if (dcl.getDupCount() > 0) {
                        return false;
                    }
                }

                /*
                 * Split the dup root if necessary.  The dup root may have
                 * changed during locking above or by the split, so refetch it.
                 * In either case it will be latched.
                 */
                maybeSplitDuplicateRoot(bin, index, cacheMode);
                dupRoot = (DIN) bin.fetchTarget(index);

                /*
                 * Search the duplicate tree for the right place to insert this
                 * new record. Releases the latch on duplicateRoot. If the
                 * duplicateRoot got logged as a result of some splitting,
                 * update the BIN's LSN information. The SortedLSNTreeWalker
                 * relies on accurate LSNs in the in-memory tree.
                 */
                byte[] newLNKey = newLN.getData();
                long previousLsn = dupRoot.getLastFullVersion();
                try {
                    dupBin = (DBIN) searchSubTreeSplitsAllowed
                        (dupRoot, newLNKey, Node.NULL_NODE_ID, cacheMode);
                } catch (RelatchRequiredException e) {
                    /* Should never happen, we use exclusive latches on DINs.*/
                    throw EnvironmentFailureException.unexpectedException(e);
                } catch (SplitRequiredException e) {

                    /*
                     * Shouldn't happen -- we have the DIN in the root of the
                     * dup tree latched during this insert, so there should be
                     * no possibility of being unable to insert a new entry
                     * into the DIN root of the dup tree.
                     */
                    throw EnvironmentFailureException.unexpectedException(e);
                }

                long currentLsn = dupRoot.getLastFullVersion();
                if (currentLsn != previousLsn) {
                    bin.updateEntry(index, currentLsn);
                }

                /* Release the BIN latch to increase concurrency. */
                cursor.releaseBIN();
                bin = null;

                /* The search above released the dup root latch. */
                dupRoot = null;

                /*
                 * Try to insert a new reference object. If successful, we'll
                 * log the LN and update the LSN in the reference.
                 */
                ChildReference newLNRef =
                    new ChildReference(newLN, newLNKey, DbLsn.NULL_LSN);

                int dupIndex = dupBin.insertEntry1(newLNRef);
                if ((dupIndex & IN.INSERT_SUCCESS) != 0) {

                    /*
                     * Update the cursor to point to the entry that has been
                     * successfully inserted.
                     */
                    dupIndex &= ~IN.INSERT_SUCCESS;
                    cursor.updateDBin(dupBin, dupIndex);

                    /* Log the new LN. */
                    long newLsn = DbLsn.NULL_LSN;
                    try {
                        newLsn = newLN.optionalLog
                            (env, database, key, DbLsn.NULL_LSN,
                             cursor.getLocker(), repContext);
                    } finally {
                        if ((newLsn == DbLsn.NULL_LSN) &&
                            (!database.isDeferredWriteMode())) {

                            /*
                             * See Tree.insert for an explanation of handling
                             * of IOException and OOME.
                             */
                            dupBin.setKnownDeleted(dupIndex);
                        }
                    }

                    lnLock.setAbortLsn(DbLsn.NULL_LSN, true, true);

                    /*
                     * Use updateEntry to be sure to mark the dupBin as dirty.
                     */
                    dupBin.updateEntry(dupIndex, newLsn);

                    traceInsertDuplicate(Level.FINER,
                                         database.getDbEnvironment(),
                                         dupBin, newLN, newLsn, binNid);
                    successfulInsert = true;
                } else {

                    /*
                     * The insert was not successful. Either this is a
                     * duplicate duplicate or there is an existing entry but
                     * that entry is deleted.
                     */
                    dupIndex &= ~IN.EXACT_MATCH;
                    cursor.updateDBin(dupBin, dupIndex);
                    LN currentLN = (LN) dupBin.fetchTarget(dupIndex);

                    /* If an LN is present, lock it and check deleted-ness. */
                    boolean isDeleted = false;
                    LockResult currentLock = null;
                    if (currentLN == null) {
                        /* The LN was cleaned. */
                        isDeleted = true;
                    } else {
                        currentLock = cursor.lockLNDeletedAllowed
                            (currentLN, LockType.WRITE);
                        currentLN = currentLock.getLN();

                        /*
                         * The BIN may have been latched while locking above.
                         * Release the latch here because we released it above
                         * to improve concurrency, and we will latch it again
                         * below to increment the duplicate count. [#15574]
                         */
                        cursor.releaseBIN();

                        /* The DBIN/index may have changed while locking. */
                        dupBin = cursor.getDupBIN();
                        dupIndex = cursor.getDupIndex();
                        if (dupBin.isEntryKnownDeleted(dupIndex) ||
                            currentLN == null ||
                            currentLN.isDeleted()) {
                            /* The current LN is deleted/cleaned. */
                            isDeleted = true;
                        }
                    }

                    if (isDeleted) {
                        /* See Tree.insert for an explanation. */
                        long abortLsn = dupBin.getLsn(dupIndex);
                        boolean abortKnownDeleted = true;
                        if (currentLN != null &&
                            currentLock.getLockGrant() ==
                            LockGrantType.EXISTING) {
                            long nodeId = currentLN.getNodeId();
                            Locker locker = cursor.getLocker();
                            WriteLockInfo info =
                                locker.getWriteLockInfo(nodeId);
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.