Exemple #1
0
VOID
LfsGetActiveLsnRangeInternal (
    IN PLFCB Lfcb,
    OUT PLSN OldestLsn,
    OUT PLSN NextLsn
    )
/*++

Routine Description:

    Returns back the range that is active in the logfile from the oldest valid LSN to
    where the next active LSN will be.

Arguments:

    Lfcb - the logfile lfcb

    OldestLsn - returns the oldest active lsn

    NextLsn - returns the projected next lsn to be used

Return Value:

    None

--*/
{
    PLBCB ActiveLbcb;

    PAGED_CODE();

    //
    //  Calculate what the next LSN will be using the regular logic
    //  1) if there is no active lbcb then it will be the first offset on the next
    //     page (the seq. number will increment if it wraps)
    //  2) Otherwise its the Lsn contained in the top of the active lbcb list
    //

    if (!IsListEmpty( &Lfcb->LbcbActive )) {
        ActiveLbcb = CONTAINING_RECORD( Lfcb->LbcbActive.Flink,
                                        LBCB,
                                        ActiveLinks );
        NextLsn->QuadPart = LfsComputeLsnFromLbcb( Lfcb, ActiveLbcb );
    } else {

        if (FlagOn( Lfcb->Flags, LFCB_REUSE_TAIL)) {
            NextLsn->QuadPart = LfsFileOffsetToLsn( Lfcb, Lfcb->NextLogPage + Lfcb->ReusePageOffset, Lfcb->SeqNumber );
        } else if (Lfcb->NextLogPage != Lfcb->FirstLogPage) {
            NextLsn->QuadPart = LfsFileOffsetToLsn( Lfcb, Lfcb->NextLogPage + Lfcb->LogPageDataOffset, Lfcb->SeqNumber );
        } else {
            NextLsn->QuadPart = LfsFileOffsetToLsn( Lfcb, Lfcb->NextLogPage + Lfcb->LogPageDataOffset, Lfcb->SeqNumber + 1 );
        }
    }

    OldestLsn->QuadPart = Lfcb->OldestLsn.QuadPart;
}
Exemple #2
0
BOOLEAN
LfsFindNextLsn (
    IN PLFCB Lfcb,
    IN PLFS_RECORD_HEADER RecordHeader,
    OUT PLSN Lsn
    )

/*++

Routine Description:

    This routine takes as a starting point the log record header of an
    Lsn in the log file.  It searches for the next Lsn in the file and
    returns that value in the 'Lsn' argument.  The boolean return value
    indicates whether there is another Lsn in the file.

Arguments:

    Lfcb - This is the file control block for the log file.

    RecordHeader - This is the log record for the Lsn starting point.

    Lsn - This supplies the address to store the next Lsn, if found.

Return Value:

    BOOLEAN - Indicates whether the next Lsn was found.

--*/

{
    BOOLEAN FoundNextLsn;

    LONGLONG LsnOffset;
    LONGLONG EndOfLogRecord;
    LONGLONG LogHeaderOffset;

    LONGLONG SequenceNumber;

    PLFS_RECORD_PAGE_HEADER LogRecordPage;
    PBCB LogRecordPageBcb;
    BOOLEAN UsaError;

    PAGED_CODE();

    DebugTrace( +1, Dbg, "LfsFindNextLsn:  Entered\n", 0 );
    DebugTrace(  0, Dbg, "Lfcb          -> %08lx\n", Lfcb );
    DebugTrace(  0, Dbg, "Record Header -> %08lx\n", RecordHeader );

    LogRecordPageBcb = NULL;
    FoundNextLsn = FALSE;

    //
    //  Use a try-finally to facilitate cleanup.
    //

    try {

        //
        //  Find the file offset of the log page which contains the end
        //  of the log record for this Lsn.
        //

        LsnOffset = LfsLsnToFileOffset( Lfcb, RecordHeader->ThisLsn );

        LfsLsnFinalOffset( Lfcb,
                           RecordHeader->ThisLsn,
                           RecordHeader->ClientDataLength,
                           &EndOfLogRecord );

        LfsTruncateOffsetToLogPage( Lfcb, EndOfLogRecord, &LogHeaderOffset );

        //
        //  Remember the sequence number for this page.
        //

        SequenceNumber = LfsLsnToSeqNumber( Lfcb, RecordHeader->ThisLsn );

        //
        //  Remember if we wrapped.
        //

        if ( EndOfLogRecord <= LsnOffset ) {                                                                           //**** xxLeq( EndOfLogRecord, LsnOffset )

            SequenceNumber = SequenceNumber + 1;                                                                       //**** xxAdd( SequenceNumber, LfsLi1 );
        }

        //
        //  Pin the log page header for this page.
        //

        LfsPinOrMapData( Lfcb,
                         LogHeaderOffset,
                         (ULONG)Lfcb->LogPageSize,
                         FALSE,
                         FALSE,
                         FALSE,
                         &UsaError,
                         (PVOID *)&LogRecordPage,
                         &LogRecordPageBcb );

        //
        //  If the Lsn we were given was not the last Lsn on this page, then
        //  the starting offset for the next Lsn is on a quad word boundary
        //  following the last file offset for the current Lsn.  Otherwise
        //  the file offset is the start of the data on the next page.
        //

        if ( RecordHeader->ThisLsn.QuadPart == LogRecordPage->Copy.LastLsn.QuadPart ) {                                //**** xxEql( RecordHeader->ThisLsn, LogRecordPage->Copy.LastLsn )

            BOOLEAN Wrapped;

            LfsNextLogPageOffset( Lfcb,
                                  LogHeaderOffset,
                                  &LogHeaderOffset,
                                  &Wrapped );

            LsnOffset = LogHeaderOffset + Lfcb->LogPageDataOffset;                                                     //**** xxAdd( LogHeaderOffset, Lfcb->LogPageDataOffset );

            //
            //  If we wrapped, we need to increment the sequence number.
            //

            if (Wrapped) {

                SequenceNumber = SequenceNumber + 1;                                                                   //**** xxAdd( SequenceNumber, LfsLi1 );
            }

        } else {

            LiQuadAlign( EndOfLogRecord, &LsnOffset );
        }

        //
        //  Compute the Lsn based on the file offset and the sequence count.
        //

        Lsn->QuadPart = LfsFileOffsetToLsn( Lfcb, LsnOffset, SequenceNumber );

        //
        //  If this Lsn is within the legal range for the file, we return TRUE.
        //  Otherwise FALSE indicates that there are no more Lsn's.
        //

        if (LfsIsLsnInFile( Lfcb, *Lsn )) {

            FoundNextLsn = TRUE;
        }

    } finally {

        DebugUnwind( LfsFindNextLsn );

        //
        //  Unpin the log page header if held.
        //

        if (LogRecordPageBcb != NULL) {

            CcUnpinData( LogRecordPageBcb );
        }

        DebugTrace(  0, Dbg, "Lsn (Low)     -> %08lx\n", Lsn->LowPart );
        DebugTrace(  0, Dbg, "Lsn (High)    -> %08lx\n", Lsn->HighPart );
        DebugTrace( -1, Dbg, "LfsFindNextLsn:  Exit -> %08x\n", FoundNextLsn );
    }

    return FoundNextLsn;
}