Logo Search packages:      
Sourcecode: maxdb-7.5.00 version File versions

Log_Transaction::RollbackResult Log_Transaction::Rollback ( RollbackKind  rollbackKind,
tgg00_SubtransNo  SubtransNo,
Log_EntrySequence  undoStopSequence = Log_EntrySequence() 
)

The TransState becomes rollbacked and must be open before.

Parameters:
rollbackKind [in] - endOfTrans,command,subTrans
SubtransNo [in] if LOG_NIL_SUBTRANS_NO, then the complete transaction is rollbacked
undoStopSequence [in] - only used during redo
Returns:
RollbackResult

Definition at line 783 of file Log_Transaction.cpp.

References Allocator(), Data_ChainSplitSpaceBackwardRead< PAGE >::Iterator::CheckAccessMode(), command, DropRedoFile(), endOfTrans, EndOfTransHandling(), EndSubtrans(), ExecuteUndoAction(), Log_BeforeImage::GetActionType(), Log_UndoFile::GetIterator(), Log_UndoFile::GetLastUndoEntry(), Log_BeforeImage::GetSequence(), Data_ChainSplitSpaceBackwardRead< PAGE >::Iterator::Invalidate(), Data_BaseFile::IsCreated(), Log_BeforeImage::IsDeleted(), Container_Stack< T >::IsEmpty(), IsInitialized(), IsInitializedForRedo(), Log_BeforeImage::IsRollbacked(), Data_ChainSplitSpaceBackwardRead< PAGE >::Iterator::IsValid(), SAPDB_Invalidatable< T, InvalidValue >::IsValid(), Log_Transaction::Persistent::LastRedoEntrySequence, Log_Transaction::Persistent::LastUndoEntrySequence, LOG_FIRST_ENTRY_SEQUENCE, LOG_NIL_SUBTRANS_NO, logError, logFull, LogTrans_Trace, m_Context, m_pSubtransStack, m_pTrans, m_pUndoFile, m_TransType, noError, online, PopUntilSubtransFound(), Log_ActionObject::ReadPersistentFormat(), Log_BeforeImage::ReadPersistentFormat(), redoExecute, Data_SplitSpaceReader::Reset(), rollbacked, Log_BeforeImage::SetDeleted(), Log_BeforeImage::SetRollbacked(), subTrans, undoExecuteError, undoLogFull, undoNoOpenSubtrans, undoOk, undoReadError, undoWriteError, undoWrongEntry, WritePartialRollbackEntry(), Log_BeforeImage::WriteToTrace(), WriteToTrace(), Data_ChainSplitSpaceBackwardRead< PAGE >::Iterator::WriteToTrace(), and Log_ActionObject::WriteToTrace().

Referenced by Table_Table::Create(), Rst_RedoTrafficControl::ExecuteJobs(), and RedoPartialRollback().

{
    SAPDBTRACE_METHOD_DEBUG ("Log_Transaction::Rollback", LogTrans_Trace, 5);

    bool isRedoPartialRollback = undoStopSequence.IsValid(); // PTS 1113230 UH 2001-12-20
    
    if ( m_pTrans != NULL )
        m_pTrans->trError_gg00 = e_ok;
    
#   ifdef SAPDB_QUICK
    if ( online == m_TransType && ! IsInitialized() )
        RTE_Crash( SAPDBErr_Exception(__CONTEXT__, SAPDBERR_ASSERT_STATE_FAILED,
                   "Log_Transaction::Rollback: TransType / Initialization1") );
    if ( redoExecute == m_TransType && ! IsInitializedForRedo() )
        RTE_Crash( SAPDBErr_Exception(__CONTEXT__, SAPDBERR_ASSERT_STATE_FAILED,
                   "Log_Transaction::Rollback: TransType / Initialization2") );
#   endif
    
    if ( m_TransType != online
         &&
         ! isRedoPartialRollback ) // PTS 1113230 UH 2001-12-20
    {
        DropRedoFile();
        SAPDBERR_ASSERT_STATE ( m_pUndoFile != NULL );
    }

    RollbackResult Result = undoOk;

#   ifdef SAPDB_SLOW
    if ( LogTrans_Trace.TracesLevel(6) )
        WriteToTrace("CurrentTrans");

    if ( endOfTrans == rollbackKind
         &&
         SubtransNo != LOG_NIL_SUBTRANS_NO )
        RTE_Crash( SAPDBErr_Exception(
                   __FILE__, __LINE__,
                   SAPDBERR_ASSERT_STATE_FAILED,
                   "Log_Transaction::Rollback: SubtransNo is not nil") );
#   endif

    if ( endOfTrans != rollbackKind
         &&
         ! isRedoPartialRollback // PTS 1113230 UH 2001-12-20
         &&
         m_pSubtransStack->IsEmpty() )
        return undoNoOpenSubtrans;

    // ++++ TEMP LOGGING SHOULD BE OBSOLETE
    if ( m_pTrans->trState_gg00.includes (tsTempUpdated_egg00) )
    {
        if ( rollbackKind == endOfTrans )
            k54rollback_temp (*m_pTrans, mm_rollback);
        else if ( rollbackKind == command
                  &&
                  m_pTrans->trState_gg00.includes (tsFunctRollbSet_egg00) )
            k54rollback_temp (*m_pTrans, mm_nil);
        else if ( rollbackKind == subTrans )
            k54rollback_temp (*m_pTrans, mm_subtrans);
        if ( m_pTrans->trError_gg00 != e_ok )
            RTE_Crash( SAPDBErr_Exception(
                       __FILE__, __LINE__,
                       SAPDBERR_ASSERT_STATE_FAILED,
                       "Log_Transaction::Rollback: k54rollback_temp() failed") );
    }
    // ++++ TEMP LOGGING SHOULD BE OBSOLETE

    if ( ! m_Context.LastUndoEntrySequence.IsValid() )
    {
        if ( endOfTrans == rollbackKind )
            EndOfTransHandling(rollbacked);
        else
            if ( ! isRedoPartialRollback // PTS 1113230 UH 2001-12-20 
                 &&
                 ! EndSubtrans() )
                return undoNoOpenSubtrans;
        return undoOk;
    }

    SAPDBERR_ASSERT_STATE ( m_pUndoFile->IsCreated() );

    Log_EntrySequence UndoStopSequence = LOG_FIRST_ENTRY_SEQUENCE;
    Log_EntrySequence RedoStopSequence = LOG_FIRST_ENTRY_SEQUENCE;
    Log_EntrySequence PrevSequence     = LOG_FIRST_ENTRY_SEQUENCE;

    if ( isRedoPartialRollback ) // PTS 1113230 UH 2001-12-20 begin
        UndoStopSequence = undoStopSequence;
    else                         // PTS 1113230 UH 2001-12-20 end
    {
        if ( LOG_NIL_SUBTRANS_NO != SubtransNo )
        {
            m_pTrans->trSubtransId_gg00 =
                PopUntilSubtransFound (SubtransNo,
                                       UndoStopSequence,
                                       RedoStopSequence);

            SAPDBTRACE_WRITELN (LogTrans_Trace, 6,
                                "PartialRollback:SubtransNo: " << SubtransNo <<
                                (endOfTrans == rollbackKind?" eot ":command == rollbackKind?" command":" partial ")
                                << "=> UndoStopSequence: " << UndoStopSequence
                                << (UndoStopSequence == m_Context.LastUndoEntrySequence + 1 ? " => nothing to do." : ""));
    
            if ( UndoStopSequence == m_Context.LastUndoEntrySequence + 1 )
                return undoOk;
        }
    }
    
    Log_UndoFile::Iterator& iter = m_pUndoFile->GetIterator(); // PTS ? UH 2002-03-15

    m_pUndoFile->GetLastUndoEntry(Data_ForUpdate, iter); // PTS ? UH 2002-03-15

    Data_SplitSpaceReader   Reader (*iter, true); // PTS 1114994 UH 2002-04-17 added releasable
    Log_BeforeImage         BeforeImage;
    SAPDB_UInt              EntryCount = 0;

    #ifdef SAPDB_QUICK
    if ( ! iter.CheckAccessMode(Data_ForUpdate) )
    {
        iter.WriteToTrace("ErrorSplitSpace: wrong accessmode");
        BeforeImage.WriteToTrace("RollbackErrorImage");
        WriteToTrace("RollbackErrorTrans");
        RTE_Crash( SAPDBErr_Exception( __FILE__, __LINE__,
                                       SAPDBERR_ASSERT_STATE_FAILED,
                                       "Log_Transaction::Rollback() accessmode not update1" ) );
    }
    #endif

    if ( m_pTrans->trError_gg00 != e_ok ) // PTS 1117126 UH 2002-08-07
        Result = undoReadError;

    while ( iter.IsValid() )
    {
        Reader.Reset();
        bool isOK = true;
        BeforeImage.ReadPersistentFormat (Reader, isOK);
        if ( ! isOK )
        {
            Result = undoReadError;
            Kernel_VTrace() << "undo: (" << BeforeImage.GetSequence() << ") '"
                            << Log_ActionTypeStrings[BeforeImage.GetActionType()] << "'";
            WriteToTrace("RollbackErrorTrans");
            Kernel_VTrace() << "ROLLBACK-ERROR: cannot read image";
            break;
        }


        if ( LOG_FIRST_ENTRY_SEQUENCE != PrevSequence )
        {
            if ( (PrevSequence - 1) != BeforeImage.GetSequence() )
            {
                Result = undoWrongEntry;
                Kernel_VTrace() << "undo: (" << BeforeImage.GetSequence() << ") '"
                                << Log_ActionTypeStrings[BeforeImage.GetActionType()] << "'";
                iter.WriteToTrace("wrong sequences");
                BeforeImage.WriteToTrace("RollbackErrorImage");
                WriteToTrace("RollbackErrorTrans");
                Kernel_VTrace() << "ROLLBACK-ERROR: sequences not continguous";
                break;
            }
        }
        PrevSequence = BeforeImage.GetSequence();

        #ifdef SAPDB_QUICK
        if ( ! iter.CheckAccessMode(Data_ForUpdate) )
        {
            Kernel_VTrace() << "EntryCount: " << EntryCount;
            iter.WriteToTrace("ErrorSplitSpace: wrong accessmode");
            BeforeImage.WriteToTrace("RollbackErrorImage");
            WriteToTrace("RollbackErrorTrans");
            RTE_Crash( SAPDBErr_Exception( __FILE__, __LINE__,
                                           SAPDBERR_ASSERT_STATE_FAILED,
                                           "Log_Transaction::Rollback() accessmode not update1" ) );
        }
        #endif
        
        if ( BeforeImage.IsRollbacked(false)
             ||
             BeforeImage.IsDeleted(false) ) // PTS 1115828 UH 2002-05-17
            {
            if ( LogTrans_Trace.TracesLevel(6) )
            {
                Kernel_VTrace() << "skipped undo entry: (" << BeforeImage.GetSequence() << ") '"
                                << Log_ActionTypeStrings[BeforeImage.GetActionType()] << "'";
                if ( BeforeImage.GetActionType() == Log_NewObject )
                {
                    Log_ActionObject action;
                    action.ReadPersistentFormat (Reader, Allocator(), isOK);
                    if ( isOK )
                        action.WriteToTrace("skipped undo entry: ");
                }
                if ( LogTrans_Trace.TracesLevel(7) )
                {
                    iter.WriteToTrace("skipped undo entry");
                    BeforeImage.WriteToTrace("skipped undo entry");
                }
            }
            }
        else
        {
            ++EntryCount;

            bool isOK = false;

            ExecuteUndoAction (BeforeImage, Reader, iter, isOK);

            if ( ! isOK )
            {
                Kernel_VTrace() << "ROLLBACK-ERROR: after ExecuteUndoAction: TrError: " << m_pTrans->trError_gg00;
                Kernel_VTrace() << "entry: ("
                                << BeforeImage.GetSequence() << ") '"
                                << Log_ActionTypeStrings[BeforeImage.GetActionType()] << "'";
                BeforeImage.WriteToTrace("RollbackErrorImage");
                WriteToTrace("RollbackErrorTrans");
                Result = undoExecuteError;
                break;
            }
            #ifdef SAPDB_QUICK
            if ( ! iter.CheckAccessMode(Data_ForUpdate) )
            {
                Kernel_VTrace() << "EntryCount: " << EntryCount;
                iter.WriteToTrace("ErrorSplitSpace: wrong accessmode");
                BeforeImage.WriteToTrace("RollbackErrorImage");
                WriteToTrace("RollbackErrorTrans");
                RTE_Crash( SAPDBErr_Exception( __FILE__, __LINE__,
                                               SAPDBERR_ASSERT_STATE_FAILED,
                                               "Log_Transaction::Rollback() accessmode not update3" ) );
            }
            #endif
            
            // This MUST be placed AFTER the undo action.
            if ( BeforeImage.GetActionType() == Log_DeleteObject )
                BeforeImage.SetDeleted(true); // PTS 1115828 UH 2002-05-17
            else
                BeforeImage.SetRollbacked(true); // PTS 1114840 UH 2002-03-14
        }

        if ( (UndoStopSequence != LOG_FIRST_ENTRY_SEQUENCE)
             &&
             (UndoStopSequence == BeforeImage.GetSequence()) )
        {
            SAPDBTRACE_WRITELN (LogTrans_Trace, 6, "ROLLBACK-INFO: stop sequence reached");
            break;
        }

        --iter;
        *iter; // really assign the space
    }
    // release all resources (pages)
    iter.Invalidate();

    if ( undoOk == Result )
        if ( endOfTrans == rollbackKind )
            EndOfTransHandling (rollbacked);
        else
            // there was anything rollbacked and there are entries,
            // which must be skipped during redo
            if ( EntryCount > 0
                 &&
                 m_Context.LastRedoEntrySequence.IsValid()
                 &&
                 RedoStopSequence < m_Context.LastRedoEntrySequence + 1
                 &&
                 ! isRedoPartialRollback ) // PTS 1113230 UH 2001-12-20
            {
                switch  ( WritePartialRollbackEntry (UndoStopSequence,RedoStopSequence) )
                {
                    case Log_Transaction::noError:    
                        break;
                    case Log_Transaction::logFull:  
                        Result = undoLogFull;
                        Kernel_VTrace() << "ROLLBACK-ERROR: WritePartialRollbackEntry() logFull";
                        WriteToTrace("RollbackErrorTrans");
                        break;
                    case Log_Transaction::logError: 
                        Result = undoWriteError; 
                        Kernel_VTrace() << "ROLLBACK-ERROR: WritePartialRollbackEntry() logError";
                        WriteToTrace("RollbackErrorTrans");
                        break;
                    default:                        
                        RTE_Crash( SAPDBErr_Exception(__FILE__, __LINE__,SAPDBERR_ASSERT_STATE_FAILED,
                        "Log_Transaction::Rollback(): invalid result of WriteRedoEntry") );
                }
            }

    if ( Result != undoOk )
        Kernel_VTrace() << "end-error: " << Result;

    return Result;
}


Generated by  Doxygen 1.6.0   Back to index