SegNodeLock< Node > Class Template Reference

SegNodeLock refines SegPageLock to allow typecasting to be hidden. More...

#include <SegPageLock.h>

Inheritance diagram for SegNodeLock< Node >:

SegPageLock List of all members.

Public Member Functions

 SegNodeLock ()
 SegNodeLock (SegmentAccessor &segmentAccessor)
bool checkMagicNumber () const
Node const & getNodeForRead () const
Node & getNodeForWrite ()
PageId allocatePage (PageOwnerId ownerId=ANON_PAGE_OWNER_ID)
PageId tryAllocatePage (PageOwnerId ownerId=ANON_PAGE_OWNER_ID)
void setMagicNumber ()
bool isMagicNumberValid ()
void accessSegment (SegmentAccessor const &segmentAccessorInit)
bool isLocked () const
CachePagegetPage () const
void deallocateLockedPage ()
void deallocateUnlockedPage (PageId pageId)
void unlock ()
void dontUnlock ()
void lockPage (PageId pageId, LockMode lockModeInit, bool readIfUnmapped=true)
void lockPageWithCoupling (PageId pageId, LockMode lockModeInit)
void lockShared (PageId pageId)
void lockExclusive (PageId pageId)
void lockSharedNoWait (PageId pageId)
void lockExclusiveNoWait (PageId pageId)
void updatePage ()
void lockUpdatePage (PageId updatePageId)
PageId getPageId ()
void flushPage (bool async)
void swapBuffers (SegPageLock &other)
bool tryUpgrade ()
SharedCacheAccessor getCacheAccessor () const

Private Member Functions

void verifyMagicNumber (Node const &node) const

Detailed Description

template<class Node>
class SegNodeLock< Node >

SegNodeLock refines SegPageLock to allow typecasting to be hidden.

Whereas a SegPageLock references an arbitrary CachePage, usage of SegNodeLock demonstrates the intention to lock only pages of a given type. The Node template parameter determines the derived class of StoredNode. It must have a static member MAGIC_NUMBER defining its unique magic number. (To generate these, I run uuidgen on Linux and take the last 16 nybbles.)

For more information, see the HOWTO.

Definition at line 414 of file SegPageLock.h.


Constructor & Destructor Documentation

template<class Node>
SegNodeLock< Node >::SegNodeLock (  )  [inline, explicit]

Definition at line 422 of file SegPageLock.h.

00423     {
00424     }

template<class Node>
SegNodeLock< Node >::SegNodeLock ( SegmentAccessor segmentAccessor  )  [inline, explicit]

Definition at line 426 of file SegPageLock.h.

00428         : SegPageLock(segmentAccessor)
00429     {
00430     }


Member Function Documentation

template<class Node>
void SegNodeLock< Node >::verifyMagicNumber ( Node const &  node  )  const [inline, private]

Definition at line 416 of file SegPageLock.h.

Referenced by SegNodeLock< Node >::getNodeForRead().

00417     {
00418         assert(node.magicNumber == Node::MAGIC_NUMBER);
00419     }

template<class Node>
bool SegNodeLock< Node >::checkMagicNumber (  )  const [inline]

Definition at line 432 of file SegPageLock.h.

References SegPageLock::getPage(), and CachePage::getReadableData().

Referenced by VersionedRandomAllocationSegment::allocateAllocNodes(), and Database::loadHeader().

00433     {
00434         Node const &node =
00435             *reinterpret_cast<Node const *>(getPage().getReadableData());
00436         return (node.magicNumber == Node::MAGIC_NUMBER);
00437     }

template<class Node>
Node const& SegNodeLock< Node >::getNodeForRead (  )  const [inline]

Definition at line 439 of file SegPageLock.h.

References SegPageLock::getPage(), CachePage::getReadableData(), and SegNodeLock< Node >::verifyMagicNumber().

Referenced by BTreeReader::accessLeafTuple(), RandomAllocationSegmentBase::allocatePageIdFromSegment(), VersionedRandomAllocationSegment::backupAllocationNodes(), BTreeWriter::checkMonotonicity(), VersionedRandomAllocationSegment::copyPageEntryToTemp(), BTreeAccessBase::getFirstChild(), VersionedRandomAllocationSegment::getOldestTxnId(), VersionedRandomAllocationSegment::getOldPageIds(), FixedBuildLevel::indexLastKey(), BTreeBuildLevel::isFinished(), BTreeNonLeafReader::isPositionedOnInfinityKey(), BTreeNonLeafReader::isRootOnly(), Database::loadHeader(), VersionedRandomAllocationSegment::locateDataPages(), SegInputStream::lockBuffer(), CrcSegInputStream::lockBufferParanoid(), BTreeWriter::lockParentPage(), LcsClusterReader::moveToBlock(), LcsClusterReader::moveToBlockWithRid(), LcsClusterReader::readClusterPage(), VersionedRandomAllocationSegment::restoreFromBackup(), BTreeLeafReader::searchExtreme(), BTreeReader::searchExtremeInternal(), BTreeReader::searchForKeyTemplate(), BTreeReader::searchNext(), BTreeNonLeafReader::searchNext(), BTreeLeafReader::searchNext(), BTreeReader::searchNextInternal(), BTreeWriter::splitCurrentNode(), RandomAllocationSegmentBase::tallySegAllocNodePages(), BTreeBuilder::truncate(), BTreeBuilder::truncateChildren(), VersionedRandomAllocationSegment::uncommittedDeallocation(), BTreeBuildLevel::unmarshalLastKey(), VersionedRandomAllocationSegment::validateFreePageCount(), BTreeVerifier::verifyNode(), and BackupRestoreTest::verifySnapshotData().

00440     {
00441         Node const &node =
00442             *reinterpret_cast<Node const *>(getPage().getReadableData());
00443         verifyMagicNumber(node);
00444         return node;
00445     }

template<class Node>
Node& SegNodeLock< Node >::getNodeForWrite (  )  [inline]

Definition at line 447 of file SegPageLock.h.

References SegPageLock::getPage(), CachePage::getWritableData(), and SegPageLock::updatePage().

Referenced by VersionedRandomAllocationSegment::allocateAllocNodes(), BTreeBuildLevel::allocateAndLinkNewNode(), LcsClusterNodeWriter::allocateClusterPage(), Database::allocateHeader(), BTreeBuildLevel::allocatePage(), RandomAllocationSegmentBase::allocatePageIdFromSegment(), BTreeWriter::attemptInsertWithoutSplit(), BTreeBuilder::buildBalanced(), VersionedRandomAllocationSegment::chainPageEntries(), BTreeWriter::compactNode(), VersionedRandomAllocationSegment::copyPageEntryFromTemp(), VersionedRandomAllocationSegment::copyPageEntryToTemp(), BTreeBuilder::createEmptyRoot(), BackupRestoreTest::createSnapshotData(), RandomAllocationSegmentBase::deallocatePageId(), VersionedRandomAllocationSegment::deallocateSinglePage(), VersionedRandomAllocationSegment::deferDeallocation(), BTreeWriter::deleteCurrent(), BackupRestoreTest::executeSnapshotTxn(), SegOutputStream::flushBuffer(), RandomAllocationSegmentBase::format(), LcsClusterNodeWriter::getLastClusterPageForWrite(), BTreeWriter::grow(), BTreeBuildLevel::indexLastChild(), VersionedRandomAllocationSegment::initPageEntry(), BTreeBuildLevel::processInput(), SegNodeLock< Node >::setMagicNumber(), BTreeWriter::splitCurrentNode(), BTreeBuilder::swapRoot(), BTreeBuilder::truncate(), BTreeWriter::updateCurrent(), VersionedRandomAllocationSegment::updateExtentEntry(), SegOutputStream::updatePage(), VersionedRandomAllocationSegment::updateTempPageEntry(), and Database::writeHeader().

00448     {
00449         updatePage();
00450         return *reinterpret_cast<Node *>(getPage().getWritableData());
00451     }

template<class Node>
PageId SegNodeLock< Node >::allocatePage ( PageOwnerId  ownerId = ANON_PAGE_OWNER_ID  )  [inline]

Reimplemented from SegPageLock.

Definition at line 453 of file SegPageLock.h.

References SegPageLock::allocatePage(), and SegNodeLock< Node >::setMagicNumber().

Referenced by LcsClusterNodeWriter::allocArrays(), LcsClusterNodeWriter::allocateClusterPage(), Database::allocateHeader(), BTreeBuildLevel::allocatePage(), BTreePrefetchSearchExecStream::allocateScratchPages(), BTreeWriter::compactNode(), BTreeBuilder::createEmptyRoot(), BackupRestoreTest::createSnapshotData(), SegOutputStream::flushBuffer(), BTreeWriter::grow(), LbmGeneratorExecStream::initBitmapTable(), LcsClusterAppendExecStream::initLoad(), and BTreeWriter::splitCurrentNode().

00454     {
00455         PageId pageId = SegPageLock::allocatePage(ownerId);
00456         setMagicNumber();
00457         return pageId;
00458     }

template<class Node>
PageId SegNodeLock< Node >::tryAllocatePage ( PageOwnerId  ownerId = ANON_PAGE_OWNER_ID  )  [inline]

Reimplemented from SegPageLock.

Definition at line 460 of file SegPageLock.h.

References NULL_PAGE_ID, SegNodeLock< Node >::setMagicNumber(), and SegPageLock::tryAllocatePage().

00461     {
00462         PageId pageId = SegPageLock::tryAllocatePage(ownerId);
00463         if (pageId != NULL_PAGE_ID) {
00464             setMagicNumber();
00465         }
00466         return pageId;
00467     }

template<class Node>
void SegNodeLock< Node >::setMagicNumber (  )  [inline]

Definition at line 469 of file SegPageLock.h.

References SegNodeLock< Node >::getNodeForWrite().

Referenced by VersionedRandomAllocationSegment::allocateAllocNodes(), SegNodeLock< Node >::allocatePage(), RandomAllocationSegmentBase::allocatePageIdFromSegment(), RandomAllocationSegmentBase::format(), and SegNodeLock< Node >::tryAllocatePage().

00470     {
00471         getNodeForWrite().magicNumber = Node::MAGIC_NUMBER;
00472     }

template<class Node>
bool SegNodeLock< Node >::isMagicNumberValid (  )  [inline]

Definition at line 474 of file SegPageLock.h.

References SegPageLock::getPage(), and CachePage::getReadableData().

Referenced by CrcSegInputStream::lockBufferParanoid().

00475     {
00476         Node const &node =
00477             *reinterpret_cast<Node const *>(getPage().getReadableData());
00478         return node.magicNumber == Node::MAGIC_NUMBER;
00479     }

void SegPageLock::accessSegment ( SegmentAccessor const &  segmentAccessorInit  )  [inline, inherited]

Definition at line 119 of file SegPageLock.h.

References SegmentAccessor::pCacheAccessor, and SegmentAccessor::pSegment.

Referenced by BTreeBuildLevel::allocateAndLinkNewNode(), BTreeBuildLevel::BTreeBuildLevel(), BTreeReader::BTreeReader(), BTreeWriter::BTreeWriter(), BTreeBuilder::createEmptyRoot(), ExternalSortRunLoader::ExternalSortRunLoader(), SegPageBackupRestoreDevice::init(), LhxHashTable::init(), LcsClusterAccessBase::LcsClusterAccessBase(), LcsClusterNodeWriter::LcsClusterNodeWriter(), LcsClusterAppendExecStream::prepare(), LbmUnionExecStream::prepare(), LbmGeneratorExecStream::prepare(), LbmChopperExecStream::prepare(), BTreePrefetchSearchExecStream::prepare(), FlatFileExecStreamImpl::prepare(), ScratchBufferExecStream::prepare(), MockResourceExecStream::prepare(), DoubleBufferExecStream::prepare(), SpillOutputStream::SpillOutputStream(), LbmEntryTest::testldb35(), LbmEntryTest::testler5920(), LbmEntryTest::testMergeEntry(), LbmEntryTest::testZeroBytes(), BTreeBuilder::truncate(), BTreeBuilder::truncateChildren(), BTreeBuilder::truncateExternal(), and BTreeVerifier::verifyNode().

00121     {
00122         assert(!pPage);
00123         assert(segmentAccessorInit.pSegment);
00124         assert(segmentAccessorInit.pCacheAccessor);
00125         segmentAccessor = segmentAccessorInit;
00126         isWriteVersioned = segmentAccessor.pSegment->isWriteVersioned();
00127     }

bool SegPageLock::isLocked (  )  const [inline, inherited]

Definition at line 129 of file SegPageLock.h.

Referenced by LcsClusterNodeWriter::allocateClusterPage(), LcsClusterNodeWriter::close(), SpillOutputStream::closeImpl(), BTreeWriter::compactNode(), BTreeWriter::deleteCurrent(), SpillOutputStream::flushBuffer(), SegOutputStream::flushBuffer(), SpillOutputStream::getInputStream(), BTreeReader::isPositioned(), BTreeNonLeafReader::isPositionedOnInfinityKey(), SegmentTestBase::lockPage(), ScratchBufferExecStream::open(), DoubleBufferExecStream::open(), SegInputStream::readNextBuffer(), BTreeReader::searchNext(), BTreeNonLeafReader::searchNext(), BTreeLeafReader::searchNext(), SegPageLock::swapBuffers(), BTreeWriter::updateCurrent(), and SegOutputStream::updatePage().

00130     {
00131         return pPage ? true : false;
00132     }

CachePage& SegPageLock::getPage (  )  const [inline, inherited]

Definition at line 134 of file SegPageLock.h.

Referenced by LcsClusterNodeWriter::allocArrays(), BTreeBuildLevel::allocateAndLinkNewNode(), LbmEntryTest::allocateBuf(), ExternalSortRunLoader::allocateBuffer(), BTreePrefetchSearchExecStream::allocateScratchPages(), LhxHashTable::allocBlock(), VersionedRandomAllocationSegment::backupAllocationNodes(), SegNodeLock< Node >::checkMagicNumber(), DoubleBufferExecStream::execute(), SegOutputStream::flushBuffer(), SpillOutputStream::getInputStream(), SegNodeLock< Node >::getNodeForRead(), SegNodeLock< Node >::getNodeForWrite(), LbmGeneratorExecStream::initBitmapTable(), LcsClusterAppendExecStream::initLoad(), SegPageBackupRestoreDevice::initScratchPages(), SegNodeLock< Node >::isMagicNumberValid(), VersionedRandomAllocationSegment::locateDataPages(), CrcSegInputStream::lockBufferParanoid(), SegmentTestBase::lockPage(), VersionedSegment::notifyPageDirty(), LbmUnionExecStream::open(), LbmChopperExecStream::open(), FlatFileExecStreamImpl::open(), ScratchBufferExecStream::open(), DoubleBufferExecStream::open(), VersionedSegment::recover(), SpillOutputStream::spill(), SpillOutputStream::SpillOutputStream(), RandomAllocationSegmentTest::testAllocateAndDeallocate(), and Database::writeHeader().

00135     {
00136         assert(isLocked());
00137         return *pPage;
00138     }

void SegPageLock::deallocateLockedPage (  )  [inline, inherited]

Definition at line 159 of file SegPageLock.h.

Referenced by SegInputStream::readNextBuffer(), BTreeBuilder::swapRoot(), SegmentTestBase::testDeallocate(), and BTreeBuilder::truncate().

00160     {
00161         assert(isLocked());
00162         BlockId blockId = pPage->getBlockId();
00163         unlock();
00164         PageId pageId = segmentAccessor.pSegment->translateBlockId(blockId);
00165         // we rely on the segment to decide whether to discard the block
00166         // from cache
00167         segmentAccessor.pSegment->deallocatePageRange(pageId,pageId);
00168     }

void SegPageLock::deallocateUnlockedPage ( PageId  pageId  )  [inline, inherited]

Definition at line 170 of file SegPageLock.h.

References NULL_PAGE_ID.

Referenced by SegInputStream::closeImpl(), BTreeBuilder::truncateChildren(), and BTreeBuilder::truncateExternal().

00171     {
00172         assert(pageId != NULL_PAGE_ID);
00173         BlockId blockId = segmentAccessor.pSegment->translatePageId(pageId);
00174         // we rely on the segment to decide whether to discard the block
00175         // from cache
00176         segmentAccessor.pSegment->deallocatePageRange(pageId,pageId);
00177     }

void SegPageLock::unlock (  )  [inline, inherited]

Definition at line 179 of file SegPageLock.h.

Referenced by BTreeReader::adjustRootLockMode(), LcsClusterNodeWriter::allocArrays(), LbmEntryTest::allocateBuf(), ExternalSortRunLoader::allocateBuffer(), Database::allocateHeader(), RandomAllocationSegmentBase::allocatePageIdFromSegment(), LhxHashTable::allocBlock(), LcsClusterNodeWriter::close(), SpillOutputStream::closeImpl(), SegStream::closeImpl(), SegInputStream::closeImpl(), ScratchBufferExecStream::closeImpl(), DoubleBufferExecStream::closeImpl(), BackupRestoreTest::createSnapshotData(), BTreeReader::endSearch(), BackupRestoreTest::executeSnapshotTxn(), SegOutputStream::flushBuffer(), BTreeWriter::grow(), LcsClusterAppendExecStream::initLoad(), BTreeNonLeafReader::isRootOnly(), VersionedRandomAllocationSegment::locateDataPages(), CrcSegInputStream::lockBuffer(), BTreeWriter::lockParentPage(), LbmUnionExecStream::open(), SegInputStream::readNextBuffer(), BTreeWriter::releaseScratchBuffers(), BTreeReader::searchForKeyTemplate(), SpillOutputStream::spill(), BTreeWriter::splitCurrentNode(), SegmentTestBase::testAllocate(), RandomAllocationSegmentTest::testAllocateAndDeallocate(), SegPageIterTest::testIter(), SegPageEntryIterTest::testIter(), BTreeBuilder::truncateChildren(), and LcsClusterAccessBase::unlockClusterPage().

00180     {
00181         if (pPage) {
00182             segmentAccessor.pCacheAccessor->unlockPage(
00183                 *pPage,
00184                 lockMode);
00185             resetPage();
00186         }
00187     }

void SegPageLock::dontUnlock (  )  [inline, inherited]

Definition at line 189 of file SegPageLock.h.

Referenced by SegmentTestBase::lockPage().

00190     {
00191         resetPage();
00192     }

void SegPageLock::lockPage ( PageId  pageId,
LockMode  lockModeInit,
bool  readIfUnmapped = true 
) [inline, inherited]

Definition at line 194 of file SegPageLock.h.

Referenced by BTreeNonLeafReader::isRootOnly(), SegmentTestBase::lockPage(), BTreeLeafReader::searchExtreme(), BTreeReader::searchExtremeInternal(), BTreeReader::searchForKeyTemplate(), and BTreeReader::searchNextInternal().

00197     {
00198         // if the page we want to lock is already locked in the desired
00199         // mode, nothing needs to be done
00200         if (isLocked() && pageId == lockedPageId && lockMode == lockModeInit) {
00201             return;
00202         }
00203         unlock();
00204         lockMode = getLockMode(lockModeInit);
00205         BlockId blockId = segmentAccessor.pSegment->translatePageId(pageId);
00206         pPage = segmentAccessor.pCacheAccessor->lockPage(
00207             blockId,
00208             lockMode,
00209             readIfUnmapped,
00210             segmentAccessor.pSegment->getMappedPageListener(blockId));
00211         lockedPageId = pageId;
00212     }

void SegPageLock::lockPageWithCoupling ( PageId  pageId,
LockMode  lockModeInit 
) [inline, inherited]

Definition at line 214 of file SegPageLock.h.

References LOCKMODE_S_NOWAIT.

Referenced by BTreeWriter::lockParentPage(), and BTreeReader::searchForKeyTemplate().

00216     {
00217         assert(lockModeInit < LOCKMODE_S_NOWAIT);
00218         BlockId blockId = segmentAccessor.pSegment->translatePageId(pageId);
00219         LockMode newLockMode = getLockMode(lockModeInit);
00220         CachePage *pNewPage = segmentAccessor.pCacheAccessor->lockPage(
00221             blockId,
00222             newLockMode,
00223             true,
00224             segmentAccessor.pSegment->getMappedPageListener(blockId));
00225         assert(pNewPage);
00226         unlock();
00227         lockMode = newLockMode;
00228         pPage = pNewPage;
00229         lockedPageId = pageId;
00230     }

void SegPageLock::lockShared ( PageId  pageId  )  [inline, inherited]

Definition at line 232 of file SegPageLock.h.

References LOCKMODE_S.

Referenced by VersionedRandomAllocationSegment::backupAllocationNodes(), VersionedRandomAllocationSegment::copyPageEntryToTemp(), BTreeAccessBase::getFirstChild(), VersionedRandomAllocationSegment::getOldestTxnId(), VersionedRandomAllocationSegment::getOldPageIds(), Database::loadHeader(), VersionedRandomAllocationSegment::locateDataPages(), SegInputStream::lockBuffer(), CrcSegInputStream::lockBufferParanoid(), LcsClusterReader::moveToBlock(), LcsClusterReader::moveToBlockWithRid(), LcsClusterReader::readClusterPage(), VersionedRandomAllocationSegment::restoreFromBackup(), SegmentTestBase::testDeallocate(), SegPageIterTest::testIter(), SegPageEntryIterTest::testIter(), VersionedRandomAllocationSegment::uncommittedDeallocation(), VersionedRandomAllocationSegment::validateFreePageCount(), BTreeVerifier::verifyNode(), and BackupRestoreTest::verifySnapshotData().

00233     {
00234         lockPage(pageId,LOCKMODE_S);
00235     }

void SegPageLock::lockExclusive ( PageId  pageId  )  [inline, inherited]

Definition at line 237 of file SegPageLock.h.

References LOCKMODE_X.

Referenced by VersionedRandomAllocationSegment::allocateAllocNodes(), BTreeBuildLevel::allocateAndLinkNewNode(), RandomAllocationSegmentBase::allocatePageIdFromSegment(), BTreeBuilder::buildBalanced(), VersionedRandomAllocationSegment::chainPageEntries(), VersionedRandomAllocationSegment::copyPageEntryFromTemp(), VersionedRandomAllocationSegment::copyPageEntryToTemp(), RandomAllocationSegmentBase::deallocatePageId(), VersionedRandomAllocationSegment::deallocateSinglePage(), VersionedRandomAllocationSegment::deferDeallocation(), BackupRestoreTest::executeSnapshotTxn(), RandomAllocationSegmentBase::format(), LcsClusterNodeWriter::getLastClusterPageForWrite(), VersionedRandomAllocationSegment::initPageEntry(), VersionedSegment::recover(), BTreeBuilder::swapRoot(), RandomAllocationSegmentBase::tallySegAllocNodePages(), BTreeBuilder::truncate(), BTreeBuilder::truncateChildren(), VersionedRandomAllocationSegment::updateExtentEntry(), VersionedRandomAllocationSegment::updateTempPageEntry(), VersionedRandomAllocationSegment::validateFreePageCount(), and Database::writeHeader().

00238     {
00239         lockPage(pageId,LOCKMODE_X);
00240     }

void SegPageLock::lockSharedNoWait ( PageId  pageId  )  [inline, inherited]

Definition at line 242 of file SegPageLock.h.

References LOCKMODE_S, and LOCKMODE_S_NOWAIT.

00243     {
00244         lockPage(pageId,LOCKMODE_S_NOWAIT);
00245         lockMode = LOCKMODE_S;
00246     }

void SegPageLock::lockExclusiveNoWait ( PageId  pageId  )  [inline, inherited]

Definition at line 248 of file SegPageLock.h.

References LOCKMODE_X, and LOCKMODE_X_NOWAIT.

00249     {
00250         lockPage(pageId,LOCKMODE_X_NOWAIT);
00251         lockMode = LOCKMODE_X;
00252     }

void SegPageLock::updatePage (  )  [inline, inherited]

Definition at line 254 of file SegPageLock.h.

References LOCKMODE_S, LOCKMODE_X, and NULL_PAGE_ID.

Referenced by SegNodeLock< Node >::getNodeForWrite(), and SegPageLock::swapBuffers().

00255     {
00256         assert(isLocked());
00257 
00258         // If the page is not newly allocated and can't be updated in-place,
00259         // lock the page that will be updated
00260         if (!newPage) {
00261             PageId origPageId =
00262                 segmentAccessor.pSegment->translateBlockId(getPage().
00263                     getBlockId());
00264             PageId updatePageId =
00265                 segmentAccessor.pSegment->updatePage(origPageId);
00266             if (updatePageId != NULL_PAGE_ID) {
00267                 lockUpdatePage(updatePageId);
00268                 return;
00269             }
00270         }
00271 
00272         // Either the page is new or the page can be updated in-place.
00273         // If we haven't locked the page exclusively yet, upgrade the
00274         // shared lock, forcing the upgrade to wait for pending IOs.
00275         if (lockMode == LOCKMODE_S) {
00276             assert(isWriteVersioned);
00277             TxnId txnId = segmentAccessor.pCacheAccessor->getTxnId();
00278             pPage->upgrade(txnId);
00279             lockMode = LOCKMODE_X;
00280         }
00281     }

void SegPageLock::lockUpdatePage ( PageId  updatePageId  )  [inline, inherited]

Definition at line 283 of file SegPageLock.h.

References LOCKMODE_S, and LOCKMODE_X.

00284     {
00285         assert(isWriteVersioned);
00286         BlockId blockId =
00287             segmentAccessor.pSegment->translatePageId(updatePageId);
00288         assert(lockMode == LOCKMODE_S);
00289         CachePage *pNewPage = segmentAccessor.pCacheAccessor->lockPage(
00290             blockId,
00291             LOCKMODE_X,
00292             true,
00293             segmentAccessor.pSegment->getMappedPageListener(blockId));
00294         assert(pNewPage);
00295         // copy the original page while we have both the original and new
00296         // pages locked
00297         memcpy(
00298             pNewPage->getWritableData(),
00299             pPage->getReadableData(),
00300             segmentAccessor.pSegment->getUsablePageSize());
00301         PageId origPageId = lockedPageId;
00302         unlock();
00303         lockMode = LOCKMODE_X;
00304         pPage = pNewPage;
00305         newPage = true;
00306         // keep track of the locked page based on the original pageId
00307         // requested
00308         lockedPageId = origPageId;
00309     }

PageId SegPageLock::getPageId (  )  [inline, inherited]

Definition at line 311 of file SegPageLock.h.

Referenced by LcsClusterNodeWriter::allocateClusterPage().

00312     {
00313         // note that lockedPageId may not be the same as
00314         // segmentAccessor.pSegment->translateBlockId(getPage().getBlockId())
00315         // if the page is versioned
00316         return lockedPageId;
00317     }

void SegPageLock::flushPage ( bool  async  )  [inline, inherited]

Definition at line 319 of file SegPageLock.h.

Referenced by LcsClusterNodeWriter::allocateClusterPage(), LcsClusterNodeWriter::close(), BTreeWriter::grow(), and BTreeWriter::splitCurrentNode().

00320     {
00321         assert(isLocked());
00322         segmentAccessor.pCacheAccessor->flushPage(getPage(), true);
00323     }

void SegPageLock::swapBuffers ( SegPageLock other  )  [inline, inherited]

Definition at line 326 of file SegPageLock.h.

References Segment::getFullPageSize(), Segment::getUsablePageSize(), CachePage::getWritableData(), SegPageLock::isLocked(), SegPageLock::lockMode, LOCKMODE_X, SegPageLock::pPage, and SegPageLock::updatePage().

Referenced by BTreeWriter::compactNode(), and BTreeBuilder::swapRoot().

00327     {
00328         // TODO:  assert magic numbers the same?
00329         assert(isLocked());
00330         assert(other.isLocked());
00331         assert(lockMode == LOCKMODE_X);
00332         assert(other.lockMode == LOCKMODE_X);
00333         assert(pPage != other.pPage);
00334 
00335         // since we're copying new data into other, treat it as an update
00336         other.updatePage();
00337 
00338         // both pages will end up with this page's footer, on the assumption
00339         // that other was a scratch page
00340         // TODO:  correctly swap footers as well?
00341         Segment &segment = *(segmentAccessor.pSegment);
00342         memcpy(
00343             other.pPage->getWritableData() + segment.getUsablePageSize(),
00344             pPage->getReadableData() +  segment.getUsablePageSize(),
00345             segment.getFullPageSize() - segment.getUsablePageSize());
00346         pPage->swapBuffers(*other.pPage);
00347     }

bool SegPageLock::tryUpgrade (  )  [inline, inherited]

Definition at line 349 of file SegPageLock.h.

References LOCKMODE_S, and LOCKMODE_X.

Referenced by BTreeReader::adjustRootLockMode().

00350     {
00351         assert(isLocked());
00352         assert(lockMode == LOCKMODE_S);
00353         // REVIEW jvs 31-Dec-2005:  This should really go through
00354         // the CacheAccessor interface.
00355         TxnId txnId = segmentAccessor.pCacheAccessor->getTxnId();
00356 
00357         // If we're versioning, defer upgrading the lock until
00358         // we're actually going to be update the page.
00359         if (isWriteVersioned) {
00360             return true;
00361         } else {
00362             if (pPage->tryUpgrade(txnId)) {
00363                 lockMode = LOCKMODE_X;
00364                 return true;
00365             }
00366             return false;
00367         }
00368     }

SharedCacheAccessor SegPageLock::getCacheAccessor (  )  const [inline, inherited]

Definition at line 370 of file SegPageLock.h.

Referenced by SegOutputStream::flushBuffer(), and SpillOutputStream::spill().

00371     {
00372         return segmentAccessor.pCacheAccessor;
00373     }


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