SegPageBackupRestoreDevice Class Reference

Device used to backup and restore pages from a data segment. More...

#include <SegPageBackupRestoreDevice.h>

Inheritance diagram for SegPageBackupRestoreDevice:

ClosableObject List of all members.

Public Member Functions

 SegPageBackupRestoreDevice (const std::string &backupFilePathname, const char *mode, const std::string &compressionProgram, uint nScratchPages, uint nReservedPages, SegmentAccessor &scratchAccessor, DeviceAccessScheduler &scheduler, SharedRandomAccessDevice pDataDevice)
 Opens a device that is used to backup and restore pages from a segment.
PBuffer getReservedBufferPage ()
 Returns a pointer to one of the reserved buffer pages.
void writeBackupPage (PConstBuffer pageBuffer)
 Writes a single page of data to the backup file.
void backupPage (BlockId blockId)
 Backs up a data page by scheduling a request to read it, then writing it to the backup file once the read request has been met.
void notifyReadTransferCompletion (BackupRestorePage &scratchPage, bool bSuccess)
 Receives notification that a read request has completed and writes the page to the backup file.
void restorePage (BlockId blockId)
 Restores a page by reading it from the backup file and then scheduling a request to write it to the data device.
void notifyWriteTransferCompletion (BackupRestorePage &scratchPage, bool bSuccess)
 Receives notification that a write request has completed.
void waitForPendingWrites ()
 Waits for any pending writes to complete.
StrictMutexgetMutex ()
 
Returns:
the mutex that ensures that only one thread is modifying this object

bool isClosed () const
 
Returns:
whether the object has been closed

void close ()
 Closes this object, releasing any unallocated resources.

Static Public Member Functions

static SharedSegPageBackupRestoreDevice newSegPageBackupRestoreDevice (const std::string &backupFilePathname, const char *mode, const std::string &compressionProgram, uint nScratchPages, uint nReservedPages, SegmentAccessor &scratchAccessor, DeviceAccessScheduler &scheduler, SharedRandomAccessDevice pDataDevice)
 Creates a new SegPageBackupRestoreDevice, returning a shared pointer to the object.

Protected Attributes

bool needsClose

Private Types

typedef std::hash_map< BlockNum,
BackupRestorePage * > 
PendingWriteMap
typedef PendingWriteMap::iterator PendingWriteMapIter

Private Member Functions

void init ()
 Initializes the backup/restore device.
void setCompressionProgramPathname (const std::string &programName)
 Determines the full pathname for a compression program by locating the program either in /bin or /usr/bin.
void initScratchPages (SegPageLock &scratchLock, uint nScratchPages, uint nReservedPages, uint bufferSize)
 Allocates scratch pages used by backup and restore.
BackupRestorePagegetFreeScratchPage ()
 Retrieves an available scratch page.
void freeScratchPage (BackupRestorePage &scratchPage)
 Puts the scratch page that is no longer being used back into the free scratch page queue, increments counters tracking which page needs to be written next to the backup file, and notifies any threads waiting for a free scratch page.
void writeBackupPage (PConstBuffer pageBuffer, bool scheduledWrite)
 Writes a single page of data to the backup file.
void checkPendingException ()
 Determines if there is a pending I/O exception, and if so, throws the exception.
virtual void closeImpl ()
 Must be implemented by derived class to release any resources.

Private Attributes

std::string backupFilePathname
 Full pathname of the backup file.
uint nReservedPages
 Number of reserved scratch pages available.
SegmentAccessor scratchAccessor
 Scratch accessor used for temporary buffers.
DeviceAccessSchedulerscheduler
 Scheduler for I/O requests.
SharedRandomAccessDevice pDataDevice
 Device corresponding to the segment pages that are backed up or restored.
char * mode
 String value indicating how the device should be opened.
std::string compressionProgram
uint nScratchPages
bool isCompressed
 True if the backup file is compressed.
SegPageLock scratchLock
 Scratch lock.
FILE * backupFile
 File stream for the backup file.
uint pageSize
 Size of each page backed up or restored.
boost::scoped_array< PBufferreservedPages
 Array of reserved scratch pages.
std::vector< BackupRestorePage * > freeScratchPageQueue
 Queue of free scratch pages that can be used to read/write pages during backup and restore.
LocalCondition freeScratchPageCondition
 Condition variable used for notification of free scratch page availability.
StrictMutex mutex
 Mutex to ensure that only one thread is modifying shared data.
PendingWriteMap pendingWriteMap
 A map containing pages waiting to be written to the backup file.
BlockNum currPageReadCount
 In the case of a backup, the counter corresponding to the page that needs to be read, for reads that are scheduled.
BlockNum currPageWriteCount
 In case of a backup, the counter corresponding to the page that needs to be written to the backup file, for pages for which the reads were scheduled.
boost::scoped_array< BackupRestorePagebackupRestorePages
 Array of requests, representing pages being backed up or restored.
boost::scoped_ptr< FennelExcnpPendingExcn
 Pending exception, if there is one.

Detailed Description

Device used to backup and restore pages from a data segment.

Definition at line 126 of file SegPageBackupRestoreDevice.h.


Member Typedef Documentation

typedef std::hash_map<BlockNum, BackupRestorePage *> SegPageBackupRestoreDevice::PendingWriteMap [private]

Definition at line 215 of file SegPageBackupRestoreDevice.h.

typedef PendingWriteMap::iterator SegPageBackupRestoreDevice::PendingWriteMapIter [private]

Definition at line 217 of file SegPageBackupRestoreDevice.h.


Constructor & Destructor Documentation

SegPageBackupRestoreDevice::SegPageBackupRestoreDevice ( const std::string &  backupFilePathname,
const char *  mode,
const std::string &  compressionProgram,
uint  nScratchPages,
uint  nReservedPages,
SegmentAccessor scratchAccessor,
DeviceAccessScheduler scheduler,
SharedRandomAccessDevice  pDataDevice 
)

Opens a device that is used to backup and restore pages from a segment.

Parameters:
backupFilePathname pathname of the backup file
mode string indicating how the device should be opened
compressionProgram if non-empty string, the name of the program to use to compress or decompress the backup file
nScratchPages number of scratch pages to allocate for backing up and restoring data pages
nReservedPages additional scratch pages to allocate for special reserved buffers
scratchAccessor accessor used to allocate temporary scratch buffers
scheduler scheduler used for scheduling I/O requests
pDataDevice the device containing the data segment pages that will be backed up or restored

Definition at line 115 of file SegPageBackupRestoreDevice.cpp.

References backupFile, currPageReadCount, currPageWriteCount, mode, nScratchPages, and setCompressionProgramPathname().

Referenced by newSegPageBackupRestoreDevice().

00123                                               :
00124     backupFilePathname(backupFilePathnameInit),
00125     nReservedPages(nReservedPagesInit),
00126     scratchAccessor(scratchAccessorInit),
00127     scheduler(schedulerInit),
00128     pDataDevice(pDataDeviceInit)
00129 {
00130     mode = (char *) modeInit;
00131     setCompressionProgramPathname(compressionProgramInit);
00132     nScratchPages = nScratchPagesInit;
00133     currPageReadCount = 0;
00134     currPageWriteCount = 0;
00135     backupFile = NULL;
00136 }


Member Function Documentation

void SegPageBackupRestoreDevice::init (  )  [private]

Initializes the backup/restore device.

Definition at line 138 of file SegPageBackupRestoreDevice.cpp.

References SegPageLock::accessSegment(), backupFile, backupFilePathname, compressionProgram, initScratchPages(), isCompressed, mode, nReservedPages, nScratchPages, pageSize, SegmentAccessor::pSegment, scratchAccessor, and scratchLock.

00139 {
00140     if (compressionProgram.length() == 0) {
00141         backupFile = fopen(backupFilePathname.c_str(), mode);
00142         isCompressed = false;
00143     } else {
00144 #ifdef __MSVC__
00145         throw FennelExcn(
00146             FennelResource::instance().unsupportedOperation("popen"));
00147 #else
00148         std::ostringstream cmd;
00149         if (mode[0] == 'r') {
00150             cmd << compressionProgram.c_str() << " -dc "
00151                 << backupFilePathname.c_str();
00152         } else {
00153             cmd << compressionProgram.c_str() << " > "
00154                 << backupFilePathname.c_str();
00155         }
00156         backupFile = popen(cmd.str().c_str(), mode);
00157         isCompressed = true;
00158 #endif
00159     }
00160 
00161     if (backupFile == NULL) {
00162         throw SysCallExcn(
00163             FennelResource::instance().openBackupFileFailed(
00164                 backupFilePathname));
00165     }
00166 
00167     scratchLock.accessSegment(scratchAccessor);
00168     pageSize = scratchAccessor.pSegment->getUsablePageSize();
00169     initScratchPages(scratchLock, nScratchPages, nReservedPages, pageSize);
00170 }

void SegPageBackupRestoreDevice::setCompressionProgramPathname ( const std::string &  programName  )  [private]

Determines the full pathname for a compression program by locating the program either in /bin or /usr/bin.

If the program doesn't exist in either, then the user must specify the location of the program via their path.

Parameters:
programName name of the compression program, or an empty string if compression isn't being used

Definition at line 172 of file SegPageBackupRestoreDevice.cpp.

References compressionProgram, and FileSystem::doesFileExist().

Referenced by SegPageBackupRestoreDevice().

00174 {
00175     if (programName.length() == 0) {
00176         compressionProgram = "";
00177     } else {
00178         std::string path = "/bin/";
00179         compressionProgram = path + programName;
00180         if (!FileSystem::doesFileExist(compressionProgram.c_str())) {
00181             path = "/usr/bin/";
00182             compressionProgram = path + programName;
00183             if (!FileSystem::doesFileExist(compressionProgram.c_str())) {
00184                 compressionProgram = programName;
00185             }
00186         }
00187     }
00188 }

void SegPageBackupRestoreDevice::initScratchPages ( SegPageLock scratchLock,
uint  nScratchPages,
uint  nReservedPages,
uint  bufferSize 
) [private]

Allocates scratch pages used by backup and restore.

Parameters:
scratchLock scratch lock used to allocate pages
nScratchPages the number of scratch pages to allocate
nReservedPages the number of reserved scratch pages to allocate
bufferSize size of scratch page buffers

Definition at line 190 of file SegPageBackupRestoreDevice.cpp.

References SegPageLock::allocatePage(), backupRestorePages, freeScratchPageQueue, SegPageLock::getPage(), CachePage::getWritableData(), mutex, pageSize, reservedPages, and scratchLock.

Referenced by init().

00195 {
00196     StrictMutexGuard mutexGuard(mutex);
00197 
00198     // Allocate an array of requests and associate a scratch page with each
00199     // one.  Initialize the free scratch page queue with these requests.
00200     backupRestorePages.reset(new BackupRestorePage[nScratchPages]);
00201     for (uint i = 0; i < nScratchPages; i++) {
00202         scratchLock.allocatePage();
00203         backupRestorePages[i].setParent(
00204             WeakSegPageBackupRestoreDevice(shared_from_this()));
00205         backupRestorePages[i].setBufferSize(pageSize);
00206         backupRestorePages[i].setBuffer(
00207             scratchLock.getPage().getWritableData());
00208         freeScratchPageQueue.push_back(&backupRestorePages[i]);
00209     }
00210 
00211     reservedPages.reset(new PBuffer[nReservedPages]);
00212     for (uint i = 0; i < nReservedPages; i++) {
00213         scratchLock.allocatePage();
00214         reservedPages[i] = scratchLock.getPage().getWritableData();
00215     }
00216 }

BackupRestorePage * SegPageBackupRestoreDevice::getFreeScratchPage (  )  [private]

Retrieves an available scratch page.

Waits if necessary until a free scratch page is available.

Returns:
a pointer to a scratch page

Definition at line 272 of file SegPageBackupRestoreDevice.cpp.

References checkPendingException(), convertTimeout(), freeScratchPageCondition, freeScratchPageQueue, and mutex.

Referenced by backupPage(), and restorePage().

00273 {
00274     while (true) {
00275         StrictMutexGuard mutexGuard(mutex);
00276         if (!freeScratchPageQueue.empty()) {
00277             BackupRestorePage *freePage = freeScratchPageQueue.back();
00278             freeScratchPageQueue.pop_back();
00279             return freePage;
00280         }
00281 
00282         // If no page is available, wait for one to become available (with
00283         // timeout just in case)
00284         boost::xtime atv;
00285         convertTimeout(100, atv);
00286         freeScratchPageCondition.timed_wait(mutexGuard, atv);
00287         checkPendingException();
00288     }
00289 }

void SegPageBackupRestoreDevice::freeScratchPage ( BackupRestorePage scratchPage  )  [private]

Puts the scratch page that is no longer being used back into the free scratch page queue, increments counters tracking which page needs to be written next to the backup file, and notifies any threads waiting for a free scratch page.

Parameters:
scratchPage scratch page that's now free

Definition at line 331 of file SegPageBackupRestoreDevice.cpp.

References currPageWriteCount, freeScratchPageCondition, and freeScratchPageQueue.

Referenced by notifyReadTransferCompletion(), and notifyWriteTransferCompletion().

00332 {
00333     ++currPageWriteCount;
00334     freeScratchPageQueue.push_back(&scratchPage);
00335     freeScratchPageCondition.notify_all();
00336 }

void SegPageBackupRestoreDevice::writeBackupPage ( PConstBuffer  pageBuffer,
bool  scheduledWrite 
) [private]

Writes a single page of data to the backup file.

Parameters:
pageBuffer buffer containing the page data
scheduledWrite true if the write was scheduled by the device scheduler

Definition at line 231 of file SegPageBackupRestoreDevice.cpp.

References backupFile, backupFilePathname, pageSize, and pPendingExcn.

Referenced by notifyReadTransferCompletion(), and writeBackupPage().

00234 {
00235     size_t pagesWritten = fwrite(pageBuffer, pageSize, 1, backupFile);
00236     if (pagesWritten < 1) {
00237         if (!scheduledWrite) {
00238             throw SysCallExcn(
00239                 FennelResource::instance().writeBackupFileFailed(
00240                     backupFilePathname));
00241         } else if (!pPendingExcn) {
00242             // For scheduled writes, indicate that an exception has occurred
00243             // so the calling thread can return the exception, unless there
00244             // already is a pending exception.
00245             pPendingExcn.reset(
00246                 new SysCallExcn(
00247                     FennelResource::instance().writeBackupFileFailed(
00248                         backupFilePathname)));
00249         }
00250     }
00251 }

void SegPageBackupRestoreDevice::checkPendingException (  )  [private]

Determines if there is a pending I/O exception, and if so, throws the exception.

Definition at line 390 of file SegPageBackupRestoreDevice.cpp.

References pPendingExcn.

Referenced by getFreeScratchPage(), and waitForPendingWrites().

00391 {
00392     if (pPendingExcn) {
00393         pPendingExcn->throwSelf();
00394     }
00395 }

void SegPageBackupRestoreDevice::closeImpl (  )  [private, virtual]

Must be implemented by derived class to release any resources.

Implements ClosableObject.

Definition at line 397 of file SegPageBackupRestoreDevice.cpp.

References backupFile, backupRestorePages, freeScratchPageQueue, isCompressed, mutex, NULL_PAGE_ID, SegmentAccessor::pSegment, reservedPages, scratchAccessor, and waitForPendingWrites().

00398 {
00399     // Wait for any pending writes to complete before freeing up structures
00400     // because those writes were issued as async requests and their
00401     // notifications will need to come back to this object.
00402     waitForPendingWrites();
00403 
00404     StrictMutexGuard mutexGuard(mutex);
00405     if (scratchAccessor.pSegment) {
00406         scratchAccessor.pSegment->deallocatePageRange(
00407             NULL_PAGE_ID, NULL_PAGE_ID);
00408     }
00409     backupRestorePages.reset();
00410     reservedPages.reset();
00411     freeScratchPageQueue.clear();
00412     if (backupFile != NULL) {
00413         if (isCompressed) {
00414 #ifdef __MSVC__
00415         throw FennelExcn(
00416             FennelResource::instance().unsupportedOperation("pclose"));
00417 #else
00418             pclose(backupFile);
00419 #endif
00420         } else {
00421             fclose(backupFile);
00422         }
00423         backupFile = NULL;
00424     }
00425 }

SharedSegPageBackupRestoreDevice SegPageBackupRestoreDevice::newSegPageBackupRestoreDevice ( const std::string &  backupFilePathname,
const char *  mode,
const std::string &  compressionProgram,
uint  nScratchPages,
uint  nReservedPages,
SegmentAccessor scratchAccessor,
DeviceAccessScheduler scheduler,
SharedRandomAccessDevice  pDataDevice 
) [static]

Creates a new SegPageBackupRestoreDevice, returning a shared pointer to the object.

Parameters:
backupFilePathname pathname of the backup file
mode string indicating how the device should be opened
compressionProgram if non-empty string, the name of the program to use to compress or decompress the backup file
nScratchPages number of scratch pages to allocate for backing up and restoring data pages
nReservedPages additional scratch pages to allocate for special reserved buffers
scratchAccessor accessor used to allocate temporary scratch buffers
scheduler scheduler used for scheduling I/O requests
pDataDevice the device containing the data segment pages that will be backed up or restored
Returns:
shared pointer to the new object

Definition at line 89 of file SegPageBackupRestoreDevice.cpp.

References scheduler, scratchAccessor, and SegPageBackupRestoreDevice().

Referenced by BackupRestoreTest::backup(), Database::initiateBackup(), BackupRestoreTest::restore(), and Database::restoreFromBackup().

00098 {
00099     SharedSegPageBackupRestoreDevice pDevice =
00100         SharedSegPageBackupRestoreDevice(
00101             new SegPageBackupRestoreDevice(
00102                 backupFilePathname,
00103                 mode,
00104                 compressionProgram,
00105                 nScratchPages,
00106                 nReservedPages,
00107                 scratchAccessor,
00108                 scheduler,
00109                 pDataDevice),
00110             ClosableObjectDestructor());
00111     pDevice->init();
00112     return pDevice;
00113 }

PBuffer SegPageBackupRestoreDevice::getReservedBufferPage (  ) 

Returns a pointer to one of the reserved buffer pages.

The number of calls to this method cannot exceed the number of reserved buffers available.

Returns:
pointer to an available reserved buffer; NULL if no more buffers are available

Definition at line 218 of file SegPageBackupRestoreDevice.cpp.

References nReservedPages, and reservedPages.

00219 {
00220     if (nReservedPages == 0) {
00221         assert(false);
00222     }
00223     return reservedPages[--nReservedPages];
00224 }

void SegPageBackupRestoreDevice::writeBackupPage ( PConstBuffer  pageBuffer  ) 

Writes a single page of data to the backup file.

Parameters:
pageBuffer the buffer containing the data

Definition at line 226 of file SegPageBackupRestoreDevice.cpp.

References writeBackupPage().

00227 {
00228     writeBackupPage(pageBuffer, false);
00229 }

void SegPageBackupRestoreDevice::backupPage ( BlockId  blockId  ) 

Backs up a data page by scheduling a request to read it, then writing it to the backup file once the read request has been met.

Parameters:
blockId block id of the page that needs to be backed up

Definition at line 253 of file SegPageBackupRestoreDevice.cpp.

References RandomAccessRequest::bindingList, RandomAccessRequest::cbOffset, RandomAccessRequest::cbTransfer, currPageReadCount, CompoundId::getBlockNum(), getFreeScratchPage(), pageSize, pDataDevice, RandomAccessRequest::pDevice, RandomAccessRequest::READ, DeviceAccessScheduler::schedule(), scheduler, BackupRestorePage::setPageCounter(), BackupRestorePage::setReadRequest(), and RandomAccessRequest::type.

00254 {
00255     // This only schedules the read request.  Later when the read request
00256     // has been met, the write will be done in notifyReadTransferCompletion.
00257 
00258     // First, find a free scratch page
00259     BackupRestorePage *pScratchPage = getFreeScratchPage();
00260 
00261     pScratchPage->setPageCounter(currPageReadCount++);
00262     RandomAccessRequest request;
00263     request.pDevice = pDataDevice.get();
00264     request.cbOffset = (FileSize) pageSize * CompoundId::getBlockNum(blockId);
00265     request.cbTransfer = pageSize;
00266     request.type = RandomAccessRequest::READ;
00267     pScratchPage->setReadRequest(true);
00268     request.bindingList.push_back(*pScratchPage);
00269     scheduler.schedule(request);
00270 }

void SegPageBackupRestoreDevice::notifyReadTransferCompletion ( BackupRestorePage scratchPage,
bool  bSuccess 
)

Receives notification that a read request has completed and writes the page to the backup file.

Parameters:
scratchPage the scratch page containing the data read
bSuccess whether the request was successful

Definition at line 291 of file SegPageBackupRestoreDevice.cpp.

References currPageWriteCount, freeScratchPage(), BackupRestorePage::getBuffer(), BackupRestorePage::getPageCounter(), pendingWriteMap, pPendingExcn, and writeBackupPage().

00294 {
00295     if (!bSuccess) {
00296         if (!pPendingExcn) {
00297             pPendingExcn.reset(
00298                 new SysCallExcn(
00299                     FennelResource::instance().readDataPageFailed()));
00300         }
00301         return;
00302     }
00303 
00304 
00305     // If the page read is the next one to be written, write it out to the
00306     // backup file.  Otherwise, add it to the map of pending pages to
00307     // be written out.
00308     if (scratchPage.getPageCounter() == currPageWriteCount) {
00309         writeBackupPage(scratchPage.getBuffer(), true);
00310         freeScratchPage(scratchPage);
00311     } else {
00312         pendingWriteMap[scratchPage.getPageCounter()] = &scratchPage;
00313     }
00314 
00315     // Go back and see if the next set of pages that need to be written are
00316     // already in the pending write queue.  If they are, write them out.
00317     while (true) {
00318         PendingWriteMapIter iter = pendingWriteMap.find(currPageWriteCount);
00319         if (iter == pendingWriteMap.end()) {
00320             break;
00321         }
00322         BackupRestorePage *nextPage = iter->second;
00323         pendingWriteMap.erase(currPageWriteCount);
00324         writeBackupPage(nextPage->getBuffer(), true);
00325         freeScratchPage(*nextPage);
00326         // freeScratchPage increments currPageWriteCount, so loop to see
00327         // if that next page is available to be written
00328     }
00329 }

void SegPageBackupRestoreDevice::restorePage ( BlockId  blockId  ) 

Restores a page by reading it from the backup file and then scheduling a request to write it to the data device.

Parameters:
blockId block id of the page that needs to be restored

Definition at line 349 of file SegPageBackupRestoreDevice.cpp.

References backupFile, backupFilePathname, RandomAccessRequest::bindingList, RandomAccessRequest::cbOffset, RandomAccessRequest::cbTransfer, currPageReadCount, CompoundId::getBlockNum(), BackupRestorePage::getBuffer(), getFreeScratchPage(), pageSize, pDataDevice, RandomAccessRequest::pDevice, DeviceAccessScheduler::schedule(), scheduler, BackupRestorePage::setPageCounter(), BackupRestorePage::setReadRequest(), RandomAccessRequest::type, and RandomAccessRequest::WRITE.

00350 {
00351     // Get a free scratch buffer to read the page from the backup file
00352     BackupRestorePage *pScratchPage = getFreeScratchPage();
00353 
00354     size_t pagesRead =
00355         fread(pScratchPage->getBuffer(), pageSize, 1, backupFile);
00356     if (pagesRead < 1) {
00357         throw SysCallExcn(
00358             FennelResource::instance().readBackupFileFailed(
00359                 backupFilePathname));
00360     }
00361 
00362     // Schedule a request to write it
00363     pScratchPage->setPageCounter(currPageReadCount++);
00364     RandomAccessRequest request;
00365     request.pDevice = pDataDevice.get();
00366     request.cbOffset = (FileSize) pageSize * CompoundId::getBlockNum(blockId);
00367     request.cbTransfer = pageSize;
00368     request.type = RandomAccessRequest::WRITE;
00369     pScratchPage->setReadRequest(false);
00370     request.bindingList.push_back(*pScratchPage);
00371     scheduler.schedule(request);
00372 }

void SegPageBackupRestoreDevice::notifyWriteTransferCompletion ( BackupRestorePage scratchPage,
bool  bSuccess 
)

Receives notification that a write request has completed.

Frees the scratch buffer associated with the request.

Parameters:
scratchPage the scratch page containing the data read
bSuccess whether the request was successful

Definition at line 374 of file SegPageBackupRestoreDevice.cpp.

References freeScratchPage(), and pPendingExcn.

00377 {
00378     if (!bSuccess) {
00379         if (!pPendingExcn) {
00380             pPendingExcn.reset(
00381                 new SysCallExcn(
00382                     FennelResource::instance().writeDataPageFailed()));
00383         }
00384         return;
00385     }
00386 
00387     freeScratchPage(scratchPage);
00388 }

void SegPageBackupRestoreDevice::waitForPendingWrites (  ) 

Waits for any pending writes to complete.

Definition at line 338 of file SegPageBackupRestoreDevice.cpp.

References checkPendingException(), currPageReadCount, currPageWriteCount, freeScratchPageCondition, and mutex.

Referenced by closeImpl().

00339 {
00340     StrictMutexGuard mutexGuard(mutex);
00341     while (currPageWriteCount < currPageReadCount) {
00342         freeScratchPageCondition.wait(mutexGuard);
00343         checkPendingException();
00344     }
00345 
00346     checkPendingException();
00347 }

StrictMutex & SegPageBackupRestoreDevice::getMutex (  ) 

Returns:
the mutex that ensures that only one thread is modifying this object

Definition at line 427 of file SegPageBackupRestoreDevice.cpp.

References mutex.

00428 {
00429     return mutex;
00430 }

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

Returns:
whether the object has been closed

Definition at line 58 of file ClosableObject.h.

00059     {
00060         return !needsClose;
00061     }

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().

00040 {
00041     if (!needsClose) {
00042         return;
00043     }
00044     needsClose = false;
00045     closeImpl();
00046 }


Member Data Documentation

std::string SegPageBackupRestoreDevice::backupFilePathname [private]

Full pathname of the backup file.

Definition at line 134 of file SegPageBackupRestoreDevice.h.

Referenced by init(), restorePage(), and writeBackupPage().

uint SegPageBackupRestoreDevice::nReservedPages [private]

Number of reserved scratch pages available.

Definition at line 139 of file SegPageBackupRestoreDevice.h.

Referenced by getReservedBufferPage(), and init().

SegmentAccessor SegPageBackupRestoreDevice::scratchAccessor [private]

Scratch accessor used for temporary buffers.

Definition at line 144 of file SegPageBackupRestoreDevice.h.

Referenced by closeImpl(), init(), and newSegPageBackupRestoreDevice().

DeviceAccessScheduler& SegPageBackupRestoreDevice::scheduler [private]

Scheduler for I/O requests.

Definition at line 149 of file SegPageBackupRestoreDevice.h.

Referenced by backupPage(), newSegPageBackupRestoreDevice(), and restorePage().

SharedRandomAccessDevice SegPageBackupRestoreDevice::pDataDevice [private]

Device corresponding to the segment pages that are backed up or restored.

Definition at line 154 of file SegPageBackupRestoreDevice.h.

Referenced by backupPage(), and restorePage().

char* SegPageBackupRestoreDevice::mode [private]

String value indicating how the device should be opened.

Definition at line 159 of file SegPageBackupRestoreDevice.h.

Referenced by init(), and SegPageBackupRestoreDevice().

std::string SegPageBackupRestoreDevice::compressionProgram [private]

Definition at line 165 of file SegPageBackupRestoreDevice.h.

Referenced by init(), and setCompressionProgramPathname().

uint SegPageBackupRestoreDevice::nScratchPages [private]

Definition at line 171 of file SegPageBackupRestoreDevice.h.

Referenced by init(), and SegPageBackupRestoreDevice().

bool SegPageBackupRestoreDevice::isCompressed [private]

True if the backup file is compressed.

Definition at line 176 of file SegPageBackupRestoreDevice.h.

Referenced by closeImpl(), and init().

SegPageLock SegPageBackupRestoreDevice::scratchLock [private]

Scratch lock.

Definition at line 181 of file SegPageBackupRestoreDevice.h.

Referenced by init(), and initScratchPages().

FILE* SegPageBackupRestoreDevice::backupFile [private]

File stream for the backup file.

Definition at line 186 of file SegPageBackupRestoreDevice.h.

Referenced by closeImpl(), init(), restorePage(), SegPageBackupRestoreDevice(), and writeBackupPage().

uint SegPageBackupRestoreDevice::pageSize [private]

Size of each page backed up or restored.

Definition at line 191 of file SegPageBackupRestoreDevice.h.

Referenced by backupPage(), init(), initScratchPages(), restorePage(), and writeBackupPage().

boost::scoped_array<PBuffer> SegPageBackupRestoreDevice::reservedPages [private]

Array of reserved scratch pages.

Definition at line 196 of file SegPageBackupRestoreDevice.h.

Referenced by closeImpl(), getReservedBufferPage(), and initScratchPages().

std::vector<BackupRestorePage *> SegPageBackupRestoreDevice::freeScratchPageQueue [private]

Queue of free scratch pages that can be used to read/write pages during backup and restore.

Definition at line 202 of file SegPageBackupRestoreDevice.h.

Referenced by closeImpl(), freeScratchPage(), getFreeScratchPage(), and initScratchPages().

LocalCondition SegPageBackupRestoreDevice::freeScratchPageCondition [private]

Condition variable used for notification of free scratch page availability.

Definition at line 208 of file SegPageBackupRestoreDevice.h.

Referenced by freeScratchPage(), getFreeScratchPage(), and waitForPendingWrites().

StrictMutex SegPageBackupRestoreDevice::mutex [private]

Mutex to ensure that only one thread is modifying shared data.

Definition at line 213 of file SegPageBackupRestoreDevice.h.

Referenced by closeImpl(), getFreeScratchPage(), getMutex(), initScratchPages(), and waitForPendingWrites().

PendingWriteMap SegPageBackupRestoreDevice::pendingWriteMap [private]

A map containing pages waiting to be written to the backup file.

Each page is keyed by the page's destination count within the backup file.

Definition at line 223 of file SegPageBackupRestoreDevice.h.

Referenced by notifyReadTransferCompletion().

BlockNum SegPageBackupRestoreDevice::currPageReadCount [private]

In the case of a backup, the counter corresponding to the page that needs to be read, for reads that are scheduled.

In the case of a restore, the counter corresponding to the page currently read from the backup file.

Definition at line 231 of file SegPageBackupRestoreDevice.h.

Referenced by backupPage(), restorePage(), SegPageBackupRestoreDevice(), and waitForPendingWrites().

BlockNum SegPageBackupRestoreDevice::currPageWriteCount [private]

In case of a backup, the counter corresponding to the page that needs to be written to the backup file, for pages for which the reads were scheduled.

In the case of a restore, the counter corresponding to pages that have been written to the data device.

Definition at line 239 of file SegPageBackupRestoreDevice.h.

Referenced by freeScratchPage(), notifyReadTransferCompletion(), SegPageBackupRestoreDevice(), and waitForPendingWrites().

boost::scoped_array<BackupRestorePage> SegPageBackupRestoreDevice::backupRestorePages [private]

Array of requests, representing pages being backed up or restored.

Definition at line 244 of file SegPageBackupRestoreDevice.h.

Referenced by closeImpl(), and initScratchPages().

boost::scoped_ptr<FennelExcn> SegPageBackupRestoreDevice::pPendingExcn [private]

Pending exception, if there is one.

Definition at line 249 of file SegPageBackupRestoreDevice.h.

Referenced by checkPendingException(), notifyReadTransferCompletion(), notifyWriteTransferCompletion(), and writeBackupPage().

bool ClosableObject::needsClose [protected, inherited]

Definition at line 44 of file ClosableObject.h.

Referenced by SegStreamAllocation::beginWrite(), ExecStreamGraphImpl::clear(), ClosableObject::ClosableObject(), ClosableObject::close(), FlatFileBuffer::open(), ExecStreamGraphImpl::open(), ExecStream::open(), and ClosableObject::~ClosableObject().


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