LogicalRecoveryTxn Class Reference

LogicalRecoveryTxn implements recovery for transactions previously logged via LogicalTxn. More...

#include <LogicalRecoveryTxn.h>

List of all members.

Public Member Functions

 LogicalRecoveryTxn (SharedByteInputStream pTxnInputStream, LogicalTxnParticipantFactory *pParticipantFactory)
 Constructor.
virtual ~LogicalRecoveryTxn ()
void redoActions (uint cbRedo)
 Performs redo for actions from the log in their original logged order.
void undoActions (LogicalTxnSavepoint const &svptEnd, uint nActionsMax=MAXU, FileSize minActionOffset=0)
 Performs undo for actions from the log in reverse order.

Private Types

typedef std::hash_map< LogicalTxnParticipant *,
SharedLogicalTxnParticipant,
VoidPtrHash
ParticipantMap
typedef ParticipantMap::iterator ParticipantMapIter

Private Member Functions

bool isOnline () const
void recoverParticipant (LogicalTxnParticipant *pLoggedParticipant)
LogicalTxnParticipantswizzleParticipant (LogicalTxnParticipant *pParticipant)

Private Attributes

SharedByteInputStream pTxnInputStream
 Stream from which to read log data.
LogicalTxnParticipantFactorypParticipantFactory
 Factory for recovering txn participants, or NULL if online recovery being performed.
ParticipantMap participantMap
 Swizzling map from logged participant to recovered participant.


Detailed Description

LogicalRecoveryTxn implements recovery for transactions previously logged via LogicalTxn.

Definition at line 43 of file LogicalRecoveryTxn.h.


Member Typedef Documentation

typedef std::hash_map< LogicalTxnParticipant *, SharedLogicalTxnParticipant, VoidPtrHash> LogicalRecoveryTxn::ParticipantMap [private]

Definition at line 49 of file LogicalRecoveryTxn.h.

typedef ParticipantMap::iterator LogicalRecoveryTxn::ParticipantMapIter [private]

Definition at line 50 of file LogicalRecoveryTxn.h.


Constructor & Destructor Documentation

LogicalRecoveryTxn::LogicalRecoveryTxn ( SharedByteInputStream  pTxnInputStream,
LogicalTxnParticipantFactory pParticipantFactory 
) [explicit]

Constructor.

Parameters:
pTxnInputStream stream for reading transaction log
pParticipantFactory if NULL, online recovery is being performed, and logged participants can be accessed directly; if non-NULL, logged participants must be recovered via this factory

Definition at line 33 of file LogicalRecoveryTxn.cpp.

00036     : pTxnInputStream(pTxnInputStreamInit),
00037       pParticipantFactory(pParticipantFactoryInit)
00038 {
00039 }

LogicalRecoveryTxn::~LogicalRecoveryTxn (  )  [virtual]

Definition at line 41 of file LogicalRecoveryTxn.cpp.

00042 {
00043 }


Member Function Documentation

bool LogicalRecoveryTxn::isOnline (  )  const [inline, private]

Definition at line 68 of file LogicalRecoveryTxn.h.

Referenced by recoverParticipant(), and swizzleParticipant().

00069     {
00070         return pParticipantFactory ? false : true;
00071     }

void LogicalRecoveryTxn::recoverParticipant ( LogicalTxnParticipant pLoggedParticipant  )  [private]

Definition at line 90 of file LogicalRecoveryTxn.cpp.

References isOnline(), LogicalTxnParticipantFactory::loadParticipant(), participantMap, pParticipantFactory, and pTxnInputStream.

Referenced by redoActions(), and undoActions().

00092 {
00093     if (isOnline()) {
00094         return;
00095     }
00096     LogicalTxnClassId classId;
00097     pTxnInputStream->readValue(classId);
00098     SharedLogicalTxnParticipant pRecoveredParticipant =
00099         pParticipantFactory->loadParticipant(classId,*pTxnInputStream);
00100     participantMap[pLoggedParticipant] = pRecoveredParticipant;
00101 }

LogicalTxnParticipant * LogicalRecoveryTxn::swizzleParticipant ( LogicalTxnParticipant pParticipant  )  [private]

Definition at line 164 of file LogicalRecoveryTxn.cpp.

References isOnline(), and participantMap.

Referenced by redoActions(), and undoActions().

00166 {
00167     if (isOnline()) {
00168         return pParticipant;
00169     }
00170     ParticipantMapIter pParticipantEntry = participantMap.find(pParticipant);
00171     if (pParticipantEntry != participantMap.end()) {
00172         return pParticipantEntry->second.get();
00173     } else {
00174         return NULL;
00175     }
00176 }

void LogicalRecoveryTxn::redoActions ( uint  cbRedo  ) 

Performs redo for actions from the log in their original logged order.

Parameters:
cbRedo number of log bytes to read; redo stops after this

Definition at line 45 of file LogicalRecoveryTxn.cpp.

References ACTION_TXN_DESCRIBE_PARTICIPANT, ACTION_TXN_ROLLBACK_TO_SAVEPOINT, LogicalTxnActionHeader::actionType, LogicalTxnSavepoint::cbActionPrev, LogicalTxnSavepoint::cbLogged, MAXU, LogicalTxnActionHeader::pParticipant, pTxnInputStream, recoverParticipant(), LogicalTxnParticipant::redoLogicalAction(), swizzleParticipant(), and undoActions().

Referenced by LogicalRecoveryLog::redoTxn().

00047 {
00048     FileSize cbStart = pTxnInputStream->getOffset();
00049     while (pTxnInputStream->getOffset() < (cbStart + cbRedo)) {
00050         LogicalTxnActionHeader actionHeader;
00051         pTxnInputStream->readValue(actionHeader);
00052 
00053         switch (actionHeader.actionType) {
00054         case ACTION_TXN_DESCRIBE_PARTICIPANT:
00055             recoverParticipant(actionHeader.pParticipant);
00056             break;
00057         case ACTION_TXN_ROLLBACK_TO_SAVEPOINT:
00058             {
00059                 LogicalTxnSavepoint oldSvpt;
00060                 pTxnInputStream->readValue(oldSvpt);
00061                 // remember current position
00062                 FileSize offset = pTxnInputStream->getOffset();
00063                 // rewind this action
00064                 pTxnInputStream->seekBackward(
00065                     sizeof(oldSvpt) + sizeof(actionHeader));
00066                 LogicalTxnSavepoint svptEnd;
00067                 svptEnd.cbLogged = pTxnInputStream->getOffset();
00068                 svptEnd.cbActionPrev = actionHeader.cbActionPrev;
00069                 // redo rollback
00070                 undoActions(svptEnd,MAXU,oldSvpt.cbLogged);
00071                 // restore position
00072                 pTxnInputStream->seekForward(
00073                     offset - pTxnInputStream->getOffset());
00074             }
00075             break;
00076         default:
00077             {
00078                 LogicalTxnParticipant *pParticipant = swizzleParticipant(
00079                     actionHeader.pParticipant);
00080                 pParticipant->redoLogicalAction(
00081                     actionHeader.actionType,
00082                     *pTxnInputStream);
00083             }
00084             break;
00085         }
00086     }
00087     assert(pTxnInputStream->getOffset() == (cbStart + cbRedo));
00088 }

void LogicalRecoveryTxn::undoActions ( LogicalTxnSavepoint const &  svptEnd,
uint  nActionsMax = MAXU,
FileSize  minActionOffset = 0 
)

Performs undo for actions from the log in reverse order.

The undo may be limited by nActionsMax or minActionOffset, but not both.

Parameters:
svptEnd savepoint for log position just after first action to be undone
nActionsMax limit on number of actions to undo, or MAXU for no limit
minActionOffset log position at which to stop rolling back, or 0 for the entire log

Definition at line 103 of file LogicalRecoveryTxn.cpp.

References ACTION_TXN_DESCRIBE_PARTICIPANT, ACTION_TXN_ROLLBACK_TO_SAVEPOINT, LogicalTxnActionHeader::actionType, LogicalTxnActionHeader::cbActionPrev, LogicalTxnSavepoint::cbActionPrev, LogicalTxnSavepoint::cbLogged, isMAXU(), LogicalTxnActionHeader::pParticipant, pTxnInputStream, recoverParticipant(), swizzleParticipant(), and LogicalTxnParticipant::undoLogicalAction().

Referenced by redoActions(), LogicalRecoveryLog::redoTxn(), LogicalTxn::rollback(), LogicalTxn::rollbackToSavepoint(), and LogicalRecoveryLog::undoTxn().

00107 {
00108     assert(isMAXU(nActionsMax) || !minActionOffset);
00109 
00110     uint nActions = 0;
00111     uint cbActionExpected = svptEnd.cbActionPrev;
00112     uint seekDist = 0;
00113     while (cbActionExpected && (nActions < nActionsMax)) {
00114         seekDist += cbActionExpected;
00115         pTxnInputStream->seekBackward(seekDist);
00116         FileSize actionOffset = pTxnInputStream->getOffset();
00117         if (actionOffset < minActionOffset) {
00118             break;
00119         }
00120         LogicalTxnActionHeader actionHeader;
00121         pTxnInputStream->readValue(actionHeader);
00122 
00123         switch (actionHeader.actionType) {
00124         case ACTION_TXN_DESCRIBE_PARTICIPANT:
00125             if (swizzleParticipant(actionHeader.pParticipant)) {
00126                 // ignore log data since the participant is already available
00127                 seekDist = sizeof(actionHeader);
00128             } else {
00129                 recoverParticipant(actionHeader.pParticipant);
00130                 assert(pTxnInputStream->getOffset() ==
00131                        actionOffset + cbActionExpected);
00132                 seekDist = cbActionExpected;
00133             }
00134             break;
00135         case ACTION_TXN_ROLLBACK_TO_SAVEPOINT:
00136             {
00137                 // skip everything back to savepoint, since it was already
00138                 // undone
00139                 LogicalTxnSavepoint oldSvpt;
00140                 pTxnInputStream->readValue(oldSvpt);
00141                 assert(oldSvpt.cbLogged < pTxnInputStream->getOffset());
00142                 actionHeader.cbActionPrev = oldSvpt.cbActionPrev;
00143                 seekDist = pTxnInputStream->getOffset() - oldSvpt.cbLogged;
00144             }
00145             break;
00146         default:
00147             {
00148                 LogicalTxnParticipant *pParticipant = swizzleParticipant(
00149                     actionHeader.pParticipant);
00150                 pParticipant->undoLogicalAction(
00151                     actionHeader.actionType,
00152                     *pTxnInputStream);
00153                 assert(pTxnInputStream->getOffset() ==
00154                        actionOffset + cbActionExpected);
00155                 seekDist = cbActionExpected;
00156             }
00157             break;
00158         }
00159         cbActionExpected = actionHeader.cbActionPrev;
00160         ++nActions;
00161     }
00162 }


Member Data Documentation

SharedByteInputStream LogicalRecoveryTxn::pTxnInputStream [private]

Stream from which to read log data.

Definition at line 55 of file LogicalRecoveryTxn.h.

Referenced by recoverParticipant(), redoActions(), and undoActions().

LogicalTxnParticipantFactory* LogicalRecoveryTxn::pParticipantFactory [private]

Factory for recovering txn participants, or NULL if online recovery being performed.

Definition at line 61 of file LogicalRecoveryTxn.h.

Referenced by recoverParticipant().

ParticipantMap LogicalRecoveryTxn::participantMap [private]

Swizzling map from logged participant to recovered participant.

Definition at line 66 of file LogicalRecoveryTxn.h.

Referenced by recoverParticipant(), and swizzleParticipant().


The documentation for this class was generated from the following files:
Generated on Mon Jun 22 04:00:39 2009 for Fennel by  doxygen 1.5.1