LogicalRecoveryLog Class Reference

LogicalRecoveryLog is the recovery-time counterpart to the online LogicalTxnLog. More...

#include <LogicalRecoveryLog.h>

List of all members.

Public Member Functions

virtual ~LogicalRecoveryLog ()
void recover (LogicalTxnLogCheckpointMemento const &memento)

Static Public Member Functions

static SharedLogicalRecoveryLog newLogicalRecoveryLog (LogicalTxnParticipantFactory &participantFactory, SegmentAccessor const &logSegmentAccessor, PseudoUuid const &onlineUuid, SharedSegmentFactory pSegmentFactory)
 Opens a LogicalRecoveryLog stored in the given segment.
static std::string getLongLogFileName (TxnId txnId)
 Gets the relative filename for a long transaction log.

Private Types

typedef std::hash_map< TxnId,
LogicalTxnEventMemento
TxnMap
typedef TxnMap::iterator TxnMapIter

Private Member Functions

 LogicalRecoveryLog (LogicalTxnParticipantFactory &participantFactory, SegmentAccessor const &logSegmentAccessor, PseudoUuid const &onlineUuid, SharedSegmentFactory pSegmentFactory)
void redoTxn (LogicalTxnEventMemento const &commitMemento, LogicalTxnEventMemento const *pCheckpointMemento, SharedSegInputStream pTxnInputStream)
void undoTxn (LogicalTxnEventMemento const &checkpointMemento, SharedSegInputStream pTxnInputStream)
SharedSegInputStream openLongLogStream (TxnId txnId)

Private Attributes

TxnMap checkpointTxnMap
LogicalTxnParticipantFactoryparticipantFactory
SharedSegmentFactory pSegmentFactory
SegmentAccessor logSegmentAccessor
SharedSegInputStream pInputStream


Detailed Description

LogicalRecoveryLog is the recovery-time counterpart to the online LogicalTxnLog.

Definition at line 42 of file LogicalRecoveryLog.h.


Member Typedef Documentation

typedef std::hash_map<TxnId,LogicalTxnEventMemento> LogicalRecoveryLog::TxnMap [private]

Definition at line 45 of file LogicalRecoveryLog.h.

typedef TxnMap::iterator LogicalRecoveryLog::TxnMapIter [private]

Definition at line 46 of file LogicalRecoveryLog.h.


Constructor & Destructor Documentation

LogicalRecoveryLog::LogicalRecoveryLog ( LogicalTxnParticipantFactory participantFactory,
SegmentAccessor const &  logSegmentAccessor,
PseudoUuid const &  onlineUuid,
SharedSegmentFactory  pSegmentFactory 
) [explicit, private]

Definition at line 36 of file LogicalRecoveryLog.cpp.

References logSegmentAccessor, CrcSegInputStream::newCrcSegInputStream(), and pInputStream.

Referenced by newLogicalRecoveryLog().

00041     : participantFactory(participantFactoryInit),
00042       pSegmentFactory(pSegmentFactoryInit),
00043       logSegmentAccessor(logSegmentAccessorInit)
00044 {
00045     pInputStream = CrcSegInputStream::newCrcSegInputStream(
00046         logSegmentAccessor,onlineUuid);
00047 }

LogicalRecoveryLog::~LogicalRecoveryLog (  )  [virtual]

Definition at line 60 of file LogicalRecoveryLog.cpp.

00061 {
00062 }


Member Function Documentation

void LogicalRecoveryLog::redoTxn ( LogicalTxnEventMemento const &  commitMemento,
LogicalTxnEventMemento const *  pCheckpointMemento,
SharedSegInputStream  pTxnInputStream 
) [private]

Definition at line 138 of file LogicalRecoveryLog.cpp.

References LogicalTxnEventMemento::cbActionLast, LogicalTxnSavepoint::cbActionPrev, LogicalTxnSavepoint::cbLogged, SegStreamPosition::cbOffset, LogicalTxnEventMemento::logPosition, LogicalTxnEventMemento::nParticipants, participantFactory, LogicalRecoveryTxn::redoActions(), and LogicalRecoveryTxn::undoActions().

Referenced by recover().

00142 {
00143     LogicalRecoveryTxn recoveryTxn(
00144         pTxnInputStream,
00145         &participantFactory);
00146     FileSize cbRedo;
00147     if (pCheckpointMemento) {
00148         pTxnInputStream->seekSegPos(pCheckpointMemento->logPosition);
00149         // first, recover checkpointed participants
00150         LogicalTxnSavepoint svpt;
00151         svpt.cbActionPrev = pCheckpointMemento->cbActionLast;
00152         svpt.cbLogged = pCheckpointMemento->logPosition.cbOffset;
00153         recoveryTxn.undoActions(
00154             svpt,
00155             pCheckpointMemento->nParticipants);
00156         // now, prepare for redo
00157         cbRedo = commitMemento.logPosition.cbOffset
00158             - pCheckpointMemento->logPosition.cbOffset;
00159         pTxnInputStream->seekSegPos(pCheckpointMemento->logPosition);
00160     } else {
00161         cbRedo = commitMemento.logPosition.cbOffset;
00162     }
00163     recoveryTxn.redoActions(cbRedo);
00164 }

void LogicalRecoveryLog::undoTxn ( LogicalTxnEventMemento const &  checkpointMemento,
SharedSegInputStream  pTxnInputStream 
) [private]

Definition at line 166 of file LogicalRecoveryLog.cpp.

References LogicalTxnEventMemento::cbActionLast, LogicalTxnSavepoint::cbActionPrev, LogicalTxnSavepoint::cbLogged, SegStreamPosition::cbOffset, LogicalTxnEventMemento::logPosition, participantFactory, and LogicalRecoveryTxn::undoActions().

Referenced by recover().

00169 {
00170     LogicalTxnSavepoint svpt;
00171     svpt.cbActionPrev = checkpointMemento.cbActionLast;
00172     svpt.cbLogged = checkpointMemento.logPosition.cbOffset;
00173     pTxnInputStream->seekSegPos(checkpointMemento.logPosition);
00174     LogicalRecoveryTxn recoveryTxn(
00175         pTxnInputStream,
00176         &participantFactory);
00177     recoveryTxn.undoActions(svpt);
00178 }

SharedSegInputStream LogicalRecoveryLog::openLongLogStream ( TxnId  txnId  )  [private]

Definition at line 123 of file LogicalRecoveryLog.cpp.

References getLongLogFileName(), DeviceMode::load, logSegmentAccessor, SegInputStream::newSegInputStream(), SegmentAccessor::pCacheAccessor, pSegmentFactory, and DeviceMode::readOnly.

Referenced by recover().

00124 {
00125     DeviceMode openMode = DeviceMode::load;
00126     openMode.readOnly = true;
00127     SharedSegment pTxnLogSegment =
00128         pSegmentFactory->newTempDeviceSegment(
00129             logSegmentAccessor.pCacheAccessor->getCache(),
00130             openMode,
00131             getLongLogFileName(txnId));
00132     SegmentAccessor txnSegmentAccessor(
00133         pTxnLogSegment,
00134         logSegmentAccessor.pCacheAccessor);
00135     return SegInputStream::newSegInputStream(txnSegmentAccessor);
00136 }

SharedLogicalRecoveryLog LogicalRecoveryLog::newLogicalRecoveryLog ( LogicalTxnParticipantFactory participantFactory,
SegmentAccessor const &  logSegmentAccessor,
PseudoUuid const &  onlineUuid,
SharedSegmentFactory  pSegmentFactory 
) [static]

Opens a LogicalRecoveryLog stored in the given segment.

Parameters:
participantFactory factory for reloading instances of LogicalTxnParticipant
logSegmentAccessor accessor for segment containing log data
onlineUuid UUID associated with log instance while it was online
pSegmentFactory SegmentFactory to use for accessing long log segments
Returns:
shared_ptr to new LogicalRecoveryLog

Definition at line 49 of file LogicalRecoveryLog.cpp.

References LogicalRecoveryLog(), logSegmentAccessor, and participantFactory.

Referenced by LogicalTxnTest::createRecoveryLog(), and Database::recover().

00054 {
00055     return SharedLogicalRecoveryLog(
00056         new LogicalRecoveryLog(
00057             participantFactory,logSegmentAccessor,onlineUuid,pSegmentFactory));
00058 }

void LogicalRecoveryLog::recover ( LogicalTxnLogCheckpointMemento const &  memento  ) 

Definition at line 64 of file LogicalRecoveryLog.cpp.

References checkpointTxnMap, LogicalTxnEventMemento::EVENT_CHECKPOINT, LogicalTxnEventMemento::EVENT_COMMIT, LogicalTxnEventMemento::EVENT_ROLLBACK, LogicalTxnLogCheckpointMemento::logPosition, LogicalTxnLogCheckpointMemento::nUncommittedTxns, openLongLogStream(), pInputStream, redoTxn(), and undoTxn().

00066 {
00067     LogicalTxnEventMemento txnMemento;
00068     pInputStream->seekSegPos(logMemento.logPosition);
00069     for (uint i = 0; i < logMemento.nUncommittedTxns; ++i) {
00070         uint cb = pInputStream->readValue(txnMemento);
00071         assert(cb == sizeof(txnMemento));
00072         assert(txnMemento.event == LogicalTxnEventMemento::EVENT_CHECKPOINT);
00073         checkpointTxnMap[txnMemento.txnId] = txnMemento;
00074     }
00075     for (;;) {
00076         uint cb = pInputStream->readValue(txnMemento);
00077         if (cb < sizeof(txnMemento)) {
00078             break;
00079         }
00080         TxnId txnId = txnMemento.txnId;
00081         TxnMapIter pTxnEntry = checkpointTxnMap.find(txnId);
00082         SharedSegInputStream pTxnInputStream;
00083         if (txnMemento.longLog) {
00084             pTxnInputStream = openLongLogStream(txnId);
00085         } else {
00086             // REVIEW:  Is there a chance that txn might be incompletely
00087             // logged?  If so, need to prevent it or detect it.
00088             pTxnInputStream = pInputStream;
00089         }
00090         switch (txnMemento.event) {
00091         case LogicalTxnEventMemento::EVENT_COMMIT:
00092             if (pTxnEntry == checkpointTxnMap.end()) {
00093                 redoTxn(txnMemento,NULL,pTxnInputStream);
00094             } else {
00095                 redoTxn(
00096                     txnMemento,
00097                     &(pTxnEntry->second),
00098                     pTxnInputStream);
00099                 checkpointTxnMap.erase(pTxnEntry);
00100             }
00101             break;
00102         case LogicalTxnEventMemento::EVENT_ROLLBACK:
00103             assert(pTxnEntry != checkpointTxnMap.end());
00104             undoTxn(pTxnEntry->second,pTxnInputStream);
00105             checkpointTxnMap.erase(txnId);
00106             break;
00107         case LogicalTxnEventMemento::EVENT_CHECKPOINT:
00108             break;
00109         default:
00110             permAssert(false);
00111         }
00112     }
00113     for (TxnMapIter pTxnEntry = checkpointTxnMap.begin();
00114          pTxnEntry != checkpointTxnMap.end(); ++pTxnEntry)
00115     {
00116         SharedSegInputStream pTxnInputStream =
00117             openLongLogStream(pTxnEntry->first);
00118         undoTxn(pTxnEntry->second,pTxnInputStream);
00119     }
00120     checkpointTxnMap.clear();
00121 }

std::string LogicalRecoveryLog::getLongLogFileName ( TxnId  txnId  )  [static]

Gets the relative filename for a long transaction log.

This is deterministic based on the TxnId.

Parameters:
txnId the TxnId of the transaction

Definition at line 180 of file LogicalRecoveryLog.cpp.

Referenced by LogicalTxn::LogicalTxn(), and openLongLogStream().

00181 {
00182     std::ostringstream oss;
00183     oss << "txn";
00184     oss << txnId;
00185     oss << ".dat";
00186     return oss.str();
00187 }


Member Data Documentation

TxnMap LogicalRecoveryLog::checkpointTxnMap [private]

Definition at line 48 of file LogicalRecoveryLog.h.

Referenced by recover().

LogicalTxnParticipantFactory& LogicalRecoveryLog::participantFactory [private]

Definition at line 50 of file LogicalRecoveryLog.h.

Referenced by newLogicalRecoveryLog(), redoTxn(), and undoTxn().

SharedSegmentFactory LogicalRecoveryLog::pSegmentFactory [private]

Definition at line 52 of file LogicalRecoveryLog.h.

Referenced by openLongLogStream().

SegmentAccessor LogicalRecoveryLog::logSegmentAccessor [private]

Definition at line 54 of file LogicalRecoveryLog.h.

Referenced by LogicalRecoveryLog(), newLogicalRecoveryLog(), and openLongLogStream().

SharedSegInputStream LogicalRecoveryLog::pInputStream [private]

Definition at line 56 of file LogicalRecoveryLog.h.

Referenced by LogicalRecoveryLog(), and recover().


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