Examples of LockResult


Examples of com.sleepycat.je.txn.LockResult

        /*
         * We're reconstructing an unfinished transaction.  We know that there
         * was a write lock on this LN since it exists in the log under this
         * txnId.
         */
        final LockResult result = txn.nonBlockingLock
            (logLsn, LockType.WRITE, false /*jumpAheadOfWaiters*/, db);
        if (result.getLockGrant() == LockGrantType.DENIED) {
            throw EnvironmentFailureException.unexpectedState
               ("Resurrected lock denied txn=" + txn.getId() +
                " logLsn=" + DbLsn.getNoFormatString(logLsn) +
                " abortLsn=" + DbLsn.getNoFormatString(abortLsn));
        }

        /*
         * Set abortLsn and database for utilization tracking.  We don't know
         * lastLoggedSize, so a default will be used for utilization counting.
         * This should not be common.
         */
        result.setAbortLsn(abortLsn, abortKnownDeleted);
        final WriteLockInfo wli = result.getWriteLockInfo();
        if (wli == null) {
            throw EnvironmentFailureException.unexpectedState
               ("Resurrected lock has no write info txn=" + txn.getId() +
                " logLsn=" + DbLsn.getNoFormatString(logLsn) +
                " abortLsn=" + DbLsn.getNoFormatString(abortLsn));
View Full Code Here

Examples of com.sleepycat.je.txn.LockResult

        /**
         * Lock the new LSN immediately after logging, with the BIN latched.
         * Lock non-blocking, since no contention is possible on the new LSN.
         */
        if (locker != null) {
            final LockResult lockResult = locker.nonBlockingLock
                (item.newLsn, LockType.WRITE, false /*jumpAheadOfWaiters*/,
                 dbImpl);
            assert lockResult.getLockGrant() != LockGrantType.DENIED:
                   DbLsn.getNoFormatString(item.newLsn);
            lockResult.copyWriteLockInfo(writeLockInfo);
        }
        clearDirty();
        return item.newLsn;
    }
View Full Code Here

Examples of com.sleepycat.je.txn.LockResult

        /**
         * Lock immediately after assigning a new LSN, with the BIN latched.
         * Lock non-blocking, since no contention is possible on the new LSN.
         */
        if (locker != null) {
            final LockResult lockResult = locker.nonBlockingLock
                (newLsn, LockType.WRITE, false /*jumpAheadOfWaiters*/, dbImpl);
            assert lockResult.getLockGrant() != LockGrantType.DENIED:
                   DbLsn.getNoFormatString(newLsn);
        }

        return newLsn;
    }
View Full Code Here

Examples of com.sleepycat.je.txn.LockResult

    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

Examples of com.sleepycat.je.txn.LockResult

                     * 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

Examples of com.sleepycat.je.txn.LockResult

  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

Examples of com.sleepycat.je.txn.LockResult

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

Examples of com.sleepycat.je.txn.LockResult

        if (ln == null) {
      releaseBINs();
            return OperationStatus.KEYEMPTY;
        }

  LockResult lockResult = lockLN(ln, LockType.WRITE);
  ln = lockResult.getLN();
           
        /* 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();
View Full Code Here

Examples of com.sleepycat.je.txn.LockResult

        throws DatabaseException {

        assert assertCursorState(false) : dumpToString(true);

        assert Latch.countLatchesHeld() == 0;
  LockResult lockResult =
            locker.lock(ln.getNodeId(), LockType.WRITE, database);

  /*
   * We'll set abortLsn down in Tree.insert when we know whether we're
   * re-using a BIN entry or not.
View Full Code Here

Examples of com.sleepycat.je.txn.LockResult

                ln == null) {
    return OperationStatus.NOTFOUND;
      }

            /* Get a write lock. */
      LockResult lockResult = lockLN(ln, LockType.WRITE);
      ln = lockResult.getLN();

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

            /*
             * If cursor points at a dup, then we can only replace the entry
             * with a new entry that is "equal" to the old one.  Since a user
             * defined comparison function may actually compare equal for two
             * byte sequences that are actually different we still have to do
             * the replace.  Arguably we could skip the replacement if there is
             * no user defined comparison function and the new data is the
             * same.
             */
      byte[] foundDataBytes;
      byte[] foundKeyBytes;
            latchBINs();
      isDup = setTargetBin();
      if (isDup) {
    foundDataBytes = lnKey;
    foundKeyBytes = targetBin.getDupKey();
      } else {
    foundDataBytes = ln.getData();
    foundKeyBytes = lnKey;
      }
            byte[] newData;

            /* Resolve partial puts. */
            if (data.getPartial()) {
                int dlen = data.getPartialLength();
                int doff = data.getPartialOffset();
                int origlen = (foundDataBytes != null) ?
                    foundDataBytes.length : 0;
                int oldlen = (doff + dlen > origlen) ? doff + dlen : origlen;
                int len = oldlen - dlen + data.getSize();
                newData = new byte[len];
                int pos = 0;

                /*
     * Keep 0..doff of the old data (truncating if doff > length).
     */
                int slicelen = (doff < origlen) ? doff : origlen;
                if (slicelen > 0)
                    System.arraycopy(foundDataBytes, 0, newData,
             pos, slicelen);
                pos += doff;

                /* Copy in the new data. */
                slicelen = data.getSize();
                System.arraycopy(data.getData(), data.getOffset(),
                                 newData, pos, slicelen);
                pos += slicelen;

                /* Append the rest of the old data (if any). */
                slicelen = origlen - (doff + dlen);
                if (slicelen > 0)
                    System.arraycopy(foundDataBytes, doff + dlen, newData, pos,
                                     slicelen);
            } else {
                int len = data.getSize();
                newData = new byte[len];
                System.arraycopy(data.getData(), data.getOffset(),
                                 newData, 0, len);
            }

            if (database.getSortedDuplicates()) {
    /* Check that data compares equal before replacing it. */
    boolean keysEqual = false;
    if (foundDataBytes != null) {
        keysEqual = (userComparisonFcn == null ?
         (Key.compareKeys
                                  (foundDataBytes, newData) == 0) :
         (userComparisonFcn.compare
                                  (foundDataBytes, newData) == 0));
    }
    if (!keysEqual) {
        revertLock(ln, lockResult);
        throw new DatabaseException
      ("Can't replace a duplicate with different data.");
    }
      }
      if (foundData != null) {
    setDbt(foundData, foundDataBytes);
      }
      if (foundKey != null) {
    setDbt(foundKey, foundKeyBytes);
      }

            /*
             * 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.
             */
      long oldLsn = targetBin.getLsn(targetIndex);
      lockResult.setAbortLsn
    (oldLsn, targetBin.isEntryKnownDeleted(targetIndex));

            /*
       * The modify has to be inside the latch so that the BIN is updated
       * inside the latch.
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.