Examples of LNFileReader


Examples of com.sleepycat.je.log.LNFileReader

            e.addErrorMessage("SyncDataSet: " + dataSetName +
                              ", SyncProcessor: " + processor.getName());
            throw e;
        }

        LNFileReader reader = new LNFileReader(envImpl,
                                               readBufferSize,
                                               readStart,
                                               true,
                                               DbLsn.NULL_LSN,
                                               finishLsn,
                                               null,
                                               DbLsn.NULL_LSN);
       
        for (LogEntryType entryType : targetTypes) {
            reader.addTargetType(entryType);
        }

        return reader;
    }
View Full Code Here

Examples of com.sleepycat.je.log.LNFileReader

        long firstActiveLsn = info.firstActiveLsn;
        long lastUsedLsn = info.lastUsedLsn;
        long endOfFileLsn = info.nextAvailableLsn;

        /* Set up a reader to pick up target log entries from the log. */
        LNFileReader reader =
            new LNFileReader(envImpl, readBufferSize, lastUsedLsn,
                             false, endOfFileLsn, firstActiveLsn, null,
                             info.checkpointEndLsn);

        for (LogEntryType lt: logTypes) {
            reader.addTargetType(lt);
        }

        DbTree dbMapTree = envImpl.getDbTree();

        /*
         * See RollbackTracker.java for details on replication rollback
         * periods.  Standalone recovery must handle replication rollback at
         * recovery, because we might be opening a replicated environment in a
         * read-only, non-replicated way for use by a command line utility.
         * Even though the utility will not write invisible bits, it will need
         * to ensure that all btree nodes are in the proper state, and reflect
         * any rollback related changes.
         *
         * The rollbackScanner is a sort of cursor that acts with the known
         * state of the rollback period detection.
         *
         * We let the tracker know if it is the first pass or not, in order
         * to support some internal tracker assertions.
         */
        rollbackTracker.setFirstPass(firstUndoPass);
        final Scanner rollbackScanner =  rollbackTracker.getScanner();

        try {

            /*
             * Iterate over the target LNs and commit records, constructing the
             * tree.
             */
            while (reader.readNextEntry()) {
                counter.incNumRead();
                if (reader.isLN()) {

                    /* Get the txnId from the log entry. */
                    Long txnId = reader.getTxnId();

                    /* Skip past this, no need to undo non-txnal LNs. */
                    if (txnId == null) {
                        continue;
                    }

                    if (rollbackScanner.positionAndCheck(reader.getLastLsn(),
                                                         txnId)) {
                        /*
                         * If an LN is in the rollback period and was part of a
                         * rollback, let the rollback scanner decide how it
                         * should be handled. This does not include LNs that
                         * were explicitly aborted.
                         */
                        rollbackScanner.rollback(txnId, reader, tracker);
                        continue;
                    }

                    /* This LN is part of a committed txn. */
                    if (committedTxnIds.containsKey(txnId)) {
                        continue;
                    }

                    /* This LN is part of a prepared txn. */
                    if (preparedTxns.get(txnId) != null) {
                        resurrectedLsns.add(reader.getLastLsn());
                        continue;
                    }

                    /*
                     * This LN is part of a uncommitted, unaborted
                     * replicated txn.
                     */
                    if (isReplicatedUncommittedLN(reader, txnId)) {
                        createReplayTxn(txnId);
                        resurrectedLsns.add(reader.getLastLsn());
                        continue;
                    }

                    undoUncommittedLN(reader, dbMapTree);
                    counter.incNumProcessed();

                } else if (reader.isPrepare()) {
                    handlePrepare(reader);
                    counter.incNumAux();
                } else if (reader.isAbort()) {
                    /* The entry just read is an abort record. */
                    abortedTxnIds.add(Long.valueOf(reader.getTxnAbortId()));
                    counter.incNumAux();
                } else if (reader.isCommit()) {

                    /*
                     * Sanity check that the commit does not interfere with the
                     * rollback period. Since the reader includes commits only
                     * on the first pass, the cost of the check is confined to
                     * that pass, and is very low if there is no rollback
                     * period.
                     */
                    rollbackTracker.checkCommit(reader.getLastLsn(),
                                                reader.getTxnCommitId());

                    committedTxnIds.put(Long.valueOf(reader.getTxnCommitId()),
                            Long.valueOf(reader.getLastLsn()));
                    counter.incNumAux();

                } else if (reader.isRollbackStart()) {
                    rollbackTracker.register
                        ((RollbackStart) reader.getMainItem(),
                         reader.getLastLsn());
                    counter.incNumAux();
                } else if (reader.isRollbackEnd()) {
                    rollbackTracker.register((RollbackEnd) reader.getMainItem(),
                                             reader.getLastLsn());
                    counter.incNumAux();
                } else {
                    throw new EnvironmentFailureException
                        (envImpl,
                         EnvironmentFailureReason.UNEXPECTED_STATE,
                         "LNreader should not have picked up type " +
                         reader.dumpCurrentHeader());
                }
            } /* while */
            counter.setRepeatIteratorReads(reader.getNRepeatIteratorReads());
            rollbackTracker.singlePassSetInvisible();

        } catch (RuntimeException e) {
            traceAndThrowException(reader.getLastLsn(), "undoLNs", e);
        }
    }
View Full Code Here

Examples of com.sleepycat.je.log.LNFileReader

         * belong to replicated, uncommitted txns.  These LNs still need to be
         * processed and can live in the log between the firstActive LSN and
         * the checkpointStart LSN, so we start the LNFileReader at the First
         * Active LSN.
         */
        LNFileReader reader =
            new LNFileReader(envImpl, readBufferSize, firstActiveLsn,
                             true, DbLsn.NULL_LSN, endOfFileLsn, null,
                             info.checkpointEndLsn);

        for (LogEntryType lt : lnTypes) {
            reader.addTargetType(lt);
        }

        DbTree dbMapTree = envImpl.getDbTree();
        TreeLocation location = new TreeLocation();

        try {

            /*
             * Iterate over the target LNs and construct in-memory tree.
             */
            while (reader.readNextEntry()) {
                counter.incNumRead();
                RedoEligible eligible = eligibleForRedo(reader);

                if (!eligible.isEligible) {
                    continue;
                }

                /*
                 * We're doing a redo. Invoke the evictor in this loop to
                 * reduce memory consumption.
                 */
                envImpl.invokeEvictor();

                DatabaseId dbId = reader.getDatabaseId();
                DatabaseImpl db = dbMapTree.getDb(dbId);

                /*
                 * Database may be null if it's been deleted. Only redo for
                 * extant databases.
                 */
                if (db == null) {
                    counter.incNumDeleted();
                    continue;
                }
                try {
                    LNLogEntry lnEntry = reader.getLNLogEntry();
                    lnEntry.postFetchInit(db);
                    LN ln = lnEntry.getLN();

                    long logLsn = reader.getLastLsn();
                    long treeLsn = DbLsn.NULL_LSN;

                    counter.incNumProcessed();
                    treeLsn = redoOneLN(reader, ln, lnEntry.getKey(), logLsn,
                                        dbId, db, eligible, location);

                    /*
                     * Redo utilization info irregardless of whether the db
                     * is deleted or not.
                     */
                    redoUtilizationInfo
                        (logLsn, treeLsn, eligible.commitLsn,
                         eligible.isCommitted(),
                         reader.getAbortLsn(),
                         reader.getAbortKnownDeleted(),
                         reader.getLastEntrySize(),
                         ln, db);
                } finally {
                    dbMapTree.releaseDb(db);
                }
            }
            counter.setRepeatIteratorReads(reader.getNRepeatIteratorReads());
        } catch (Exception e) {
            traceAndThrowException(reader.getLastLsn(), "redoLns", e);
        }
    }
View Full Code Here

Examples of com.sleepycat.je.log.LNFileReader

  long firstActiveLsn = info.firstActiveLsn;
  long lastUsedLsn = info.lastUsedLsn;
  long endOfFileLsn = info.nextAvailableLsn;
        /* Set up a reader to pick up target log entries from the log. */
        LNFileReader reader =
            new LNFileReader(env, readBufferSize, lastUsedLsn,
                             false, endOfFileLsn, firstActiveLsn, null);

        Iterator iter = lnTypes.iterator();
        while (iter.hasNext()) {
            LogEntryType lnType = (LogEntryType) iter.next();
            reader.addTargetType(lnType);
        }

        Map countedFileSummaries = new HashMap(); // TxnNodeId -> file number
        Set countedAbortLsnNodes = new HashSet(); // set of TxnNodeId

        DbTree dbMapTree = env.getDbMapTree();
        TreeLocation location = new TreeLocation();
        try {

            /*
             * Iterate over the target LNs and commit records, constructing
             * tree.
             */
            while (reader.readNextEntry()) {
                if (reader.isLN()) {

                    /* Get the txnId from the log entry. */
                    Long txnId = reader.getTxnId();

                    /*
                     * If this node is not in a committed txn, examine it to
                     * see if it should be undone.
                     */
                    if (!committedTxnIds.contains(txnId)) {

      /*
       * Invoke the evictor to reduce memory consumption.
       */
      env.invokeEvictor();

      LN ln = reader.getLN();
      long logLsn = reader.getLastLsn();
      long abortLsn = reader.getAbortLsn();
      boolean abortKnownDeleted =
          reader.getAbortKnownDeleted();
      DatabaseId dbId = reader.getDatabaseId();
      DatabaseImpl db = dbMapTree.getDb(dbId);
                       
      /* Database may be null if it's been deleted. */
      if (db != null) {
          ln.postFetchInit(db, logLsn);
          try {
                                undo(detailedTraceLevel,
                                     db,
                                     location,
                                     ln,
                                     reader.getKey(),
                                     reader.getDupTreeKey(),
                                     logLsn,
                                     abortLsn,
                                     abortKnownDeleted,
                                     info,
                                     true);
          } finally {
        if (location.bin != null) {
            location.bin.releaseLatchIfOwner();
        }
          }
          /* Undo utilization info. */
          TxnNodeId txnNodeId =
        new TxnNodeId(reader.getNodeId(),
                txnId.longValue());
          undoUtilizationInfo(ln, logLsn, abortLsn,
            abortKnownDeleted,
            txnNodeId,
            countedFileSummaries,
            countedAbortLsnNodes);

          /*
           * Add any db that we encounter LN's for because
           * they'll be part of the in-memory tree and
           * therefore should be included in the INList
           * rebuild.
           */
          inListRebuildDbIds.add(dbId);
      }
        }
                } else if (reader.isPrepare()) {

        /*
         * The entry just read is a prepare record.  There should
         * be no lock conflicts during recovery, but just in case
         * there are, we set the locktimeout to 0.
         */
        long prepareId = reader.getTxnPrepareId();
        Long prepareIdL = new Long(prepareId);
        if (!committedTxnIds.contains(prepareIdL) &&
      !abortedTxnIds.contains(prepareIdL)) {
      TransactionConfig txnConf = new TransactionConfig();
      Txn preparedTxn = new Txn(env, txnConf, prepareId);
      preparedTxn.setLockTimeout(0);
      preparedTxns.put(prepareIdL, preparedTxn);
      env.getTxnManager().registerXATxn
          (reader.getTxnPrepareXid(), preparedTxn, true);
      Tracer.trace(Level.INFO, env,
             "Found unfinished prepare record: id: " +
             reader.getTxnPrepareId() +
             " Xid: " + reader.getTxnPrepareXid());
        }
                } else if (reader.isAbort()) {
        /* The entry just read is an abort record. */
        abortedTxnIds.add(new Long(reader.getTxnAbortId()));
    } else {
                    /* The entry just read is a commit record. */
                    committedTxnIds.add(new Long(reader.getTxnCommitId()));
                }
            }
            info.nRepeatIteratorReads += reader.getNRepeatIteratorReads();
        } catch (Exception e) {
            traceAndThrowException(reader.getLastLsn(), "undoLNs", e);
        }
    }
View Full Code Here

Examples of com.sleepycat.je.log.LNFileReader

        throws IOException, DatabaseException {

  long endOfFileLsn = info.nextAvailableLsn;
  long rollForwardLsn = info.checkpointStartLsn;
        /* Set up a reader to pick up target log entries from the log */
        LNFileReader reader =
            new LNFileReader(env, readBufferSize, rollForwardLsn,
                             true, DbLsn.NULL_LSN, endOfFileLsn, null);

        Iterator iter = lnTypes.iterator();
        while (iter.hasNext()) {
            LogEntryType lnType = (LogEntryType) iter.next();
            reader.addTargetType(lnType);
        }

        Set countedAbortLsnNodes = new HashSet(); // set of TxnNodeId

        DbTree dbMapTree = env.getDbMapTree();
        TreeLocation location = new TreeLocation();
        try {

            /* Iterate over the target LNs and construct in- memory tree. */
            while (reader.readNextEntry()) {
                if (reader.isLN()) {

                    /* Get the txnId from the log entry. */
                    Long txnId = reader.getTxnId();
               
                    /*
                     * If this LN is in a committed txn, or if it's a
                     * non-transactional LN, redo it.
                     */
        boolean processThisLN = false;
        boolean lnIsCommitted = false;
        boolean lnIsPrepared = false;
        Txn preparedTxn = null;
        if (txnId == null) {
      processThisLN = true;
        } else {
      lnIsCommitted = committedTxnIds.contains(txnId);
      if (!lnIsCommitted) {
          preparedTxn = (Txn) preparedTxns.get(txnId);
          lnIsPrepared = preparedTxn != null;
      }
      if (lnIsCommitted || lnIsPrepared) {
          processThisLN = true;
      }
        }
        if (processThisLN) {

                        /* Invoke the evictor to reduce memory consumption. */
                        env.invokeEvictor();

                        LN ln = reader.getLN();
                        DatabaseId dbId = reader.getDatabaseId();
                        DatabaseImpl db = dbMapTree.getDb(dbId);
                        long logLsn = reader.getLastLsn();
                        long treeLsn = DbLsn.NULL_LSN;

                        /* Database may be null if it's been deleted. */
                        if (db != null) {
                            ln.postFetchInit(db, logLsn);

          if (preparedTxn != null) {
        preparedTxn.addLogInfo(logLsn);

        /*
         * We're reconstructing a prepared, but not
         * finished, transaction.  We know that there
         * was a write lock on this LN since it exists
         * in the log under this txnId.
         */
        preparedTxn.lock(ln.getNodeId(),
             LockType.WRITE,
             db);
        preparedTxn.setPrepared(true);
          }

                            treeLsn = redo(db,
                                           location,
                                           ln,
                                           reader.getKey(),
                                           reader.getDupTreeKey(),
                                           logLsn,
                                           info);

                            /*
                             * Add any db that we encounter LN's for because
                             * they'll be part of the in-memory tree and
                             * therefore should be included in the INList
                             * rebuild.
                             */
                            inListRebuildDbIds.add(dbId);
                        }

                        /* Redo utilization info. */
                        TxnNodeId txnNodeId = null;
                        if (txnId != null) {
                            txnNodeId = new TxnNodeId(reader.getNodeId(),
                                                      txnId.longValue());
                        }
                        redoUtilizationInfo(logLsn, treeLsn,
                                            reader.getAbortLsn(),
                                            reader.getAbortKnownDeleted(),
                                            ln, txnNodeId,
                                            countedAbortLsnNodes);
                    }
                }
            }
            info.nRepeatIteratorReads += reader.getNRepeatIteratorReads();
        } catch (Exception e) {
            traceAndThrowException(reader.getLastLsn(), "redoLns", e);
        }
    }
View Full Code Here

Examples of com.sleepycat.je.log.LNFileReader

        DbConfigManager cm = getConfigManager();
        int readBufferSize =
            cm.getInt(EnvironmentParams.LOG_ITERATOR_READ_SIZE);
        long endOfLogLsn = fileManager.getNextLsn();
        boolean forwards = config.getForwards();
        LNFileReader reader = null;
        if (forwards) {
            if (endPosition > endOfLogLsn) {
                throw new IllegalArgumentException
                    ("endPosition (" + endPosition +
                     ") is past the end of the log on a forewards scan.");
            }
            reader = new LNFileReader(this,
                                      readBufferSize,
                                      startPosition,  /*startLsn*/
                                      true,           /*forwards*/
                                      endPosition,    /*endOfFileLsn*/
                                      DbLsn.NULL_LSN, /*finishLsn*/
                                      null,           /*singleFileNum*/
                                      DbLsn.NULL_LSN);/*ckptEnd*/
        } else {
            if (startPosition > endOfLogLsn) {
                throw new IllegalArgumentException
                    ("startPosition (" + startPosition +
                     ") is past the end of the log on a backwards scan.");
            }
            reader = new LNFileReader(this,
                                      readBufferSize,
                                      startPosition,  /*startLsn*/
                                      false,          /*forwards*/
                                      endOfLogLsn,    /*endOfFileLsn*/
                                      endPosition,    /*finishLsn*/
                                      null,           /*singleFileNum*/
                                      DbLsn.NULL_LSN);/*ckptEnd*/
        }
        reader.addTargetType(LogEntryType.LOG_LN_TRANSACTIONAL);
        reader.addTargetType(LogEntryType.LOG_LN);
        reader.addTargetType(LogEntryType.LOG_DEL_DUPLN_TRANSACTIONAL);
        reader.addTargetType(LogEntryType.LOG_DEL_DUPLN);

        Map<DatabaseId,String> dbNameMap = dbMapTree.getDbNamesAndIds();

        while (reader.readNextEntry()) {
            if (reader.isLN()) {
                LN theLN = reader.getLN();
                byte[] theKey = reader.getKey();

                DatabaseId dbId = reader.getDatabaseId();
                String dbName = dbNameMap.get(dbId);
                if (DbTree.isReservedDbName(dbName)) {
                    continue;
                }

View Full Code Here

Examples of com.sleepycat.je.log.LNFileReader

  long firstActiveLsn = info.firstActiveLsn;
  long lastUsedLsn = info.lastUsedLsn;
  long endOfFileLsn = info.nextAvailableLsn;
        /* Set up a reader to pick up target log entries from the log. */
        LNFileReader reader =
            new LNFileReader(env, readBufferSize, lastUsedLsn,
                             false, endOfFileLsn, firstActiveLsn, null);

        Iterator iter = lnTypes.iterator();
        while (iter.hasNext()) {
            LogEntryType lnType = (LogEntryType) iter.next();
            reader.addTargetType(lnType);
        }

        Map countedFileSummaries = new HashMap(); // TxnNodeId -> file number
        Set countedAbortLsnNodes = new HashSet(); // set of TxnNodeId

        DbTree dbMapTree = env.getDbMapTree();
        TreeLocation location = new TreeLocation();
        try {

            /*
             * Iterate over the target LNs and commit records, constructing
             * tree.
             */
            while (reader.readNextEntry()) {
                if (reader.isLN()) {

                    /* Get the txnId from the log entry. */
                    Long txnId = reader.getTxnId();

                    /*
                     * If this node is not in a committed txn, examine it to
                     * see if it should be undone.
                     */
                    if (txnId != null &&
      !committedTxnIds.contains(txnId)) {

      /*
       * Invoke the evictor to reduce memory consumption.
       */
      env.invokeEvictor();

      LN ln = reader.getLN();
      long logLsn = reader.getLastLsn();
      long abortLsn = reader.getAbortLsn();
      boolean abortKnownDeleted =
          reader.getAbortKnownDeleted();
      DatabaseId dbId = reader.getDatabaseId();
      DatabaseImpl db = dbMapTree.getDb(dbId);
                       
      /* Database may be null if it's been deleted. */
      if (db != null) {
          ln.postFetchInit(db, logLsn);
          try {
                                undo(detailedTraceLevel,
                                     db,
                                     location,
                                     ln,
                                     reader.getKey(),
                                     reader.getDupTreeKey(),
                                     logLsn,
                                     abortLsn,
                                     abortKnownDeleted,
                                     info,
                                     true);
          } finally {
        if (location.bin != null) {
            location.bin.releaseLatchIfOwner();
        }
          }
          /* Undo utilization info. */
          TxnNodeId txnNodeId =
        new TxnNodeId(reader.getNodeId(),
                txnId.longValue());
          undoUtilizationInfo(ln, logLsn, abortLsn,
            abortKnownDeleted,
            txnNodeId,
            countedFileSummaries,
            countedAbortLsnNodes);

          /*
           * Add any db that we encounter LN's for because
           * they'll be part of the in-memory tree and
           * therefore should be included in the INList
           * rebuild.
           */
          inListRebuildDbIds.add(dbId);
      }
        }
                } else if (reader.isPrepare()) {

        /*
         * The entry just read is a prepare record.  There should
         * be no lock conflicts during recovery, but just in case
         * there are, we set the locktimeout to 0.
         */
        long prepareId = reader.getTxnPrepareId();
        Long prepareIdL = new Long(prepareId);
        if (!committedTxnIds.contains(prepareIdL) &&
      !abortedTxnIds.contains(prepareIdL)) {
      TransactionConfig txnConf = new TransactionConfig();
      Txn preparedTxn = new Txn(env, txnConf, prepareId);
      preparedTxn.setLockTimeout(0);
      preparedTxns.put(prepareIdL, preparedTxn);
      env.getTxnManager().registerXATxn
          (reader.getTxnPrepareXid(), preparedTxn, true);
      Tracer.trace(Level.INFO, env,
             "Found unfinished prepare record: id: " +
             reader.getTxnPrepareId() +
             " Xid: " + reader.getTxnPrepareXid());
        }
                } else if (reader.isAbort()) {
        /* The entry just read is an abort record. */
        abortedTxnIds.add(new Long(reader.getTxnAbortId()));
    } else {
                    /* The entry just read is a commit record. */
                    committedTxnIds.add(new Long(reader.getTxnCommitId()));
                }
            }
            info.nRepeatIteratorReads += reader.getNRepeatIteratorReads();
        } catch (Exception e) {
            traceAndThrowException(reader.getLastLsn(), "undoLNs", e);
        }
    }
View Full Code Here

Examples of com.sleepycat.je.log.LNFileReader

        throws IOException, DatabaseException {

  long endOfFileLsn = info.nextAvailableLsn;
  long rollForwardLsn = info.checkpointStartLsn;
        /* Set up a reader to pick up target log entries from the log */
        LNFileReader reader =
            new LNFileReader(env, readBufferSize, rollForwardLsn,
                             true, DbLsn.NULL_LSN, endOfFileLsn, null);

        Iterator iter = lnTypes.iterator();
        while (iter.hasNext()) {
            LogEntryType lnType = (LogEntryType) iter.next();
            reader.addTargetType(lnType);
        }

        Set countedAbortLsnNodes = new HashSet(); // set of TxnNodeId

        DbTree dbMapTree = env.getDbMapTree();
        TreeLocation location = new TreeLocation();
        try {

            /* Iterate over the target LNs and construct in- memory tree. */
            while (reader.readNextEntry()) {
                if (reader.isLN()) {

                    /* Get the txnId from the log entry. */
                    Long txnId = reader.getTxnId();
               
                    /*
                     * If this LN is in a committed txn, or if it's a
                     * non-transactional LN, redo it.
                     */
        boolean processThisLN = false;
        boolean lnIsCommitted = false;
        boolean lnIsPrepared = false;
        Txn preparedTxn = null;
        if (txnId == null) {
      processThisLN = true;
        } else {
      lnIsCommitted = committedTxnIds.contains(txnId);
      if (!lnIsCommitted) {
          preparedTxn = (Txn) preparedTxns.get(txnId);
          lnIsPrepared = preparedTxn != null;
      }
      if (lnIsCommitted || lnIsPrepared) {
          processThisLN = true;
      }
        }
        if (processThisLN) {

                        /* Invoke the evictor to reduce memory consumption. */
                        env.invokeEvictor();

                        LN ln = reader.getLN();
                        DatabaseId dbId = reader.getDatabaseId();
                        DatabaseImpl db = dbMapTree.getDb(dbId);
                        long logLsn = reader.getLastLsn();
                        long treeLsn = DbLsn.NULL_LSN;

                        /* Database may be null if it's been deleted. */
                        if (db != null) {
                            ln.postFetchInit(db, logLsn);

          if (preparedTxn != null) {
        preparedTxn.addLogInfo(logLsn);

        /*
         * We're reconstructing a prepared, but not
         * finished, transaction.  We know that there
         * was a write lock on this LN since it exists
         * in the log under this txnId.
         */
        preparedTxn.lock
                                    (ln.getNodeId(), LockType.WRITE,
                                     false /*noWait*/, db);
        preparedTxn.setPrepared(true);
          }

                            treeLsn = redo(db,
                                           location,
                                           ln,
                                           reader.getKey(),
                                           reader.getDupTreeKey(),
                                           logLsn,
                                           info);

                            /*
                             * Add any db that we encounter LN's for because
                             * they'll be part of the in-memory tree and
                             * therefore should be included in the INList
                             * rebuild.
                             */
                            inListRebuildDbIds.add(dbId);
                        }

                        /* Redo utilization info. */
                        TxnNodeId txnNodeId = null;
                        if (txnId != null) {
                            txnNodeId = new TxnNodeId(reader.getNodeId(),
                                                      txnId.longValue());
                        }
                        redoUtilizationInfo(logLsn, treeLsn,
                                            reader.getAbortLsn(),
                                            reader.getAbortKnownDeleted(),
                                            ln, txnNodeId,
                                            countedAbortLsnNodes);
                    }
                }
            }
            info.nRepeatIteratorReads += reader.getNRepeatIteratorReads();
        } catch (Exception e) {
            traceAndThrowException(reader.getLastLsn(), "redoLns", e);
        }
    }
View Full Code Here

Examples of com.sleepycat.je.log.LNFileReader

        long firstActiveLsn = info.firstActiveLsn;
        long lastUsedLsn = info.lastUsedLsn;
        long endOfFileLsn = info.nextAvailableLsn;

        /* Set up a reader to pick up target log entries from the log. */
        LNFileReader reader =
            new LNFileReader(envImpl, readBufferSize, lastUsedLsn,
                             false, endOfFileLsn, firstActiveLsn, null,
                             info.checkpointEndLsn);

        for (LogEntryType lt: logTypes) {
            reader.addTargetType(lt);
        }

        Map<TxnNodeId,Long> countedFileSummaries =
            new HashMap<TxnNodeId,Long>(); // TxnNodeId -> file number
        Set<TxnNodeId> countedAbortLsnNodes = new HashSet<TxnNodeId>();

        DbTree dbMapTree = envImpl.getDbTree();

        /*
         * See RollbackTracker.java for details on replication rollback
         * periods.  Standalone recovery must handle replication rollback at
         * recovery, because we might be opening a replicated environment in a
         * read-only, non-replicated way for use by a command line utility.
         * Even though the utility will not write invisible bits, it will need
         * to ensure that all btree nodes are in the proper state, and reflect
         * any rollback related changes.
         *
         * The rollbackScanner is a sort of cursor that acts with the known
         * state of the rollback period detection.
         *
         * We let the tracker know if it is the first pass or not, in order
         * to support some internal tracker assertions.
         */
        rollbackTracker.setFirstPass(firstUndoPass);
        final Scanner rollbackScanner =  rollbackTracker.getScanner();

        try {

            /*
             * Iterate over the target LNs and commit records, constructing the
             * tree.
             */
            while (reader.readNextEntry()) {
                if (reader.isLN()) {

                    /* Get the txnId from the log entry. */
                    Long txnId = reader.getTxnId();

                    /* Skip past this, no need to undo non-txnal LNs. */
                    if (txnId == null) {
                        continue;
                    }

                    if (rollbackScanner.positionAndCheck(reader.getLastLsn(),
                                                         txnId)) {
                        /*
                         * If an LN is in the rollback period and was part of a
                         * rollback, let the rollback scanner decide how it
                         * should be handled. This does not include LNs that
                         * were explicitly aborted.
                         */
                        rollbackScanner.rollback(txnId, reader, tracker);
                        continue;
                    }

                    /* This LN is part of a committed txn. */
                    if (committedTxnIds.containsKey(txnId)) {
                        continue;
                    }

                    /* This LN is part of a prepared txn. */
                    if (preparedTxns.get(txnId) != null) {
                        resurrectedLsns.add(reader.getLastLsn());
                        continue;
                    }

                    /*
                     * This LN is part of a uncommitted, unaborted
                     * replicated txn.
                     */
                    if (isReplicatedUncommittedLN(reader, txnId)) {
                        createReplayTxn(txnId);
                        resurrectedLsns.add(reader.getLastLsn());
                        continue;
                    }

                    undoUncommittedLN(reader, dbMapTree, txnId,
                                      countedFileSummaries,
                                      countedAbortLsnNodes);

                } else if (reader.isPrepare()) {
                    handlePrepare(reader);
                } else if (reader.isAbort()) {
                    /* The entry just read is an abort record. */
                    abortedTxnIds.add(Long.valueOf(reader.getTxnAbortId()));
                } else if (reader.isCommit()) {

                    /*
                     * Sanity check that the commit does not interfere with the
                     * rollback period. Since the reader includes commits only
                     * on the first pass, the cost of the check is confined to
                     * that pass, and is very low if there is no rollback
                     * period.
                     */
                    rollbackTracker.checkCommit(reader.getLastLsn(),
                                                reader.getTxnCommitId());

                    committedTxnIds.put(Long.valueOf(reader.getTxnCommitId()),
                            Long.valueOf(reader.getLastLsn()));

                } else if (reader.isRollbackStart()) {
                    rollbackTracker.register
                        ((RollbackStart) reader.getMainItem(),
                         reader.getLastLsn());
                } else if (reader.isRollbackEnd()) {
                    rollbackTracker.register((RollbackEnd) reader.getMainItem(),
                                             reader.getLastLsn());
                } else {
                    throw new EnvironmentFailureException
                        (envImpl,
                         EnvironmentFailureReason.UNEXPECTED_STATE,
                         "LNreader should not have picked up type " +
                         reader.dumpCurrentHeader());
                }
            } /* while */

            info.nRepeatIteratorReads += reader.getNRepeatIteratorReads();
            rollbackTracker.singlePassSetInvisible();

        } catch (RuntimeException e) {
            traceAndThrowException(reader.getLastLsn(), "undoLNs", e);
        }
    }
View Full Code Here

Examples of com.sleepycat.je.log.LNFileReader

         * belong to replicated, uncommitted txns.  These LNs still need to be
         * processed and can live in the log between the firstActive LSN and
         * the checkpointStart LSN, so we start the LNFileReader at the First
         * Active LSN.
         */
        LNFileReader reader =
            new LNFileReader(envImpl, readBufferSize, firstActiveLsn,
                             true, DbLsn.NULL_LSN, endOfFileLsn, null,
                             info.checkpointEndLsn);

        for (LogEntryType lt : lnTypes) {
            reader.addTargetType(lt);
        }

        Set<TxnNodeId> countedAbortLsnNodes = new HashSet<TxnNodeId>();
        DbTree dbMapTree = envImpl.getDbTree();
        TreeLocation location = new TreeLocation();

        try {

            /*
             * Iterate over the target LNs and construct in-memory tree.
             */
            while (reader.readNextEntry()) {
                RedoEligible eligible = eligibleForRedo(reader);

                if (!eligible.isEligible) {
                    continue;
                }

                /*
                 * We're doing a redo. Invoke the evictor in this loop to
                 * reduce memory consumption.
                 */
                envImpl.invokeEvictor();

                LN ln = reader.getLN();
                DatabaseId dbId = reader.getDatabaseId();
                DatabaseImpl db = dbMapTree.getDb(dbId);
                try {
                    long logLsn = reader.getLastLsn();
                    long treeLsn = DbLsn.NULL_LSN;

                    /*
                     * Database may be null if it's been deleted. Only redo for
                     * extant databases.
                     */
                    if (db != null) {
                        treeLsn = redoOneLN(reader, ln, logLsn, dbId, db,
                                            eligible, location);

                        /*
                         * Redo utilization info irregardless of whether the db
                         * is deleted or not.
                         */
                        TxnNodeId txnNodeId = null;
                        Long txnId = reader.getTxnId();
                        if (txnId != null) {
                            txnNodeId =
                                new TxnNodeId(reader.getNodeId(), txnId);
                        }

                        redoUtilizationInfo
                            (logLsn, treeLsn, eligible.commitLsn,
                             reader.getAbortLsn(),
                             reader.getAbortKnownDeleted(),
                             reader.getLastEntrySize(),
                             reader.getKey(),
                             ln, db, txnNodeId, countedAbortLsnNodes);
                    }
                } finally {
                    dbMapTree.releaseDb(db);
                }
            }
            info.nRepeatIteratorReads += reader.getNRepeatIteratorReads();
        } catch (Exception e) {
            traceAndThrowException(reader.getLastLsn(), "redoLns", e);
        }
    }
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.