Examples of BasicLocker


Examples of com.sleepycat.je.txn.BasicLocker

  throws DatabaseException {

        initEnv(false);
  byte[][] keys = new byte[N_KEYS][];
  LN[] lns = new LN[N_KEYS];
        Locker txn = new BasicLocker(DbInternal.envGetEnvironmentImpl(env));
        NullCursor cursor = new NullCursor(tree.getDatabase(), txn);
       
  for (int i = 0; i < N_KEYS; i++) {
      byte[] key = new byte[N_KEY_BYTES];
      keys[i] = key;
      lns[i] = new LN((byte[]) new byte[1]);
      TestUtils.generateRandomAlphaBytes(key);
      insertAndRetrieve(cursor, key, lns[i]);
  }

        /*
         * Note that verify will attempt to continue past errors, so
         * assertTrue on the status return.
         */
        assertTrue(env.verify(new VerifyConfig(), System.err));
  DatabaseStats stats = db.verify(new VerifyConfig());
  BtreeStats btStats = (BtreeStats) stats;

  assertTrue(btStats.getInternalNodeCount() <
       btStats.getBottomInternalNodeCount());
  assertTrue(btStats.getBottomInternalNodeCount() <
       btStats.getLeafNodeCount() +
       btStats.getDeletedLeafNodeCount());
  assertTrue(btStats.getLeafNodeCount() +
       btStats.getDeletedLeafNodeCount() ==
       N_KEYS);
        txn.operationEnd();

        /* Now intentionally create LogFileNotFoundExceptions */
        /*
          db.close();
          env.close();
View Full Code Here

Examples of com.sleepycat.je.txn.BasicLocker

        boolean ret = false;
        boolean setNewIdKey = false;
        boolean anyLocksDenied = false;
  DatabaseImpl db = getDatabase();
        BasicLocker lockingTxn = new BasicLocker(db.getDbEnvironment());

        try {
            for (int i = 0; i < getNEntries(); i++) {

    /*
     * We have to be able to lock the LN before we can compress the
     * entry.  If we can't, then, skip over it.
     *
     * We must lock the LN even if isKnownDeleted is true, because
     * locks protect the aborts. (Aborts may execute multiple
     * operations, where each operation latches and unlatches. It's
     * the LN lock that protects the integrity of the whole
     * multi-step process.)
                 *
                 * For example, during abort, there may be cases where we have
     * deleted and then added an LN during the same txn.  This
     * means that to undo/abort it, we first delete the LN (leaving
     * knownDeleted set), and then add it back into the tree.  We
     * want to make sure the entry is in the BIN when we do the
     * insert back in.
     */
                boolean deleteEntry = false;
                long obsoleteLsn = DbLsn.NULL_LSN;
                if (binRef == null ||
        isEntryPendingDeleted(i) ||
                    isEntryKnownDeleted(i) ||
                    binRef.hasDeletedKey(new Key(getKey(i)))) {

                    Node n = null;
                    if (canFetch) {
                        n = fetchTarget(i);
                    } else {
                        n = getTarget(i);
                        if (n == null) {
                            /* Punt, we don't know the state of this child. */
                            continue;
                        }
                    }

                    if (n == null) {
                        /* Cleaner deleted the log file.  Compress this LN. */
                        deleteEntry = true;
                    } else if (isEntryKnownDeleted(i)) {
                        LockGrantType lockRet =
                            lockingTxn.nonBlockingReadLock(n.getNodeId(), db);
                        if (lockRet == LockGrantType.DENIED) {
                            anyLocksDenied = true;
                            continue;
                        }

                        deleteEntry = true;
                    } else {
                        if (!n.containsDuplicates()) {
                            LN ln = (LN) n;
                            LockGrantType lockRet =
                                lockingTxn.nonBlockingReadLock(ln.getNodeId(),
                     db);
                            if (lockRet == LockGrantType.DENIED) {
                                anyLocksDenied = true;
                                continue;
                            }

                            if (ln.isDeleted()) {
                                deleteEntry = true;
                            }
                        }
                    }

                    if (deleteEntry && n instanceof LN) {
                        obsoleteLsn = getLsn(i);
                    }

                    /* Remove key from BINReference in case we requeue it. */
                    if (binRef != null) {
                        binRef.removeDeletedKey(new Key(getKey(i)));
                    }
                }

                /* At this point, we know we can delete. */
                if (deleteEntry) {
                    Comparator userComparisonFcn = getKeyComparator();
                    boolean entryIsIdentifierKey =
                        (userComparisonFcn == null ?
                         Key.compareKeys(getKey(i), getIdentifierKey()) :
                         userComparisonFcn.compare
       (getKey(i), getIdentifierKey()))
                        == 0;
                    if (entryIsIdentifierKey) {

                        /*
                         * We're about to remove the entry with the idKey so
                         * the node will need a new idkey.
                         */
                        setNewIdKey = true;
                    }

                    boolean deleteSuccess = deleteEntry(i, true);
                    assert deleteSuccess;

                    /*
                     * Since we're deleting the current entry, bump the current
                     * index back down one.
                     */
                    i--;
                }
            }
        } finally {
            if (lockingTxn != null) {
                lockingTxn.operationEnd();
            }
        }

        if (anyLocksDenied && binRef != null) {
            db.getDbEnvironment().addToCompressorQueue(binRef, false);
View Full Code Here

Examples of com.sleepycat.je.txn.BasicLocker

               NodeNotEmptyException,
               CursorsExistException {

        EnvironmentImpl envImpl = database.getDbEnvironment();
        DupCountLN dcl = null;
        BasicLocker locker = BasicLocker.createBasicLocker(envImpl);
        /* Don't allow this short-lived lock to be preempted/stolen. */
        locker.setPreemptable(false);

        /*  Latch the DIN root. */
        DIN duplicateRoot = (DIN) bin.fetchTarget(index);
        duplicateRoot.latch(CacheMode.UNCHANGED);

        ArrayList<SplitInfo> nodeLadder = new ArrayList<SplitInfo>();
        IN subtreeRootIN = null;

        try {

            /*
             * Read lock the dup count LN to ascertain whether there are any
             * 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
             * duplicate tree below because we might be deleting the whole
             * subtree from the IN and we want to keep it latched until we
             * know.
             */
            searchDeletableSubTree(duplicateRoot, idKey, nodeLadder);

            if (nodeLadder.size() == 0) {
                /* We're deleting the duplicate root. */
                if (bin.nCursors() == 0) {
                    boolean deleteOk = bin.deleteEntry(index, true);
                    assert deleteOk;

                    /*
                     * Use an INDupDeleteInfo to make it clear that this
                     * duplicate tree has been eradicated. This is analagous to
                     * deleting a root; we must be sure that we can overlay
                     * another subtree onto this slot at recovery redo.
                     */
                    INDupDeleteInfo info =
                        new INDupDeleteInfo(duplicateRoot.getNodeId(),
                                            duplicateRoot.getMainTreeKey(),
                                            duplicateRoot.getDupTreeKey(),
                                            database.getId());
                    info.optionalLog(envImpl.getLogManager(), database);

                    subtreeRootIN = duplicateRoot;

                    if (bin.getNEntries() == 0) {
                        database.getDbEnvironment().
                            addToCompressorQueue(bin, null, false);
                    }
                } else {

                    /*
                     * Cursors prevent us from deleting this dup tree, we'll
                     * have to retry.
                     */
                    throw CursorsExistException.CURSORS_EXIST;
                }
            } else {

                /* We're deleting a portion of the duplicate tree. */
                SplitInfo detachPoint =
                    nodeLadder.get(nodeLadder.size() - 1);
                boolean deleteOk =
                    detachPoint.parent.deleteEntry(detachPoint.index,
                                                   true);
                assert deleteOk;

                /*
                 * Cascade updates upward, including writing the root
                 * DIN and parent BIN.
                 */
                cascadeUpdates(nodeLadder, bin, index);
                subtreeRootIN = detachPoint.child;
            }
        } finally {
            releaseNodeLadderLatches(nodeLadder);

            locker.operationEnd(true);
            duplicateRoot.releaseLatch();
        }

        return subtreeRootIN;
    }
View Full Code Here

Examples of com.sleepycat.je.txn.BasicLocker

        boolean evictable = false;

        /* To prevent DB open, get a write-lock on the MapLN. */
        EnvironmentImpl envImpl = databaseImpl.getDbEnvironment();
        BasicLocker locker = BasicLocker.createBasicLocker(envImpl);
        DatabaseImpl idDatabaseImpl = envImpl.getDbTree().getIdDatabaseImpl();
        try {
            LockResult lockResult = locker.nonBlockingLock
                (getNodeId(), LockType.WRITE, idDatabaseImpl);

            /*
             * The isEvictableInexact result is guaranteed to hold true during
             * LN stripping if it is still true after acquiring the write-lock.
             */
            if (lockResult.getLockGrant() != LockGrantType.DENIED &&
                isEvictableInexact()) {

                /*
                 * While holding both a write-lock on the MapLN, we are
                 * guaranteed that the DB is not currently open.  It cannot be
                 * subsequently opened until the BIN latch is released, since
                 * the BIN latch will block DbTree.getDb (called during DB
                 * open).  We will evict the LN before releasing the BIN latch.
                 * After releasing the BIN latch, if a DB open is waiting on
                 * getDb, then it will proceed, fetch the evicted LN and open
                 * the DB normally.
                 */
                evictable = true;
            }
        } finally {
            /* Release the write-lock.  The BIN latch is still held. */
            locker.operationEnd();
        }

        return evictable;
    }
View Full Code Here

Examples of com.sleepycat.je.txn.BasicLocker

        boolean anyLocksDenied = false;
        DatabaseImpl db = getDatabase();
        EnvironmentImpl envImpl = db.getDbEnvironment();

        for (int i = 0; i < getNEntries(); i++) {
            final BasicLocker lockingTxn =
                BasicLocker.createBasicLocker(envImpl);
            /* Don't allow this short-lived lock to be preempted/stolen. */
            lockingTxn.setPreemptable(false);
            try {

                /*
                 * We have to be able to lock the LN before we can compress the
                 * entry.  If we can't, then, skip over it.
                 *
                 * We must lock the LN even if isKnownDeleted is true, because
                 * locks protect the aborts. (Aborts may execute multiple
                 * operations, where each operation latches and unlatches. It's
                 * the LN lock that protects the integrity of the whole
                 * multi-step process.)
                 *
                 * For example, during abort, there may be cases where we have
                 * deleted and then added an LN during the same txn.  This
                 * means that to undo/abort it, we first delete the LN (leaving
                 * knownDeleted set), and then add it back into the tree.  We
                 * want to make sure the entry is in the BIN when we do the
                 * insert back in.
                 */
                boolean deleteEntry = false;
                Node n = null;

                if (binRef == null ||
                    isEntryPendingDeleted(i) ||
                    isEntryKnownDeleted(i) ||
                    binRef.hasDeletedKey(new Key(getKey(i)))) {

                    if (canFetch) {
                        if (db.isDeferredWriteMode() &&
                            getLsn(i) == DbLsn.NULL_LSN) {
                            /* Null LSNs are ok in DW. [#15588] */
                            n = getTarget(i);
                        } else {
                            n = fetchTarget(i);
                        }
                    } else {
                        n = getTarget(i);
                        if (n == null) {
                            /* Punt, we don't know the state of this child. */
                            continue;
                        }
                    }

                    if (n == null) {
                        /* Cleaner deleted the log file.  Compress this LN. */
                        deleteEntry = true;
                    } else if (isEntryKnownDeleted(i)) {
                        LockResult lockRet = lockingTxn.nonBlockingLock
                            (n.getNodeId(), LockType.READ, db);
                        if (lockRet.getLockGrant() == LockGrantType.DENIED) {
                            anyLocksDenied = true;
                            continue;
                        }

                        deleteEntry = true;
                    } else {
                        if (!n.containsDuplicates()) {
                            LN ln = (LN) n;
                            LockResult lockRet = lockingTxn.nonBlockingLock
                                (ln.getNodeId(), LockType.READ, db);
                            if (lockRet.getLockGrant() ==
                                LockGrantType.DENIED) {
                                anyLocksDenied = true;
                                continue;
                            }

                            if (ln.isDeleted()) {
                                deleteEntry = true;
                            }
                        }
                    }

                    /* Remove key from BINReference in case we requeue it. */
                    if (binRef != null) {
                        binRef.removeDeletedKey(new Key(getKey(i)));
                    }
                }

                /* At this point, we know we can delete. */
                if (deleteEntry) {
                    boolean entryIsIdentifierKey = Key.compareKeys
                        (getKey(i), getIdentifierKey(),
                         getKeyComparator()) == 0;
                    if (entryIsIdentifierKey) {

                        /*
                         * We're about to remove the entry with the idKey so
                         * the node will need a new idkey.
                         */
                        setNewIdKey = true;
                    }

                    if (db.isDeferredWriteMode() &&
                        n instanceof LN) {
                        LN ln = (LN) n;
                        long lsn = getLsn(i);
                        if (ln.isDirty() && lsn != DbLsn.NULL_LSN) {
                            if (db.isTemporary()) {

                                /*
                                 * When a previously logged LN in a temporary
                                 * DB is dirty, we can count the LSN of the
                                 * last logged LN as obsolete without logging.
                                 * There it no requirement for the dirty
                                 * deleted LN to be durable past recovery.
                                 * There is no danger of the last logged LN
                                 * being accessed again (after log cleaning,
                                 * for example), since temporary DBs do not
                                 * survive recovery.
                                 */
                                if (localTracker != null) {
                                    localTracker.countObsoleteNode
                                        (lsn, ln.getLogType(),
                                         ln.getLastLoggedSize(), db);
                                }
                            } else {

                                /*
                                 * When a previously logged deferred-write LN
                                 * is dirty, we log the dirty deleted LN to
                                 * make the deletion durable.  The act of
                                 * logging will also count the last logged LSN
                                 * as obsolete.
                                 */
                                logDirtyLN(i, ln, false /*force*/);
                            }
                        }
                    }

                    boolean deleteSuccess = deleteEntry(i, true);
                    assert deleteSuccess;

                    /*
                     * Since we're deleting the current entry, bump the current
                     * index back down one.
                     */
                    i--;
                }
            } finally {
                lockingTxn.operationEnd();
            }
        }

        if (anyLocksDenied && binRef != null) {
            db.getDbEnvironment().addToCompressorQueue(binRef, false);
View Full Code Here

Examples of com.sleepycat.je.txn.BasicLocker

        Locker locker = null;
        CursorImpl cursor = null;
        boolean ok = true;
       
        try {
            locker = new BasicLocker(env);
            cursor = new CursorImpl(fileSummaryDb, locker);

            if (cursor.positionFirstOrLast(true, null)) {

                OperationStatus status = cursor.getCurrentAlreadyLatched
View Full Code Here

Examples of com.sleepycat.je.txn.BasicLocker

        boolean migrated = false// The LN was in use and is migrated.
        boolean lockDenied = false;// The LN lock was denied.
        boolean completed = false; // This method completed.

        long nodeId = ln.getNodeId();
        BasicLocker locker = null;
        try {
            Tree tree = db.getTree();
            assert tree != null;

            /*
             * If the tree and log LSNs are equal, then we can be fairly
             * certain that the log entry is current; in that case, it is
             * wasteful to lock the LN here -- it is better to lock only once
             * during lazy migration.  But if the tree and log LSNs differ, it
             * is likely that another thread has updated or deleted the LN and
             * the log LSN is now obsolete; in this case we can avoid dirtying
             * the BIN by checking for obsoleteness here, which requires
             * locking.  The latter case can occur frequently if trackDetail is
             * false.
             *
             * 1. If the LSN in the tree and in the log are the same, we will
             * attempt to migrate it.
             *
             * 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) {

                /*
                 * 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);
                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.
                     */
                    nLNsLockedThisRun++;
                    lockDenied = true;
                } else {
                    /* The LN is obsolete and can be purged. */
                    nLNsDeadThisRun++;
                    obsolete = true;
                }
            }

            if (!obsolete && !lockDenied) {

                /*
                 * Set the migrate flag and dirty the parent IN.  The evictor
                 * or checkpointer will migrate the LN later.
                 *
                 * Then set the target node so it does not have to be fetched
                 * when it is migrated, if the tree and log LSNs are equal and
                 * the target is not resident.  We must call postFetchInit to
                 * initialize MapLNs that have not been fully initialized yet
                 * [#13191].
                 */
                if (isDupCountLN) {
                    ChildReference dclRef = parentDIN.getDupCountLNRef();
                    dclRef.setMigrate(true);
                    parentDIN.setDirty(true);

                    if (treeLsn == logLsn && dclRef.getTarget() == null) {
                        ln.postFetchInit(db, logLsn);
                        parentDIN.updateDupCountLN(ln);
                    }
                } else {
                    bin.setMigrate(index, true);
                    bin.setDirty(true);

                    if (treeLsn == logLsn && bin.getTarget(index) == null) {
                        ln.postFetchInit(db, logLsn);
                        bin.updateEntry(index, ln);
                    }

                    /*
                     * If the generation is zero, we fetched this BIN just for
                     * cleaning.
                     */
                    if (PROHIBIT_DELTAS_WHEN_FETCHING &&
                        bin.getGeneration() == 0) {
                        bin.setProhibitNextDelta();
                    }

                    /*
                     * 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();
                }

                nLNsMarkedThisRun++;
                migrated = true;
            }
            completed = true;
        } finally {
            if (locker != null) {
                locker.operationEnd();
            }

            /*
             * If a write lock is held, it is likely that the log LSN will
             * become obsolete.  It is more efficient to process this via the
View Full Code Here

Examples of com.sleepycat.je.txn.BasicLocker

    private Locker createLocker(EnvironmentImpl envImpl)
  throws DatabaseException {

  if (envImpl.isNoLocking()) {
      return new BasicLocker(envImpl);
  } else {
      return new AutoTxn(envImpl, new TransactionConfig());
  }
    }
View Full Code Here

Examples of com.sleepycat.je.txn.BasicLocker

            return idDatabase;
        } else if (dbId.equals(nameDatabase.getId())) {
            /* We're looking for the name database itself. */
            return nameDatabase;
        } else {
            Locker locker = new BasicLocker(envImpl);
            if (lockTimeout != -1) {
                locker.setLockTimeout(lockTimeout);
            }

            /* Scan the tree for this db. */
            CursorImpl idCursor = null;
            DatabaseImpl foundDbImpl = null;

      /*
       * Retry in the face of lock timeouts.  Deadlocks may be due to
       * conflicts with modifyDbRoot.
       */
      while (true) {
                idCursor = new CursorImpl(idDatabase, locker);
                idCursor.setAllowEviction(allowEviction);
    try {
        DatabaseEntry keyDbt = new DatabaseEntry(dbId.getBytes());
        boolean found =
      (idCursor.searchAndPosition
       (keyDbt, new DatabaseEntry(), SearchMode.SET,
        LockType.READ) &
       CursorImpl.FOUND) != 0;
        if (found) {
      MapLN mapLN = (MapLN)
          idCursor.getCurrentLNAlreadyLatched(LockType.READ);
                        assert mapLN != null; /* Should be locked. */
                        foundDbImpl =  mapLN.getDatabase();
                    }
                    break;
    } catch (DeadlockException DE) {
        idCursor.close();
        locker.operationEnd(false);
        locker = new BasicLocker(envImpl);
        if (lockTimeout != -1) {
      locker.setLockTimeout(lockTimeout);
        }
        idCursor = new CursorImpl(idDatabase, locker);
                    idCursor.setAllowEviction(allowEviction);
        continue;
    } finally {
        idCursor.releaseBIN();
        idCursor.close();
        locker.operationEnd(true);
    }
      }

            /*
             * Set the debugging name in the databaseImpl, but only after
View Full Code Here

Examples of com.sleepycat.je.txn.BasicLocker

       */
      Locker locker = null;
      CursorImpl cursor = null;
            LockType lockType = LockType.NONE;
      try {
    locker = new BasicLocker(envImpl);
    cursor = new CursorImpl(idDatabase, locker);
    if (cursor.positionFirstOrLast(true, null)) {
                    MapLN mapLN = (MapLN) cursor.
                        getCurrentLNAlreadyLatched(lockType);

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.