Package com.sleepycat.je.txn

Examples of com.sleepycat.je.txn.LockResult


     */
    public LockResult lockDupCountLN(DIN dupRoot, LockType lockType)
        throws DatabaseException {

        DupCountLN ln = dupRoot.getDupCountLN();
        LockResult lockResult;

        /*
         * Try a non-blocking lock first, to avoid unlatching.  If the default
         * is no-wait, use the standard lock method so
         * LockNotAvailableException is thrown; there is no need to try a
         * non-blocking lock twice.
         */
        if (locker.getDefaultNoWait()) {
            try {
                lockResult = locker.lock
                    (ln.getNodeId(), lockType, true /*noWait*/, databaseImpl);
            } catch (LockConflictException e) {
                /*
                 * Release all latches.  Note that we catch
                 * LockConflictException for simplicity but we expect either
                 * LockNotAvailableException or LockNotGrantedException.
                 */
                dupRoot.releaseLatch();
                releaseBINs();
                throw e;
            }
        } else {
            lockResult = locker.nonBlockingLock
                (ln.getNodeId(), lockType, databaseImpl);
        }

        if (lockResult.getLockGrant() == LockGrantType.DENIED) {
            /* Release all latches. */
            dupRoot.releaseLatch();
            releaseBINs();
            /* Request a blocking lock. */
            lockResult = locker.lock
                (ln.getNodeId(), lockType, false /*noWait*/, databaseImpl);
            /* Reacquire all latches. */
            latchBIN();
            dupRoot = (DIN) bin.fetchTarget(index);
            dupRoot.latch(cacheMode);
            latchDBIN();
            ln = dupRoot.getDupCountLN();
        }
        lockResult.setLN(ln);
        return lockResult;
    }
View Full Code Here


                 * attempt to acquire a non-blocking read lock.
                 */
                locker = BasicLocker.createBasicLocker(env, false /*noWait*/);
                /* Don't allow this short-lived lock to be preempted/stolen. */
                locker.setPreemptable(false);
                LockResult lockRet = locker.nonBlockingLock
                    (nodeId, LockType.READ, db);
                if (lockRet.getLockGrant() == LockGrantType.DENIED) {

                    /*
                     * LN is currently locked by another Locker, so we can't
                     * assume anything about the value of the LSN in the bin.
                     */
 
View Full Code Here

            /* Get a non-blocking lock on the original node ID. */

            locker = BasicLocker.createBasicLocker(env, false /*noWait*/);
            /* Don't allow this short-lived lock to be preempted/stolen. */
            locker.setPreemptable(false);
            LockResult lockRet = locker.nonBlockingLock
                (ln.getNodeId(), LockType.READ, db);
            if (lockRet.getLockGrant() == LockGrantType.DENIED) {
                /* Try again later. */
                nPendingLNsLocked.increment();
                lockDenied = true;
                completed = true;
                return;
View Full Code Here

             */
            if (lockedPendingNodeId != ln.getNodeId()) {
                locker = BasicLocker.createBasicLocker(env, false /*noWait*/);
                /* Don't allow this short-lived lock to be preempted/stolen. */
                locker.setPreemptable(false);
                LockResult lockRet = locker.nonBlockingLock
                    (ln.getNodeId(), LockType.READ, db);
                if (lockRet.getLockGrant() == LockGrantType.DENIED) {

                    /*
                     * LN is currently locked by another Locker, so we can't
                     * assume anything about the value of the LSN in the bin.
                     */
 
View Full Code Here

             */
            if (lockedPendingNodeId != ln.getNodeId()) {
                locker = BasicLocker.createBasicLocker(env, false /*noWait*/);
                /* Don't allow this short-lived lock to be preempted/stolen. */
                locker.setPreemptable(false);
                LockResult lockRet = locker.nonBlockingLock
                    (ln.getNodeId(), LockType.READ, db);
                if (lockRet.getLockGrant() == LockGrantType.DENIED) {

                    /*
                     * LN is currently locked by another Locker, so we can't
                     * assume anything about the value of the LSN in the bin.
                     */
 
View Full Code Here

    cursor.updateBin(bin, duplicateEntryIndex);
    if (n != null) {
        bin.releaseLatch();
    }
    Locker locker = cursor.getLocker();
                LockResult currentLock = null;
    while (n != null) {

        /*
         * Write lock instead of read lock to avoid upgrade issues.
         * There's a good chance that we'll need it for write
         * anyway.
         */
        currentLock = locker.lock
                        (currentLN.getNodeId(), LockType.WRITE, database);
        bin = cursor.latchBIN();
        duplicateEntryIndex = cursor.getIndex();
        n = bin.fetchTarget(duplicateEntryIndex);
        if (n == null) {
      currentLN = null;
      break;
        }
        if (n == currentLN ||
      dupCount != -1) {
      break;
        } else {

      /*
       * We should consider releasing the lock on currentLN
       * here.  However, it may be been locked from a prior
       * operation in this transaction.
       */
      if (n instanceof LN) {
          currentLN = (LN) n;
          dupCount = -1;
      } else {
          DIN duplicateRoot = (DIN) n;
          currentLN = (DupCountLN)
        duplicateRoot.getDupCountLNRef().
        fetchTarget(database, duplicateRoot);
          dupCount = ((DupCountLN) currentLN).getDupCount();
      }

      bin.releaseLatch();
        }
    }

    /*
     * If the ref is knownDeleted (DupCountLN's can't be deleted or
     * knownDeleted), or the LN that it points to is not a
     * DupCountLN and the data in it is deleted, then we substitute
     * the argument LN for it.
     *
     * dupCount == -1 means there is no dup tree here.
                 *
                 * If fetchTarget returns null, a deleted LN was cleaned.
     */
    boolean isDeleted = false;
                if (bin.isEntryKnownDeleted(duplicateEntryIndex)) {
                    isDeleted = true;
                } else if (dupCount == -1) {
                    LN existingLN = (LN) bin.fetchTarget(duplicateEntryIndex);
                    if (existingLN == null || existingLN.isDeleted()) {
                        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 an 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(duplicateEntryIndex);
                    boolean abortKnownDeleted = true;
                    if (currentLN != null &&
                        currentLock.getLockGrant() == LockGrantType.EXISTING) {
                        long nodeId = currentLN.getNodeId();
      abortLsn = locker.getAbortLsn(nodeId);
                        abortKnownDeleted =
          locker.getAbortKnownDeleted(nodeId);
                    }
View Full Code Here

                     * above.
         */
        cursor.updateDBin(duplicateBin, duplicateEntryIndex);
        duplicateBin.releaseLatch();
        Locker locker = cursor.getLocker();
                    LockResult currentLock = null;
        bin.releaseLatchIfOwner();

        while (currentLN != null) {
      currentLock = locker.lock
                            (currentLN.getNodeId(), LockType.WRITE, database);
      while (true) {
          duplicateBin = cursor.getDupBIN();
          duplicateBin.latch();
          if (duplicateBin != cursor.getDupBIN()) {
        duplicateBin.releaseLatch();
        continue;
          } else {
        break;
          }
      }
      duplicateEntryIndex = cursor.getDupIndex();
      n = duplicateBin.fetchTarget(duplicateEntryIndex);
      if (n == null) {
          currentLN = null;
          break;
      }
      if (n == currentLN) {
          break;
      } else {
          duplicateBin.releaseLatch();
          currentLN = (LN) n;
      }
        }

                    /* If currentLN is null, a deleted LN was cleaned.*/
        boolean isKnownDeleted =
      duplicateBin.isEntryKnownDeleted(duplicateEntryIndex);
                    if (isKnownDeleted ||
                        currentLN == null ||
                        currentLN.isDeleted()) {

                        /*
       * Existing entry is deleted.  Replace it.  If called
                         * on behalf of a cursor, update it to point to the
                         * entry that has been successfully inserted.
       */
      cursor.updateDBin(duplicateBin, duplicateEntryIndex);

                        /*
                         * 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 an 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 = duplicateBin.getLsn
                            (duplicateEntryIndex);
                        boolean abortKnownDeleted = true;
                        if (currentLN != null &&
                            currentLock.getLockGrant() ==
                            LockGrantType.EXISTING) {
                            long nodeId = currentLN.getNodeId();
          abortLsn = locker.getAbortLsn(nodeId);
                            abortKnownDeleted =
                                locker.getAbortKnownDeleted(nodeId);
View Full Code Here

  try {

      /* Write lock the DupCountLN */
      duplicateRoot.releaseLatch();
      cursor.releaseBINs();
      LockResult lockResult = cursor.getLocker().lock
    (dupCountLN.getNodeId(), LockType.WRITE, database);
 
      /*
       * Relatch the BIN and the DIN which is the root of the duplicate
       * tree.  We must re-establish our references to the owning
View Full Code Here

             *
             * We request a lock while holding latches which is usually
             * forbidden, but safe in this case since we know it will be
             * immediately granted (we just created dupCountLN above).
             */
            LockResult lockResult = locker.lock
                (dupCountLN.getNodeId(), LockType.WRITE, database);
            lockResult.setAbortLsn(firstDupCountLNLsn, false);

            dupCountLN.setDupCount(2);
            long dupCountLsn = dupCountLN.log(env, database.getId(), key,
                                              firstDupCountLNLsn, locker);
            duplicateRoot.updateDupCountLNRef(dupCountLsn);
View Full Code Here

TOP

Related Classes of com.sleepycat.je.txn.LockResult

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.