Fennel: Database Class Reference (original) (raw)

Database defines the top-level database object, which is the unit of self-contained storage and recovery. More...

#include <[Database.h](Database%5F8h-source.html)>

Inheritance diagram for Database:

List of all members.

Public Member Functions
virtual ~Database ()
const ConfigMap & getConfigMap () const
SharedCache getCache () const
SharedSegmentFactory getSegmentFactory () const
SharedSegment getDataSegment () const
SharedSegment getTempSegment () const
SharedCheckpointThread getCheckpointThread () const
virtual SharedSegment getSegmentById (SegmentId segmentId, SharedSegment pDataSegment)
Finds a segment by its SegmentId.
virtual void writeStats (StatsTarget &target)
Writes a current stats snapshot to a StatsTarget.
SharedLogicalTxnLog getTxnLog () const
StoredTypeDescriptorFactory const & getTypeFactory () const
bool isRecoveryRequired () const
bool shouldForceTxns () const
bool areSnapshotsEnabled () const
void recoverOnline ()
void recover (LogicalTxnParticipantFactory &txnParticipantFactory)
void checkpointImpl (CheckpointType=CHECKPOINT_FLUSH_ALL)
void requestCheckpoint (CheckpointType checkpointType, bool async)
Receives request for a checkpoint.
void deallocateOldPages (TxnId oldestLabelCsn)
Deallocates old snapshot pages that are no longer referenced by any active transactions, as well as active labels marking snapshots in time.
void setLastCommittedTxnId (TxnId txnId)
Saves the id of the last committed transaction.
TxnId getLastCommittedTxnId ()
**Returns:**the id of the last committed, write transaction
TxnId initiateBackup (const std::string &backupFilePathname, bool checkSpaceRequirements, FileSize spacePadding, TxnId lowerBoundCsn, const std::string &compressionProgram, FileSize &dataDeviceSize, const volatile bool &aborted)
Initiates a backup of the data segment.
void completeBackup (TxnId lowerBoundCsn, TxnId upperBoundCsn, const volatile bool &aborted)
Completes the remainder of a backup by backing up the data pages that have allocationCsn's in between two specified bounds.
void abortBackup ()
Aborts a backup that may or may not have been previously initiated.
void restoreFromBackup (const std::string &backupFilePathname, FileSize newSize, const std::string &compressionProgram, TxnId lowerBoundCsn, TxnId upperBoundCsn, const volatile bool &aborted)
Restores the data segment from a backup file.
bool isClosed () const
**Returns:**whether the object has been closed
void close ()
Closes this object, releasing any unallocated resources.
virtual void initTraceSource (SharedTraceTarget pTraceTarget, std::string name)
For use when initialization has to be deferred until after construction.
void trace (TraceLevel level, std::string message) const
Records a trace message.
bool isTracing () const
**Returns:**true iff tracing is enabled for this source
bool isTracingLevel (TraceLevel level) const
Determines whether a particular level is being traced.
TraceTarget & getTraceTarget () const
**Returns:**the TraceTarget for this source
SharedTraceTarget getSharedTraceTarget () const
**Returns:**the SharedTraceTarget for this source
std::string getTraceSourceName () const
Gets the name of this source.
void setTraceSourceName (std::string const &n)
Sets the name of this source.
TraceLevel getMinimumTraceLevel () const
void disableTracing ()
Static Public Member Functions
static SharedDatabase newDatabase (SharedCache pCache, ConfigMap const &configMap, DeviceMode openMode, SharedTraceTarget pTraceTarget, SharedPseudoUuidGenerator pUuidGenerator=SharedPseudoUuidGenerator())
Static Public Attributes
static ParamName paramDatabaseDir
static ParamName paramResourceDir
static ParamName paramForceTxns
static ParamName paramDisableSnapshots
static ParamName paramDatabasePrefix
static ParamName paramTempPrefix
static ParamName paramShadowLogPrefix
static ParamName paramTxnLogPrefix
static ParamName paramInitSizeSuffix
static ParamName paramMaxSizeSuffix
static ParamName paramIncSizeSuffix
static ParamVal valLogAllocLinear
static ParamVal valLogAllocCircular
static const SegmentId DEFAULT_DATA_SEGMENT_ID
static const SegmentId TEMP_SEGMENT_ID
Protected Attributes
bool needsClose
StrictMutex mutex
LocalCondition condition
Private Member Functions
Database (SharedCache pCache, ConfigMap const &configMap, DeviceMode openMode, SharedTraceTarget pTraceTarget, SharedPseudoUuidGenerator pUuidGenerator)
virtual void closeImpl ()
Must be implemented by derived class to release any resources.
void init ()
void createTxnLog (DeviceMode)
SharedSegment createTxnLogSegment (DeviceMode, PageId)
SharedSegment createShadowLog (DeviceMode)
void createDataDevice (LinearDeviceSegmentParams &)
void createDataSegment (SharedSegment, LinearDeviceSegmentParams &)
void createTempSegment ()
void allocateHeader ()
void writeHeader ()
void loadHeader (bool)
void closeDevices ()
void deleteLogs ()
void openSegments ()
void prepareForRecovery ()
void recoverPhysical (CheckpointType)
void readDeviceParams (std::string paramNamePrefix, DeviceMode deviceMode, LinearDeviceSegmentParams &deviceParams)
void cleanupBackupRestore (bool isBackup)
Private Attributes
DeviceId dataDeviceId
SharedRandomAccessDevice pDataDevice
DeviceId tempDeviceId
DeviceId shadowDeviceId
DeviceId txnLogDeviceId
std::string dataDeviceName
std::string tempDeviceName
std::string shadowDeviceName
std::string txnLogDeviceName
SharedCache pCache
SharedSegmentFactory pSegmentFactory
SharedSegment pHeaderSegment
SharedSegment pDataSegment
SharedSegment pTempSegment
VersionedSegment * pVersionedSegment
SharedLogicalTxnLog pTxnLog
PageId headerPageId1
PageId headerPageId2
DatabaseHeader header
LogicalTxnParticipantFactory * pTxnParticipantFactory
bool forceTxns
bool disableSnapshots
bool recoveryRequired
DeviceMode openMode
ConfigMap configMap
StandardTypeDescriptorFactory typeFactory
SharedCheckpointThread pCheckpointThread
SharedPseudoUuidGenerator pUuidGenerator
uint nCheckpointsStat
Cumulative counter cleared whenever writeStats is called.
uint nCheckpoints
Cumulative counter.
bool disableDeallocateOld
If true, ALTER SYSTEM DEALLOCATE OLD is a no-op.
SharedSegPageBackupRestoreDevice pBackupRestoreDevice
Device used to read and write the backup file during backup and restore.
SegmentAccessor scratchAccessor
Scratch accessor used during backup and restore.

Detailed Description

Database defines the top-level database object, which is the unit of self-contained storage and recovery.

Definition at line 49 of file Database.h.


Constructor & Destructor Documentation

| Database::~Database | ( | | ) | [virtual] | | -------------------- | - | | - | ----------- |


Member Function Documentation

| void Database::closeImpl | ( | | ) | [private, virtual] | | ------------------------ | - | | - | -------------------- |

Must be implemented by derived class to release any resources.

Implements ClosableObject.

Definition at line 246 of file Database.cpp.

References areSnapshotsEnabled(), checkpointImpl(), closeDevices(), deleteLogs(), VersionedRandomAllocationSegment::freeTempPages(), header, isRecoveryRequired(), pCheckpointThread, pDataSegment, pTempSegment, pTxnLog, TRACE_INFO, and DatabaseHeader::versionNumber.

| void Database::init | ( | | ) | [private] | | ------------------- | - | | - | ----------- |

Definition at line 111 of file Database.cpp.

References configMap, DeviceMode::create, dataDeviceId, dataDeviceName, disableSnapshots, FileSystem::doesFileExist(), forceTxns, ConfigMap::getBoolParam(), Segment::getLinearPageId(), TraceSource::getSharedTraceTarget(), ConfigMap::getStringParam(), header, headerPageId1, headerPageId2, DatabaseHeader::MAGIC_NUMBER, StoredNode::magicNumber, nCheckpoints, nCheckpointsStat, SegmentFactory::newSegmentFactory(), openMode, openSegments(), paramDatabaseDir, paramDisableSnapshots, paramForceTxns, paramResourceDir, prepareForRecovery(), pSegmentFactory, recoveryRequired, shadowDeviceId, shadowDeviceName, tempDeviceId, tempDeviceName, txnLogDeviceId, txnLogDeviceName, and DatabaseHeader::versionNumber.

| void Database::createTxnLog | ( | DeviceMode | | ) | [private] | | --------------------------- | - | ----------------------------------- | | - | ----------- |

Definition at line 347 of file Database.cpp.

References LinearDeviceSegmentParams::firstBlockId, forceTxns, MAXU, LinearDeviceSegmentParams::nPagesAllocated, LinearDeviceSegmentParams::nPagesIncrement, LinearDeviceSegmentParams::nPagesMax, LinearDeviceSegmentParams::nPagesMin, paramTxnLogPrefix, pCache, pCheckpointThread, pSegmentFactory, readDeviceParams(), CompoundId::setBlockNum(), CompoundId::setDeviceId(), txnLogDeviceId, and txnLogDeviceName.

Referenced by createTxnLog(), and recover().

Definition at line 394 of file Database.cpp.

References DeviceMode::create, LinearDeviceSegmentParams::firstBlockId, forceTxns, header, MAXU, LinearDeviceSegmentParams::nPagesAllocated, LinearDeviceSegmentParams::nPagesIncrement, LinearDeviceSegmentParams::nPagesMax, LinearDeviceSegmentParams::nPagesMin, NULL_PAGE_ID, paramShadowLogPrefix, pCache, pCheckpointThread, pSegmentFactory, readDeviceParams(), CompoundId::setBlockNum(), CompoundId::setDeviceId(), shadowDeviceId, shadowDeviceName, and DatabaseHeader::shadowRecoveryPageId.

Referenced by openSegments(), and prepareForRecovery().

Definition at line 459 of file Database.cpp.

References areSnapshotsEnabled(), DeviceMode::create, dataDeviceId, LinearDeviceSegmentParams::firstBlockId, header, MAXU, LinearDeviceSegmentParams::nPagesAllocated, DatabaseHeader::onlineUuid, openMode, pCache, pDataSegment, pSegmentFactory, pTempSegment, pVersionedSegment, recoveryRequired, CompoundId::setBlockNum(), CompoundId::setDeviceId(), and DatabaseHeader::versionNumber.

Referenced by openSegments(), and prepareForRecovery().

00462 { 00463
00464 CompoundId::setDeviceId(deviceParams.firstBlockId,dataDeviceId); 00465 CompoundId::setBlockNum(deviceParams.firstBlockId,2); 00466 00467 deviceParams.nPagesAllocated = MAXU; 00468 00469 SharedSegment pDataDeviceSegment = 00470 pSegmentFactory->newLinearDeviceSegment( 00471 pCache, 00472 deviceParams); 00473 00474 SharedSegment pVersionedDataSegment = 00475 pSegmentFactory->newVersionedSegment( 00476 pDataDeviceSegment, 00477 pShadowLogSegment, 00478 header.onlineUuid, 00479 header.versionNumber + (recoveryRequired ? 0 : 1)); 00480 00481 pVersionedSegment = SegmentFactory::dynamicCast<VersionedSegment *>( 00482 pVersionedDataSegment); 00483 00484
00485
00486 if (areSnapshotsEnabled()) { 00487 pDataSegment = 00488 pSegmentFactory->newVersionedRandomAllocationSegment( 00489 pVersionedDataSegment, 00490 pTempSegment, 00491 openMode.create, 00492 recoveryRequired); 00493 } else { 00494 pDataSegment = 00495 pSegmentFactory->newRandomAllocationSegment( 00496 pVersionedDataSegment, 00497 openMode.create, 00498 recoveryRequired); 00499 } 00500 }

| void Database::createTempSegment | ( | | ) | [private] | | -------------------------------- | - | | - | ----------- |

Definition at line 502 of file Database.cpp.

References DeviceMode::create, FileSystem::doesFileExist(), openMode, paramTempPrefix, pCache, pSegmentFactory, pTempSegment, readDeviceParams(), CompoundId::setBlockNum(), CompoundId::setDeviceId(), shouldForceTxns(), tempDeviceId, and tempDeviceName.

Referenced by openSegments(), and prepareForRecovery().

| void Database::allocateHeader | ( | | ) | [private] | | ----------------------------- | - | | - | ----------- |

Definition at line 591 of file Database.cpp.

References SegNodeLock< Node >::allocatePage(), dataDeviceId, FIRST_TXN_ID, LinearDeviceSegmentParams::firstBlockId, SegNodeLock< Node >::getNodeForWrite(), header, headerPageId1, headerPageId2, pCache, pHeaderSegment, pSegmentFactory, pTxnLog, CompoundId::setBlockNum(), CompoundId::setDeviceId(), and SegPageLock::unlock().

Referenced by openSegments().

| void Database::writeHeader | ( | | ) | [private] | | -------------------------- | - | | - | ----------- |

| void Database::loadHeader | ( | bool | | ) | [private] | | ------------------------- | - | ---- | | - | ----------- |

Definition at line 616 of file Database.cpp.

References SegNodeLock< Node >::checkMagicNumber(), dataDeviceId, LinearDeviceSegmentParams::firstBlockId, SegNodeLock< Node >::getNodeForRead(), header, headerPageId1, headerPageId2, SegPageLock::lockShared(), LogicalTxnLogCheckpointMemento::nextTxnId, LinearDeviceSegmentParams::nPagesAllocated, LinearDeviceSegmentParams::nPagesMax, pCache, pHeaderSegment, pSegmentFactory, pTxnLog, CompoundId::setBlockNum(), CompoundId::setDeviceId(), DatabaseHeader::txnLogCheckpointMemento, and DatabaseHeader::versionNumber.

Referenced by openSegments(), prepareForRecovery(), and restoreFromBackup().

| void Database::closeDevices | ( | | ) | [private] | | --------------------------- | - | | - | ----------- |

Definition at line 286 of file Database.cpp.

References dataDeviceId, pCache, pDataSegment, pHeaderSegment, pTempSegment, pTxnLog, pVersionedSegment, shadowDeviceId, tempDeviceId, and txnLogDeviceId.

Referenced by closeImpl(), and recover().

| void Database::deleteLogs | ( | | ) | [private] | | ------------------------- | - | | - | ----------- |

| void Database::openSegments | ( | | ) | [private] | | --------------------------- | - | | - | ----------- |

Definition at line 186 of file Database.cpp.

References allocateHeader(), checkpointImpl(), DeviceMode::create, createDataDevice(), createDataSegment(), createShadowLog(), createTempSegment(), createTxnLog(), DeviceMode::direct, header, loadHeader(), DatabaseHeader::onlineUuid, openMode, pCheckpointThread, pUuidGenerator, TRACE_INFO, and DatabaseHeader::versionNumber.

Referenced by init(), and recover().

| void Database::prepareForRecovery | ( | | ) | [private] | | --------------------------------- | - | | - | ----------- |

Definition at line 819 of file Database.cpp.

References CHECKPOINT_FLUSH_AND_UNMAP, DeviceMode::create, VersionedSegment::deallocateCheckpointedLog(), VersionedSegment::getVersionNumber(), header, isRecoveryRequired(), NULL_PAGE_ID, openMode, pDataSegment, pVersionedSegment, VersionedSegment::recover(), recoveryRequired, DatabaseHeader::shadowRecoveryPageId, TRACE_INFO, DatabaseHeader::versionNumber, and writeHeader().

Referenced by recover(), and recoverOnline().

Definition at line 849 of file Database.cpp.

References configMap, DeviceMode::create, ConfigMap::getIntParam(), ConfigMap::isParamSet(), MAXU, LinearDeviceSegmentParams::nPagesAllocated, LinearDeviceSegmentParams::nPagesIncrement, LinearDeviceSegmentParams::nPagesMax, LinearDeviceSegmentParams::nPagesMin, paramIncSizeSuffix, paramInitSizeSuffix, and paramMaxSizeSuffix.

Referenced by createDataDevice(), createShadowLog(), createTempSegment(), and createTxnLogSegment().

void Database::cleanupBackupRestore ( bool isBackup ) [private]

| const ConfigMap & Database::getConfigMap | ( | | ) | const | | --------------------------------------------------------------- | - | | - | ----- |

void Database::writeStats ( StatsTarget & target ) [virtual]

Writes a current stats snapshot to a StatsTarget.

Parameters:

target receives the stats

Implements StatsSource.

Definition at line 877 of file Database.cpp.

References SynchMonitoredObject::mutex, nCheckpoints, nCheckpointsStat, pCache, pDataSegment, pTempSegment, and StatsTarget::writeCounter().

00878 { 00879 pCache->writeStats(target); 00880 00881 StrictMutexGuard mutexGuard(mutex); 00882 target.writeCounter( 00883 "DatabaseCheckpoints", nCheckpointsStat); 00884 target.writeCounter( 00885 "DatabaseCheckpointsSinceInit", nCheckpoints); 00886 if (pDataSegment) { 00887 target.writeCounter( 00888 "DatabasePagesAllocated", pDataSegment->getAllocatedSizeInPages()); 00889
00890 target.writeCounter( 00891 "DatabasePagesOccupiedHighWaterSinceInit", 00892 pDataSegment->getNumPagesOccupiedHighWater() + 2); 00893 target.writeCounter( 00894 "DatabasePagesExtendedSinceInit", 00895 pDataSegment->getNumPagesExtended()); 00896 } 00897 if (pTempSegment) { 00898 target.writeCounter( 00899 "TempPagesAllocated", pTempSegment->getAllocatedSizeInPages()); 00900 target.writeCounter( 00901 "TempPagesOccupiedHighWaterSinceInit", 00902 pTempSegment->getNumPagesOccupiedHighWater()); 00903 target.writeCounter( 00904 "TempPagesExtendedSinceInit", 00905 pTempSegment->getNumPagesExtended()); 00906 } 00907 nCheckpointsStat = 0; 00908 }

| bool Database::isRecoveryRequired | ( | | ) | const | | --------------------------------- | - | | - | ----- |

| bool Database::shouldForceTxns | ( | | ) | const | | ------------------------------ | - | | - | ----- |

| bool Database::areSnapshotsEnabled | ( | | ) | const | | ---------------------------------- | - | | - | ----- |

| void Database::recoverOnline | ( | | ) | | ---------------------------- | - | | - |

Definition at line 782 of file Database.cpp.

References CHECKPOINT_FLUSH_AND_UNMAP, closeDevices(), createTxnLogSegment(), deleteLogs(), CompoundId::getPageId(), header, LogicalTxnLogCheckpointMemento::logPosition, LogicalRecoveryLog::newLogicalRecoveryLog(), DatabaseHeader::onlineUuid, openMode, openSegments(), pCache, pSegmentFactory, recoverPhysical(), SegmentAccessor::reset(), SegStreamPosition::segByteId, TRACE_INFO, and DatabaseHeader::txnLogCheckpointMemento.

void Database::checkpointImpl ( CheckpointType = CHECKPOINT_FLUSH_ALL )

Definition at line 666 of file Database.cpp.

References CHECKPOINT_DISCARD, CHECKPOINT_FLUSH_FUZZY, SynchMonitoredObject::condition, VersionedSegment::deallocateCheckpointedLog(), forceTxns, VersionedSegment::getOnlineRecoveryPageId(), VersionedSegment::getRecoveryPageId(), VersionedSegment::getVersionNumber(), header, isRecoveryRequired(), SynchMonitoredObject::mutex, nCheckpoints, nCheckpointsStat, pDataSegment, pTxnLog, pVersionedSegment, recoveryRequired, DatabaseHeader::shadowRecoveryPageId, DatabaseHeader::txnLogCheckpointMemento, DatabaseHeader::versionNumber, and writeHeader().

Referenced by closeImpl(), openSegments(), recoverOnline(), and CheckpointThread::run().

void Database::requestCheckpoint ( CheckpointType checkpointType,
bool async
)
void Database::deallocateOldPages ( TxnId oldestLabelCsn )

Deallocates old snapshot pages that are no longer referenced by any active transactions, as well as active labels marking snapshots in time.

Parameters:

oldestLabelCsn the csn of the oldest active label; set to NULL_TXN_ID if there are no active labels

Definition at line 920 of file Database.cpp.

References CHECKPOINT_FLUSH_ALL, VersionedRandomAllocationSegment::deallocateOldPages(), disableDeallocateOld, VersionedRandomAllocationSegment::getOldPageIds(), min(), NULL_TXN_ID, pCheckpointThread, pDataSegment, pTxnLog, and requestCheckpoint().

00921 { 00922 uint iSegAlloc = 0; 00923 ExtentNum extentNum = 0; 00924
00925
00926
00927
00928
00929
00930
00931 uint numPages = 100; 00932 00933
00934 TxnId oldestActiveTxnId = pTxnLog->getOldestActiveTxnId(); 00935 00936
00937
00938
00939
00940 TxnId oldestTxnId; 00941 if (oldestLabelCsn == NULL_TXN_ID) { 00942 oldestTxnId = oldestActiveTxnId; 00943 } else { 00944 oldestTxnId = std::min(oldestActiveTxnId, oldestLabelCsn + 1); 00945 } 00946 00947
00948
00949
00950
00951 00952 PageSet oldPageSet; 00953 VersionedRandomAllocationSegment *pVersionedRandomSegment = 00954 SegmentFactory::dynamicCast<VersionedRandomAllocationSegment *>( 00955 pDataSegment); 00956 bool morePages = true; 00957 do { 00958 morePages = 00959 pVersionedRandomSegment->getOldPageIds( 00960 iSegAlloc, 00961 extentNum, 00962 oldestTxnId, 00963 numPages, 00964 oldPageSet); 00965 00966
00967
00968 if (!oldPageSet.empty()) { 00969 SXMutexSharedGuard actionMutexGuard( 00970 pCheckpointThread->getActionMutex()); 00971 if (disableDeallocateOld) { 00972 return; 00973 } 00974 pVersionedRandomSegment->deallocateOldPages( 00975 oldPageSet, 00976 oldestTxnId); 00977 00978 actionMutexGuard.unlock(); 00979 requestCheckpoint(CHECKPOINT_FLUSH_ALL, false); 00980 oldPageSet.clear(); 00981 } 00982 } while (morePages); 00983 }

void Database::setLastCommittedTxnId ( TxnId txnId )

Saves the id of the last committed transaction.

Parameters:

txnId id of the last committed transaction

| TxnId Database::getLastCommittedTxnId | ( | | ) | | ------------------------------------- | - | | - |

TxnId Database::initiateBackup ( const std::string & backupFilePathname,
bool checkSpaceRequirements,
FileSize spacePadding,
TxnId lowerBoundCsn,
const std::string & compressionProgram,
FileSize & dataDeviceSize,
const volatile bool & aborted
)

Initiates a backup of the data segment.

Backs up the header pages and the allocation node pages.

Parameters:

backupFilePathname pathname of the backup file
checkSpaceRequirements if true, make sure file system space is available to perform the backup of data pages
spacePadding if non-zero, the amount of padding to add to the space requirements for the backup to proceed
lowerBoundCsn the lower bound allocation csn that determines which pages need to be backed up; if the lower bound is set to NULL_TXN_ID, then that indicates that there is no lower bound; otherwise, the lower bound is exclusive
compressionProgram if non-empty string, the name of the program used to compress the backup file
dataDeviceSize returns the size of the data device in bytes
aborted reference to a flag indicating whether the backup should be aborted

Returns:

the txnId of the last committed write txn at the start of the backup; i.e., the upper bound allocationCsn for the backup

Definition at line 985 of file Database.cpp.

References areSnapshotsEnabled(), cleanupBackupRestore(), disableDeallocateOld, FileSystem::getDiskFreeSpace(), getLastCommittedTxnId(), headerPageId1, headerPageId2, SegPageBackupRestoreDevice::newSegPageBackupRestoreDevice(), pBackupRestoreDevice, pCache, pCheckpointThread, pDataDevice, pDataSegment, pHeaderSegment, pSegmentFactory, scratchAccessor, and TRACE_FINE.

00993 { 00994 FENNEL_TRACE(TRACE_FINE, "Started Fennel metadata backup"); 00995 00996
00997 if (areSnapshotsEnabled()) { 00998 throw FennelExcn( 00999 FennelResource::instance().unsupportedOperation("System backup")); 01000 } 01001 01002
01003
01004 SXMutexSharedGuard actionMutexGuard(pCheckpointThread->getActionMutex()); 01005 01006
01007 assert(disableDeallocateOld); 01008 assert(pBackupRestoreDevice == NULL); 01009 01010
01011
01012
01013
01014
01015 TxnId upperBoundCsn = getLastCommittedTxnId(); 01016 01017 disableDeallocateOld = true; 01018 dataDeviceSize = pDataDevice->getSizeInBytes(); 01019 01020
01021
01022
01023
01024 uint nScratchPages, rate; 01025 pCache->getPrefetchParams(nScratchPages, rate); 01026 01027 scratchAccessor = pSegmentFactory->newScratchSegment(pCache); 01028 pBackupRestoreDevice = 01029 SegPageBackupRestoreDevice::newSegPageBackupRestoreDevice( 01030 backupFilePathname, 01031 #ifdef MSVC 01032 "wb", 01033 #else 01034 "w", 01035 #endif 01036 compressionProgram, 01037 nScratchPages, 01038 2, 01039 scratchAccessor, 01040 pCache->getDeviceAccessScheduler(*pDataDevice), 01041 pDataDevice); 01042 VersionedRandomAllocationSegment *pVRSegment = 01043 SegmentFactory::dynamicCast<VersionedRandomAllocationSegment *>( 01044 pDataSegment); 01045 01046 try { 01047 pBackupRestoreDevice->backupPage( 01048 pHeaderSegment->translatePageId(headerPageId1)); 01049 pBackupRestoreDevice->backupPage( 01050 pHeaderSegment->translatePageId(headerPageId2)); 01051
01052
01053 pBackupRestoreDevice->waitForPendingWrites(); 01054 BlockNum nDataPages = 01055 pVRSegment->backupAllocationNodes( 01056 pBackupRestoreDevice, 01057 checkSpaceRequirements, 01058 lowerBoundCsn, 01059 upperBoundCsn, 01060 aborted); 01061 01062
01063
01064 if (checkSpaceRequirements) { 01065 FileSize spaceAvailable; 01066 FileSystem::getDiskFreeSpace( 01067 backupFilePathname.c_str(), 01068 spaceAvailable); 01069 FileSize spaceRequired = 01070 nDataPages * pDataSegment->getFullPageSize(); 01071
01072
01073 if (compressionProgram.length() != 0) { 01074 spaceRequired /= 5; 01075 } 01076 spaceRequired += spacePadding; 01077 if (spaceAvailable < spaceRequired) { 01078 throw FennelExcn(FennelResource::instance().outOfBackupSpace()); 01079 } 01080 } 01081 } catch (...) { 01082 cleanupBackupRestore(true); 01083
01084 if (aborted) { 01085 FENNEL_TRACE(TRACE_FINE, "abort detected"); 01086 throw AbortExcn(); 01087 } else { 01088 throw; 01089 } 01090 } 01091 01092 FENNEL_TRACE(TRACE_FINE, "Finished Fennel metadata backup"); 01093 return upperBoundCsn; 01094 }

void Database::completeBackup ( TxnId lowerBoundCsn,
TxnId upperBoundCsn,
const volatile bool & aborted
)

| void Database::abortBackup | ( | | ) | | -------------------------- | - | | - |

Aborts a backup that may or may not have been previously initiated.

This is necessary to perform cleanup on the backup in case an error occurred after the backup was initiated, but before there was a chance to complete it.

Definition at line 1129 of file Database.cpp.

References cleanupBackupRestore(), and TRACE_FINE.

void Database::restoreFromBackup ( const std::string & backupFilePathname,
FileSize newSize,
const std::string & compressionProgram,
TxnId lowerBoundCsn,
TxnId upperBoundCsn,
const volatile bool & aborted
)

Restores the data segment from a backup file.

The data pages in the backup file correspond to pages with allocationCsn's in between a lower and upper bound. If the lower bound is set to NULL_TXN_ID, then that indicates that there is no lower bound; otherwise, the lower bound is exclusive. There must always be an upper bound and it is inclusive.

Parameters:

backupFilePathname pathname of the backup file
newSize the size the data segment will be extended to by the restore
compressionProgram if non-empty string, the name of the program used to compress the backup file
lowerBoundCsn the lower bound allocation csn
upperBoundCsn the upper bound allocation csn
aborted reference to a flag indicating whether the restore should be aborted

Definition at line 1135 of file Database.cpp.

References areSnapshotsEnabled(), CHECKPOINT_FLUSH_AND_UNMAP, cleanupBackupRestore(), getLastCommittedTxnId(), header, headerPageId1, headerPageId2, loadHeader(), SegPageBackupRestoreDevice::newSegPageBackupRestoreDevice(), NULL_PAGE_ID, NULL_TXN_ID, DatabaseHeader::onlineUuid, pBackupRestoreDevice, pCache, pDataDevice, pDataSegment, pHeaderSegment, pSegmentFactory, pVersionedSegment, VersionedSegment::recover(), VersionedRandomAllocationSegment::restoreFromBackup(), scratchAccessor, TRACE_FINE, and DatabaseHeader::versionNumber.

01142 { 01143 FENNEL_TRACE(TRACE_FINE, "Started Fennel restore"); 01144 01145
01146 if (areSnapshotsEnabled()) { 01147 throw FennelExcn( 01148 FennelResource::instance().unsupportedOperation("System restore")); 01149 } 01150 01151
01152
01153 if (lowerBoundCsn != NULL_TXN_ID) { 01154 TxnId headerTxnId = getLastCommittedTxnId(); 01155 if (headerTxnId != lowerBoundCsn) { 01156 throw FennelExcn( 01157 FennelResource::instance().mismatchedRestore()); 01158 } 01159 } 01160 01161 pDataDevice->setSizeInBytes(newSize); 01162 01163 VersionedRandomAllocationSegment pVRSegment = 01164 SegmentFactory::dynamicCast<VersionedRandomAllocationSegment *>( 01165 pDataSegment); 01166 01167 uint nScratchPages, rate; 01168 pCache->getPrefetchParams(nScratchPages, rate); 01169 01170 scratchAccessor = 01171 pSegmentFactory->newScratchSegment(pCache); 01172 pBackupRestoreDevice = 01173 SegPageBackupRestoreDevice::newSegPageBackupRestoreDevice( 01174 backupFilePathname, 01175 #ifdef MSVC 01176 "rb", 01177 #else 01178 "r", 01179 #endif 01180 compressionProgram, 01181 nScratchPages, 01182 0, 01183 scratchAccessor, 01184 pCache->getDeviceAccessScheduler(pDataDevice), 01185 pDataDevice); 01186 01187
01188
01189
01190
01191 MappedPageListenerPredicate dataPredicate(pVRSegment); 01192 pCache->checkpointPages(dataPredicate, CHECKPOINT_FLUSH_AND_UNMAP); 01193 MappedPageListenerPredicate headerPredicate(pHeaderSegment); 01194 pCache->checkpointPages(headerPredicate, CHECKPOINT_FLUSH_AND_UNMAP); 01195 01196 try { 01197
01198 pBackupRestoreDevice->restorePage( 01199 pHeaderSegment->translatePageId(headerPageId1)); 01200 pBackupRestoreDevice->restorePage( 01201 pHeaderSegment->translatePageId(headerPageId2)); 01202 pVRSegment->restoreFromBackup( 01203 pBackupRestoreDevice, 01204 lowerBoundCsn, 01205 upperBoundCsn, 01206 aborted); 01207 cleanupBackupRestore(false); 01208 } catch (...) { 01209 cleanupBackupRestore(false); 01210
01211 if (aborted) { 01212 FENNEL_TRACE(TRACE_FINE, "abort detected"); 01213 throw AbortExcn(); 01214 } else { 01215 throw; 01216 } 01217 } 01218 01219
01220
01221
01222
01223 loadHeader(false); 01224 pVersionedSegment->recover( 01225 pDataSegment, 01226 NULL_PAGE_ID, 01227 header.versionNumber, 01228 header.onlineUuid); 01229 01230 FENNEL_TRACE(TRACE_FINE, "Finished Fennel restore"); 01231 }

| bool ClosableObject::isClosed | ( | | ) | const [inline, inherited] | | ----------------------------- | - | | - | --------------------------- |

Returns:

whether the object has been closed

Definition at line 58 of file ClosableObject.h.

| void ClosableObject::close | ( | | ) | [inherited] | | -------------------------- | - | | - | ------------- |

Closes this object, releasing any unallocated resources.

Reimplemented in CollectExecStream, CorrelationJoinExecStream, LcsClusterAppendExecStream, and LcsClusterReplaceExecStream.

Definition at line 39 of file ClosableObject.cpp.

References ClosableObject::closeImpl(), and ClosableObject::needsClose.

Referenced by CacheImpl< PageT, VictimPolicyT >::allocatePages(), LcsRowScanBaseExecStream::closeImpl(), ExecStreamGraphImpl::closeImpl(), FlatFileBuffer::open(), ClosableObjectDestructor::operator()(), and Segment::~Segment().

void TraceSource::initTraceSource ( SharedTraceTarget pTraceTarget,
std::string name
) [virtual, inherited]
void TraceSource::trace ( TraceLevel level,
std::string message
) const [inherited]

| bool TraceSource::isTracing | ( | | ) | const [inline, inherited] | | --------------------------- | - | | - | --------------------------- |

bool TraceSource::isTracingLevel ( TraceLevel level ) const [inline, inherited]

| TraceTarget& TraceSource::getTraceTarget | ( | | ) | const [inline, inherited] | | ----------------------------------------------------------------- | - | | - | --------------------------- |

| std::string TraceSource::getTraceSourceName | ( | | ) | const [inline, inherited] | | ------------------------------------------- | - | | - | --------------------------- |

void TraceSource::setTraceSourceName ( std::string const & n ) [inline, inherited]

Sets the name of this source.

Useful to construct dynamic names for fine-grained filtering.

Definition at line 136 of file TraceSource.h.

00137 { 00138 name = n; 00139 }

| TraceLevel TraceSource::getMinimumTraceLevel | ( | | ) | const [inline, inherited] | | ------------------------------------------------------------------------------------------------------ | - | | - | --------------------------- |

| void TraceSource::disableTracing | ( | | ) | [inherited] | | -------------------------------- | - | | - | ------------- |


Member Data Documentation

Definition at line 75 of file Database.h.

Referenced by allocateHeader(), closeDevices(), createDataDevice(), createDataSegment(), createShadowLog(), createTempSegment(), createTxnLog(), createTxnLogSegment(), getCache(), initiateBackup(), loadHeader(), recover(), restoreFromBackup(), writeHeader(), and writeStats().

Definition at line 77 of file Database.h.

Referenced by allocateHeader(), createDataSegment(), createShadowLog(), createTempSegment(), createTxnLog(), createTxnLogSegment(), getSegmentFactory(), init(), initiateBackup(), loadHeader(), recover(), and restoreFromBackup().

Definition at line 81 of file Database.h.

Referenced by checkpointImpl(), closeDevices(), closeImpl(), completeBackup(), createDataSegment(), deallocateOldPages(), getDataSegment(), initiateBackup(), recoverPhysical(), restoreFromBackup(), and writeStats().

Definition at line 93 of file Database.h.

Referenced by allocateHeader(), checkpointImpl(), closeImpl(), createDataSegment(), createShadowLog(), createTxnLog(), getLastCommittedTxnId(), init(), loadHeader(), openSegments(), recover(), recoverOnline(), recoverPhysical(), restoreFromBackup(), and writeHeader().

Definition at line 38 of file SynchMonitoredObject.h.

Referenced by ParallelExecStreamScheduler::abort(), LogicalTxnLog::checkpoint(), checkpointImpl(), CheckpointThread::closeImpl(), LogicalTxnLog::commitTxn(), ParallelExecStreamScheduler::executeManager(), ParallelExecStreamScheduler::executeTask(), LogicalTxnLog::getOldestActiveTxnId(), LogicalTxnLog::newLogicalTxn(), ParallelExecStreamScheduler::readStream(), SXMutex::release(), GroupLock::release(), requestCheckpoint(), CheckpointThread::requestCheckpoint(), LogicalTxnLog::rollbackTxn(), TimerThread::run(), CheckpointThread::run(), ThreadPoolBase::runPooledThread(), SXMutex::setSchedulingPolicy(), TimerThread::signalImmediate(), ParallelExecStreamScheduler::signalSentinel(), ThreadPoolBase::start(), TimerThread::stop(), ThreadPoolBase::stop(), ParallelExecStreamScheduler::stop(), ThreadPool< RandomAccessRequest >::submitTask(), ParallelExecStreamScheduler::tryExecuteManager(), ParallelExecStreamScheduler::tryExecuteTask(), SXMutex::tryUpgrade(), SXMutex::waitFor(), GroupLock::waitFor(), and writeStats().

Definition at line 39 of file SynchMonitoredObject.h.

Referenced by ParallelExecStreamScheduler::abort(), checkpointImpl(), CheckpointThread::closeImpl(), LogicalTxnLog::commitTxnWithGroup(), ParallelExecStreamScheduler::executeTask(), ParallelExecStreamScheduler::readStream(), SXMutex::release(), GroupLock::release(), requestCheckpoint(), CheckpointThread::requestCheckpoint(), TimerThread::run(), CheckpointThread::run(), ThreadPoolBase::runPooledThread(), TimerThread::signalImmediate(), TimerThread::stop(), ThreadPoolBase::stop(), ParallelExecStreamScheduler::stop(), ThreadPool< RandomAccessRequest >::submitTask(), ParallelExecStreamScheduler::tryExecuteManager(), ParallelExecStreamScheduler::tryExecuteTask(), SXMutex::waitFor(), and GroupLock::waitFor().


The documentation for this class was generated from the following files:


Generated on Mon Jun 22 04:00:29 2009 for Fennel by doxygen 1.5.1