Package com.sleepycat.je.txn

Examples of com.sleepycat.je.txn.LockResult


      releaseBINs();
            return OperationStatus.KEYEMPTY;
        }

        /* 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) {
            releaseBINs();
            return OperationStatus.KEYEMPTY;
        }

        /* Lock the DupCountLN before logging any LNs. */
        LockResult dclLockResult = null;
        DIN dupRoot = null;
        try {
            isDup = (dupBin != null);
            if (isDup) {
                dupRoot = getLatchedDupRoot(true /*isDBINLatched*/);
 
View Full Code Here


        throws DatabaseException {

        assert assertCursorState(false) : dumpToString(true);

        assert LatchSupport.countLatchesHeld() == 0;
  LockResult lockResult = locker.lock
            (ln.getNodeId(), LockType.WRITE, false /*noWait*/, 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

                releaseBINs();
    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) {
                releaseBINs();
    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;
      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();

    if (len == 0) {
        newData = LogUtils.ZERO_LENGTH_BYTE_ARRAY;
    } else {
        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();
    if (len == 0) {
        newData = LogUtils.ZERO_LENGTH_BYTE_ARRAY;
    } else {
        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 = Key.compareKeys
                        (foundDataBytes, newData, userComparisonFcn) == 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

            }

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

            /* Don't set abort LSN for a read operation! */
            return ln;

        } finally {
View Full Code Here

                        } else {
                            foundSomething = true;
                            if (!containsDuplicates && exactSearch) {
        /* Lock LN, check if deleted. */
        LN ln = (LN) n;
        LockResult lockResult = lockLN(ln, lockType);
        ln = lockResult.getLN();

        if (ln == null) {
            foundSomething = false;
        }

View Full Code Here

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

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

      if (ln == null) {
                found = !exactSearch;
      } else {

View Full Code Here

        /*
         * Lock the LN.  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);
  try {
            ln = lockResult.getLN();
            byte[] lnData = (ln != null) ? ln.getData() : null;
            if (ln == null || lnData == null) {
                if (treeStatsAccumulator != null) {
                    treeStatsAccumulator.incrementDeletedLNCount();
                }
View Full Code Here

     * lock will not be held.
     */
    private LockResult lockLN(LN ln, LockType lockType)
  throws DatabaseException {

        LockResult lockResult = lockLNDeletedAllowed(ln, lockType);
        ln = lockResult.getLN();
        if (ln != null) {
            setTargetBin();
            if (targetBin.isEntryKnownDeleted(targetIndex) ||
                ln.isDeleted()) {
                revertLock(ln.getNodeId(), lockResult.getLockGrant());
                lockResult.setLN(null);
            }
        }
        return lockResult;
    }
View Full Code Here

     * a null LN if the LN was cleaned.
     */
    public LockResult lockLNDeletedAllowed(LN ln, LockType lockType)
  throws DatabaseException {

        LockResult lockResult;

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

        /*
         * Try a non-blocking lock first, to avoid unlatching.  If the default
         * is no-wait, use the standard lock method so LockNotHeldException is
         * thrown; there is no need to try a non-blocking lock twice.
         */
        if (locker.getDefaultNoWait()) {
            lockResult = locker.lock
                (ln.getNodeId(), lockType, true /*noWait*/, database);
        } else {
            lockResult = locker.nonBlockingLock
                (ln.getNodeId(), lockType, database);
        }
        if (lockResult.getLockGrant() != LockGrantType.DENIED) {
            lockResult.setLN(ln);
            return lockResult;
        }

        /*
         * Unlatch, get a blocking lock, latch, and get the current node from
         * the slot.  If the node ID changed while unlatched, revert the lock
         * and repeat.
         */
  while (true) {

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

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

            if (ln != null && nodeId != ln.getNodeId()) {
                /* If the node ID changed, revert the lock and try again. */
                revertLock(nodeId, lockResult.getLockGrant());
                continue;
            } else {
                /* If null (cleaned) or locked correctly, return the LN. */
                lockResult.setLN(ln);
                return lockResult;
            }
  }
    }
View Full Code Here

     */
    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 LockNotHeldException is
         * thrown; there is no need to try a non-blocking lock twice.
         */
        if (locker.getDefaultNoWait()) {
            lockResult = locker.lock
                (ln.getNodeId(), lockType, true /*noWait*/, database);
        } else {
            lockResult = locker.nonBlockingLock
                (ln.getNodeId(), lockType, database);
        }

        if (lockResult.getLockGrant() == LockGrantType.DENIED) {
            /* Release all latches. */
            dupRoot.releaseLatch();
            releaseBINs();
            /* Request a blocking lock. */
            lockResult = locker.lock
                (ln.getNodeId(), lockType, false /*noWait*/, database);
            /* Reacquire all latches. */
            latchBIN();
            dupRoot = (DIN) bin.fetchTarget(index);
            dupRoot.latch();
            latchDBIN();
            ln = dupRoot.getDupCountLN();
        }
        lockResult.setLN(ln);
        return lockResult;
    }
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.