#include <RandomAllocationSegmentBase.h>
Inheritance diagram for RandomAllocationSegmentBase:
Public Types | |
enum | AllocationOrder { RANDOM_ALLOCATION, ASCENDING_ALLOCATION, CONSECUTIVE_ALLOCATION, LINEAR_ALLOCATION } |
Enumeration of the possible orderings of PageIds returned from allocatePageId. More... | |
Public Member Functions | |
virtual | ~RandomAllocationSegmentBase () |
virtual BlockId | translatePageId (PageId) |
Maps from a PageId in this segment to a BlockId. | |
virtual bool | isPageIdAllocated (PageId pageId) |
Tests whether a PageId is allocated. | |
virtual AllocationOrder | getAllocationOrder () const |
| |
virtual BlockNum | getAllocatedSizeInPages () |
| |
virtual BlockNum | getNumPagesOccupiedHighWater () |
Returns the max number of pages occupied by this segment instance. | |
virtual void | deallocatePageRange (PageId startPageId, PageId endPageId) |
Deallocates a range of pages allocated from this segment. | |
virtual void | initForUse () |
Performs additional initialization required on the segment after it has been properly formatted. | |
SharedSegment const & | getDelegateSegment () const |
virtual BlockNum | getNumPagesExtended () |
| |
virtual PageId | getPageSuccessor (PageId pageId) |
Determines the successor of a given PageId. | |
virtual void | setPageSuccessor (PageId pageId, PageId successorId) |
Sets the successor of a given PageId. | |
virtual PageId | translateBlockId (BlockId) |
Maps from a BlockId to a PageId in this segment. | |
virtual PageId | allocatePageId (PageOwnerId ownerId=ANON_PAGE_OWNER_ID) |
Allocates a page without locking it into memory. | |
virtual bool | ensureAllocatedSize (BlockNum nPages) |
Allocates pages as needed to make getAllocatedSizeInPages() meet a lower bound. | |
virtual void | delegatedCheckpoint (Segment &delegatingSegment, CheckpointType checkpointType) |
Helper for DelegatingSegment. | |
virtual PageId | updatePage (PageId pageId, bool needsTranslation=false) |
Determines whether a page can be updated in-place, and if so, prepares the page for update. | |
virtual void | notifyPageMap (CachePage &page) |
Receives notification from CacheImpl as soon as a page is mapped, before any I/O is initiated to retrieve the page contents. | |
virtual void | notifyPageUnmap (CachePage &page) |
Receives notification from CacheImpl just before a page is unmapped. | |
virtual void | notifyAfterPageRead (CachePage &page) |
Receives notification from CacheImpl after a page read completes. | |
virtual void | notifyPageDirty (CachePage &page, bool bDataValid) |
Receives notification from CacheImpl the first time a page becomes dirty after it has been mapped (but before the contents have changed). | |
virtual void | notifyBeforePageFlush (CachePage &page) |
Receives notification from CacheImpl just before a dirty page is flushed to disk. | |
virtual void | notifyAfterPageFlush (CachePage &page) |
Receives notification from CacheImpl when a page flush completes successfully. | |
virtual bool | canFlushPage (CachePage &page) |
Informs CacheImpl whether a dirty page can safely be flushed to disk. | |
SharedCache | getCache () const |
| |
uint | getFullPageSize () const |
| |
uint | getUsablePageSize () const |
| |
SharedSegment | getTracingSegment () |
| |
void | setTracingSegment (WeakSegment pTracingSegmentInit) |
Sets the tracing segment associated with this segment. | |
void | checkpoint (CheckpointType checkpointType=CHECKPOINT_FLUSH_ALL) |
Checkpoints this segment. | |
virtual MappedPageListener * | getMappedPageListener (BlockId blockId) |
Returns the mapped page listener corresponding to a page. | |
virtual bool | isWriteVersioned () |
| |
virtual MappedPageListener * | getTracingListener () |
Retrieves the tracing wrapper corresponding to this listener if tracing is turned on. | |
virtual MappedPageListener * | notifyAfterPageCheckpointFlush (CachePage &page) |
Receives notification that a page has been flushed during a checkpoint. | |
bool | isClosed () const |
| |
void | close () |
Closes this object, releasing any unallocated resources. | |
Static Public Member Functions | |
static PageId | getLinearPageId (BlockNum iPage) |
Constructs a linear PageId based on a linear page number. | |
static BlockNum | getLinearBlockNum (PageId pageId) |
Obtains the linear page number from a linear PageId. | |
Protected Types | |
typedef std::hash_map< PageId, PageId > | PageMap |
typedef PageMap::const_iterator | PageMapConstIter |
Protected Member Functions | |
RandomAllocationSegmentBase (SharedSegment delegateSegment) | |
PageId | getSegAllocPageId (uint iSegPage) const |
Calculates the PageId of a particular SegmentAllocationNode. | |
virtual PageId | getSegAllocPageIdForWrite (PageId origSegAllocPageId)=0 |
Retrieves the pageId of the SegmentAllocationNode that should be updated when updates are made to that node. | |
virtual void | undoSegAllocPageWrite (PageId segAllocPageId)=0 |
Indicates that no new pages were allocated from extents within a SegmentAllocationNode. | |
PageId | getExtentAllocPageId (ExtentNum extentNum) const |
Calculates the PageId of a particular extent allocation node. | |
virtual PageId | getExtAllocPageIdForWrite (ExtentNum extentNum)=0 |
Retrieves the pageId of the extent allocation node that should be updated when updates are made to that node. | |
BlockNum | makePageNum (ExtentNum extentNum, BlockNum iPageInExtent) const |
Calculates a linear page number. | |
void | splitPageId (PageId pageId, uint &iSegAlloc, ExtentNum &extentNum, BlockNum &iPageInExtent) const |
Maps a linear PageId from this segment into the corresponding SegmentAllocationNode, extent allocation node, and extent-relative page index. | |
virtual bool | isPageIdValid (PageId pageId) |
Tests whether the given PageId has valid contents (either an allocated data page or an allocation map page). | |
bool | testPageId (PageId pageId, bool testAllocation, bool thisSegment) |
Common implementation for isPageIdValid and isPageIdAllocated. | |
virtual PageOwnerId | getPageOwnerId (PageId pageId, bool thisSegment)=0 |
Retrieves the ownerId corresponding to a page entry. | |
template<class PageEntryT> | |
PageOwnerId | getPageOwnerIdTemplate (PageId pageId, bool thisSegment) |
Retrieves the ownerId corresponding to a page entry. | |
virtual void | freePageEntry (ExtentNum extentNum, BlockNum iPageInExtent)=0 |
Marks the page entry corresponding to a deallocated page as unallocated. | |
template<class ExtentAllocationNodeT, class ExtentAllocLockT, class PageEntryT> | |
void | freePageEntryTemplate (ExtentNum extentNum, BlockNum iPageInExtent) |
Marks the page entry corresponding to a deallocated page as unallocated. | |
virtual void | markPageEntryUnused (PageEntry &pageEntry) |
Marks a page entry as unused. | |
PageId | getFirstSegAllocPageId () const |
| |
uint | inferSegAllocCount () |
Infers the number of SegmentAllocationNodes from the size of the underlying segment. | |
void | format () |
Formats allocation pages based on current size of underlying segment, marking all pages as deallocated. | |
virtual void | formatPageExtents (SegmentAllocationNode &segAllocNode, ExtentNum &extentNum)=0 |
Formats each of the extents within a segment allocation node. | |
template<class ExtentAllocationNodeT, class ExtentAllocLockT, class PageEntryT> | |
void | formatPageExtentsTemplate (SegmentAllocationNode &segAllocNode, ExtentNum &extentNum) |
Formats each of the extents within a segment allocation node. | |
template<class ExtentAllocationNodeT, class ExtentAllocLockT, class PageEntryT> | |
void | formatExtentTemplate (ExtentAllocationNodeT &extentNode) |
Formats one extent allocation. | |
PageId | allocatePageIdFromSegment (PageOwnerId ownerId, SharedSegment allocNodeSegment) |
Allocates a page without locking it into memory. | |
virtual PageId | allocateFromExtent (ExtentNum extentNum, PageOwnerId ownerId)=0 |
Allocates a new page from an extent known to have space. | |
template<class ExtentAllocationNodeT, class ExtentAllocLockT, class PageEntryT> | |
PageId | allocateFromExtentTemplate (ExtentNum extentNum, PageOwnerId ownerId, SharedSegment allocNodeSegment) |
Allocates a new page from an extent known to have space. | |
virtual PageId | allocateFromNewExtent (ExtentNum extentNum, PageOwnerId ownerId)=0 |
Allocates a page from a new extent allocation node. | |
template<class ExtentAllocationNodeT, class ExtentAllocLockT, class PageEntryT> | |
PageId | allocateFromNewExtentTemplate (ExtentNum extentNum, PageOwnerId ownerId, SharedSegment allocNodeSegment) |
Allocates a page from a new extent allocation node. | |
template<class ExtentAllocationNodeT, class PageEntryT> | |
PageId | allocateFromLockedExtentTemplate (ExtentAllocationNodeT &extentNode, ExtentNum extentNum, PageOwnerId ownerId) |
Allocates a new page from an extent known to have space, with the extent allocation node already locked. | |
template<class ExtentAllocationNodeT, class ExtentAllocLockT> | |
void | setPageSuccessorTemplate (PageId pageId, PageId successorId, SharedSegment allocNodeSegment) |
Sets the successor pageId for a page. | |
virtual PageId | getSegAllocPageIdForRead (PageId origSegAllocPageId, SharedSegment &allocNodeSegment)=0 |
Retrieves the actual pageId corresponding to the SegmentAllocationNode that should be accessed when reading from the node. | |
virtual PageId | getExtAllocPageIdForRead (ExtentNum extentNum, SharedSegment &allocNodeSegment)=0 |
Retrieves the actual pageId corresponding to the extent allocation node that should be accessed when reading from the node. | |
virtual void | getPageEntryCopy (PageId pageId, PageEntry &pageEntryCopy, bool isAllocated, bool thisSegment)=0 |
Retrieves a copy of the page entry for a specified page. | |
template<class ExtentAllocationNodeT, class ExtentAllocLockT, class PageEntryT> | |
void | getPageEntryCopyTemplate (PageId pageId, PageEntryT &pageEntryCopy, bool isAllocated, bool thisSegment) |
Retrieves a copy of the page entry for a specified page. | |
void | setUsablePageSize (uint) |
PConstBuffer | getReadableFooter (CachePage &page) |
PBuffer | getWritableFooter (CachePage &page) |
PageId | getLinearPageSuccessor (PageId pageId) |
An implementation of getPageSuccessor suitable for LINEAR_ALLOCATION. | |
void | setLinearPageSuccessor (PageId pageId, PageId successorId) |
An implementation of setPageSuccessor suitable for LINEAR_ALLOCATION. | |
bool | isLinearPageIdAllocated (PageId pageId) |
An implementation of isPageIdAllocated suitable for LINEAR_ALLOCATION when deallocation holes are disallowed. | |
Protected Attributes | |
BlockNum | nPagesPerExtent |
Number of pages in one extent, including the extent allocation node itself (so actual data capacity per extent is one less). | |
BlockNum | nPagesPerSegAlloc |
Number of pages mapped by one SegmentAllocationNode, including the SegmentAllocationNode itself. | |
ExtentNum | nExtentsPerSegAlloc |
Number of extents mapped by a full SegmentAllocationNode. | |
SharedCache | pCache |
Cache managing pages of this segment. | |
WeakSegment | pTracingSegment |
The tracing segment associated with this segment, if tracing is turned on. | |
bool | needsClose |
Private Member Functions | |
void | incrementPageCounters () |
Increments the page counters for this segment instance, corresponding to some page allocation. | |
void | incrementPagesOccupiedCounter () |
Increments the pages occupied counter. | |
void | decrementPageCounters () |
Decrements the page counters for this segment instance, corresponding to some page deallocation. | |
void | countAllocatedPages () |
Counts the total number of allocated data pages as well as the total number of allocated pages, which includes used allocation node pages. | |
void | tallySegAllocNodePages (PageId segAllocPageId, SharedSegment allocNodeSegment, PageId &nextSegAllocPageId) |
Counts the number of allocated pages recorded in a SegmentAllocationNode. | |
void | deallocatePageId (PageId pageId) |
Deallocates a single page. | |
Private Attributes | |
BlockNum | nPagesOccupiedHighWater |
The maximum number of pages occupied by this segment instance. | |
BlockNum | nPagesAllocated |
The number of data pages allocated for this segment. | |
BlockNum | netDeallocations |
The net number of deallocations on this segment. | |
StrictMutex | pageCounterMutex |
Mutex used to ensure that only one thread is incrementing the page counters. | |
Friends | |
class | SegmentFactory |
See the design docs for more detail.
The segment tracks space allocation using segment allocation nodes and extent allocation nodes. This base class defines the structure of the segment allocation node and a base page entry. It is left to each deriving class to define its own extent allocation node, and further refine the page entry, if necessary.
The allocation nodes may be stored in a separate segment.
Definition at line 68 of file RandomAllocationSegmentBase.h.
typedef std::hash_map<PageId,PageId> Segment::PageMap [protected, inherited] |
typedef PageMap::const_iterator Segment::PageMapConstIter [protected, inherited] |
enum Segment::AllocationOrder [inherited] |
Enumeration of the possible orderings of PageIds returned from allocatePageId.
The enumeration is from weakest to strongest ordering, and should not be changed.
Definition at line 105 of file Segment.h.
00105 { 00109 RANDOM_ALLOCATION, 00110 00115 ASCENDING_ALLOCATION, 00116 00121 CONSECUTIVE_ALLOCATION, 00122 00128 LINEAR_ALLOCATION 00129 };
RandomAllocationSegmentBase::RandomAllocationSegmentBase | ( | SharedSegment | delegateSegment | ) | [explicit, protected] |
Definition at line 41 of file RandomAllocationSegmentBase.cpp.
References DelegatingSegment::getAllocationOrder(), Segment::getUsablePageSize(), Segment::LINEAR_ALLOCATION, netDeallocations, nExtentsPerSegAlloc, nPagesAllocated, and nPagesOccupiedHighWater.
00043 : DelegatingSegment(delegateSegment) 00044 { 00045 permAssert(DelegatingSegment::getAllocationOrder() == LINEAR_ALLOCATION); 00046 00047 // calculate immutable segment parameters based on page size 00048 00049 nExtentsPerSegAlloc = 00050 (getUsablePageSize() - sizeof(SegmentAllocationNode)) 00051 / sizeof(SegmentAllocationNode::ExtentEntry); 00052 00053 nPagesOccupiedHighWater = 0; 00054 nPagesAllocated = 0; 00055 netDeallocations = 0; 00056 }
RandomAllocationSegmentBase::~RandomAllocationSegmentBase | ( | ) | [virtual] |
void RandomAllocationSegmentBase::incrementPageCounters | ( | ) | [private] |
Increments the page counters for this segment instance, corresponding to some page allocation.
The pages occupied counter takes into account deallocated pages.
Definition at line 299 of file RandomAllocationSegmentBase.cpp.
References netDeallocations, nPagesAllocated, nPagesOccupiedHighWater, and pageCounterMutex.
Referenced by allocatePageIdFromSegment().
00300 { 00301 StrictMutexGuard mutexGuard(pageCounterMutex); 00302 00303 // If there are excess deallocations, don't increment the pages occupied 00304 // counter 00305 if (netDeallocations > 0) { 00306 --netDeallocations; 00307 } else { 00308 ++nPagesOccupiedHighWater; 00309 } 00310 ++nPagesAllocated; 00311 }
void RandomAllocationSegmentBase::incrementPagesOccupiedCounter | ( | ) | [private] |
Increments the pages occupied counter.
Definition at line 313 of file RandomAllocationSegmentBase.cpp.
References nPagesOccupiedHighWater, and pageCounterMutex.
Referenced by allocatePageIdFromSegment().
00314 { 00315 StrictMutexGuard mutexGuard(pageCounterMutex); 00316 ++nPagesOccupiedHighWater; 00317 }
void RandomAllocationSegmentBase::decrementPageCounters | ( | ) | [private] |
Decrements the page counters for this segment instance, corresponding to some page deallocation.
Definition at line 319 of file RandomAllocationSegmentBase.cpp.
References netDeallocations, nPagesAllocated, and pageCounterMutex.
Referenced by deallocatePageId().
00320 { 00321 StrictMutexGuard mutexGuard(pageCounterMutex); 00322 ++netDeallocations; 00323 --nPagesAllocated; 00324 }
void RandomAllocationSegmentBase::countAllocatedPages | ( | ) | [private] |
Counts the total number of allocated data pages as well as the total number of allocated pages, which includes used allocation node pages.
Definition at line 427 of file RandomAllocationSegmentBase.cpp.
References getFirstSegAllocPageId(), getSegAllocPageIdForRead(), nPagesOccupiedHighWater, NULL_PAGE_ID, pageCounterMutex, and tallySegAllocNodePages().
Referenced by initForUse().
00428 { 00429 StrictMutexGuard mutexGuard(pageCounterMutex); 00430 PageId origSegAllocPageId = getFirstSegAllocPageId(); 00431 do { 00432 SharedSegment allocNodeSegment; 00433 PageId segAllocPageId = 00434 getSegAllocPageIdForRead(origSegAllocPageId, allocNodeSegment); 00435 00436 PageId nextSegAllocPageId; 00437 tallySegAllocNodePages( 00438 segAllocPageId, 00439 allocNodeSegment, 00440 nextSegAllocPageId); 00441 // count the segment allocation node page 00442 ++nPagesOccupiedHighWater; 00443 00444 origSegAllocPageId = nextSegAllocPageId; 00445 } while (origSegAllocPageId != NULL_PAGE_ID); 00446 }
void RandomAllocationSegmentBase::tallySegAllocNodePages | ( | PageId | segAllocPageId, | |
SharedSegment | allocNodeSegment, | |||
PageId & | nextSegAllocPageId | |||
) | [private] |
Counts the number of allocated pages recorded in a SegmentAllocationNode.
segAllocPageId | the pageId of the SegmentAllocationNode | |
allocNodeSegment | the segment corresponding to the node | |
[out] | nextSegAllocPageId | the pageId of the next SegmentAllocationNode following this one |
Definition at line 453 of file RandomAllocationSegmentBase.cpp.
References SegmentAllocationNode::getExtentEntry(), SegNodeLock< Node >::getNodeForRead(), SegPageLock::lockExclusive(), SegmentAllocationNode::nExtents, SegmentAllocationNode::nextSegAllocPageId, nPagesAllocated, nPagesOccupiedHighWater, nPagesPerExtent, and Segment::pCache.
Referenced by countAllocatedPages().
00457 { 00458 SegmentAccessor segAccessor(allocNodeSegment, pCache); 00459 SegAllocLock segAllocLock(segAccessor); 00460 00461 // REVIEW zfong 2/5/07 - Do we really need to exclusively lock this page? 00462 // Isn't a share lock sufficient? 00463 segAllocLock.lockExclusive(segAllocPageId); 00464 SegmentAllocationNode const &node = segAllocLock.getNodeForRead(); 00465 uint i; 00466 for (i = 0; i < node.nExtents; i++) { 00467 // assume no partial extents; the -1 is for the extent page 00468 BlockNum numPages = 00469 nPagesPerExtent 00470 - node.getExtentEntry(i).nUnallocatedPages; 00471 nPagesAllocated += (numPages - 1); 00472 nPagesOccupiedHighWater += numPages; 00473 } 00474 nextSegAllocPageId = node.nextSegAllocPageId; 00475 }
void RandomAllocationSegmentBase::deallocatePageId | ( | PageId | pageId | ) | [private] |
Deallocates a single page.
pageId | PageId of page to deallocate |
Definition at line 338 of file RandomAllocationSegmentBase.cpp.
References decrementPageCounters(), freePageEntry(), SegmentAllocationNode::getExtentEntry(), SegNodeLock< Node >::getNodeForWrite(), getSegAllocPageId(), Segment::getTracingSegment(), isPageIdAllocated(), SegPageLock::lockExclusive(), nExtentsPerSegAlloc, nPagesPerExtent, NULL_PAGE_ID, Segment::pCache, splitPageId(), and DelegatingSegment::translatePageId().
Referenced by deallocatePageRange().
00339 { 00340 permAssert(pageId != NULL_PAGE_ID); 00341 assert(isPageIdAllocated(pageId)); 00342 00343 // Discard the page from the cache 00344 BlockId blockId = DelegatingSegment::translatePageId(pageId); 00345 pCache->discardPage(blockId); 00346 00347 ExtentNum extentNum; 00348 BlockNum iPageInExtent; 00349 uint iSegAlloc; 00350 splitPageId(pageId,iSegAlloc,extentNum,iPageInExtent); 00351 permAssert(iPageInExtent); 00352 00353 // note that we mark the free PageId on the extent page BEFORE 00354 // increasing the corresponding free page count on the segment page; 00355 // otherwise someone calling allocatePageId at the same time could fail 00356 freePageEntry(extentNum, iPageInExtent); 00357 00358 SegmentAccessor selfAccessor(getTracingSegment(), pCache); 00359 SegAllocLock segAllocLock(selfAccessor); 00360 PageId segAllocPageId = getSegAllocPageId(iSegAlloc); 00361 segAllocLock.lockExclusive(segAllocPageId); 00362 SegmentAllocationNode &segAllocNode = segAllocLock.getNodeForWrite(); 00363 ExtentNum relativeExtentNum = extentNum % nExtentsPerSegAlloc; 00364 segAllocNode.getExtentEntry(relativeExtentNum).nUnallocatedPages++; 00365 permAssert( 00366 segAllocNode.getExtentEntry(relativeExtentNum).nUnallocatedPages 00367 <= nPagesPerExtent); 00368 00369 decrementPageCounters(); 00370 }
PageId RandomAllocationSegmentBase::getSegAllocPageId | ( | uint | iSegPage | ) | const [inline, protected] |
Calculates the PageId of a particular SegmentAllocationNode.
iSegPage | 0-based index of desired SegmentAllocationNode |
Definition at line 104 of file RandomAllocationSegmentBaseImpl.h.
References Segment::getLinearPageId(), and nPagesPerSegAlloc.
Referenced by VersionedRandomAllocationSegment::allocateAllocNodes(), allocatePageIdFromSegment(), VersionedRandomAllocationSegment::backupAllocationNodes(), deallocatePageId(), VersionedRandomAllocationSegment::deallocateSinglePage(), format(), VersionedRandomAllocationSegment::getOldPageIds(), VersionedRandomAllocationSegment::locateDataPages(), VersionedRandomAllocationSegment::restoreFromBackup(), VersionedRandomAllocationSegment::updateExtentEntry(), and VersionedRandomAllocationSegment::validateFreePageCount().
00106 { 00107 return getLinearPageId(nPagesPerSegAlloc*iSegPage); 00108 }
virtual PageId RandomAllocationSegmentBase::getSegAllocPageIdForWrite | ( | PageId | origSegAllocPageId | ) | [protected, pure virtual] |
Retrieves the pageId of the SegmentAllocationNode that should be updated when updates are made to that node.
origSegAllocPageId | original SegmentAllocationNode pageId |
Implemented in RandomAllocationSegment, and VersionedRandomAllocationSegment.
Referenced by allocatePageIdFromSegment().
virtual void RandomAllocationSegmentBase::undoSegAllocPageWrite | ( | PageId | segAllocPageId | ) | [protected, pure virtual] |
Indicates that no new pages were allocated from extents within a SegmentAllocationNode.
segAllocPageId | SegmentAllocationNode pageId |
Implemented in RandomAllocationSegment, and VersionedRandomAllocationSegment.
Referenced by allocatePageIdFromSegment().
PageId RandomAllocationSegmentBase::getExtentAllocPageId | ( | ExtentNum | extentNum | ) | const [inline, protected] |
Calculates the PageId of a particular extent allocation node.
extentNum | absolute 0-based extent number |
Definition at line 118 of file RandomAllocationSegmentBaseImpl.h.
References Segment::getLinearPageId(), and makePageNum().
Referenced by VersionedRandomAllocationSegment::backupAllocationNodes(), VersionedRandomAllocationSegment::chainPageEntries(), VersionedRandomAllocationSegment::deallocateSinglePage(), formatPageExtentsTemplate(), freePageEntryTemplate(), VersionedRandomAllocationSegment::getExtAllocPageIdForRead(), RandomAllocationSegment::getExtAllocPageIdForRead(), VersionedRandomAllocationSegment::getExtAllocPageIdForWrite(), RandomAllocationSegment::getExtAllocPageIdForWrite(), VersionedRandomAllocationSegment::getOldestTxnId(), VersionedRandomAllocationSegment::getOldPageIds(), getPageEntryCopyTemplate(), VersionedRandomAllocationSegment::locateDataPages(), VersionedRandomAllocationSegment::restoreFromBackup(), VersionedRandomAllocationSegment::uncommittedDeallocation(), VersionedRandomAllocationSegment::updatePageEntry(), VersionedRandomAllocationSegment::updateTempPageEntry(), and VersionedRandomAllocationSegment::validateFreePageCount().
00120 { 00121 return getLinearPageId(makePageNum(extentNum,0)); 00122 }
virtual PageId RandomAllocationSegmentBase::getExtAllocPageIdForWrite | ( | ExtentNum | extentNum | ) | [protected, pure virtual] |
Retrieves the pageId of the extent allocation node that should be updated when updates are made to that node.
extentNum | absolute 0-based extent number |
Implemented in RandomAllocationSegment, and VersionedRandomAllocationSegment.
Referenced by allocateFromExtentTemplate(), allocateFromNewExtentTemplate(), and setPageSuccessorTemplate().
BlockNum RandomAllocationSegmentBase::makePageNum | ( | ExtentNum | extentNum, | |
BlockNum | iPageInExtent | |||
) | const [inline, protected] |
Calculates a linear page number.
extentNum | absolute 0-based extent number of extent containing desired page | |
iPageInExtent | 0-based index of page in extent |
Definition at line 110 of file RandomAllocationSegmentBaseImpl.h.
References nExtentsPerSegAlloc, and nPagesPerExtent.
Referenced by allocateFromLockedExtentTemplate(), allocatePageIdFromSegment(), getExtentAllocPageId(), VersionedRandomAllocationSegment::getOldPageIds(), VersionedRandomAllocationSegment::locateDataPages(), and VersionedRandomAllocationSegment::restoreFromBackup().
00112 { 00113 // weird calculation to take into account interspersal of SegAllocNodes 00114 uint nSegPages = extentNum / nExtentsPerSegAlloc + 1; 00115 return iPageInExtent + extentNum*nPagesPerExtent + nSegPages; 00116 }
void RandomAllocationSegmentBase::splitPageId | ( | PageId | pageId, | |
uint & | iSegAlloc, | |||
ExtentNum & | extentNum, | |||
BlockNum & | iPageInExtent | |||
) | const [protected] |
Maps a linear PageId from this segment into the corresponding SegmentAllocationNode, extent allocation node, and extent-relative page index.
pageId | input PageId | |
[out] | iSegAlloc | 0-based index of containing SegmentAllocationNode |
[out] | extentNum | absolute 0-based extent number of containing extent allocation node |
[out] | iPageInExtent | 0-based index of page in extent |
Definition at line 279 of file RandomAllocationSegmentBase.cpp.
References Segment::getLinearBlockNum(), MAXU, nExtentsPerSegAlloc, nPagesPerExtent, and nPagesPerSegAlloc.
Referenced by VersionedRandomAllocationSegment::chainPageEntries(), deallocatePageId(), VersionedRandomAllocationSegment::deallocateSinglePage(), VersionedRandomAllocationSegment::deferDeallocation(), VersionedRandomAllocationSegment::getOldestTxnId(), getPageEntryCopyTemplate(), VersionedRandomAllocationSegment::initPageEntry(), setPageSuccessorTemplate(), testPageId(), VersionedRandomAllocationSegment::uncommittedDeallocation(), VersionedRandomAllocationSegment::updateAllocNodes(), VersionedRandomAllocationSegment::updateTempPageEntry(), and VersionedRandomAllocationSegment::validateFreePageCount().
00282 { 00283 // calculate block number relative to containing SegAllocNode 00284 BlockNum iPageInSegAlloc = getLinearBlockNum(pageId) % nPagesPerSegAlloc; 00285 iSegAlloc = getLinearBlockNum(pageId) / nPagesPerSegAlloc; 00286 if (!iPageInSegAlloc) { 00287 // this is the SegAllocNode itself! 00288 extentNum = MAXU; 00289 iPageInExtent = 0; 00290 } else { 00291 // account for the SegAllocNode 00292 --iPageInSegAlloc; 00293 extentNum = 00294 iPageInSegAlloc / nPagesPerExtent + nExtentsPerSegAlloc * iSegAlloc; 00295 iPageInExtent = iPageInSegAlloc % nPagesPerExtent; 00296 } 00297 }
bool RandomAllocationSegmentBase::isPageIdValid | ( | PageId | pageId | ) | [protected, virtual] |
Tests whether the given PageId has valid contents (either an allocated data page or an allocation map page).
pageId | the PageId to test |
Reimplemented in VersionedRandomAllocationSegment.
Definition at line 412 of file RandomAllocationSegmentBase.cpp.
References testPageId().
Referenced by translatePageId().
00413 { 00414 return testPageId(pageId,false,true); 00415 }
bool RandomAllocationSegmentBase::testPageId | ( | PageId | pageId, | |
bool | testAllocation, | |||
bool | thisSegment | |||
) | [protected] |
Common implementation for isPageIdValid and isPageIdAllocated.
Definition at line 385 of file RandomAllocationSegmentBase.cpp.
References getPageOwnerId(), DelegatingSegment::isPageIdAllocated(), splitPageId(), and UNALLOCATED_PAGE_OWNER_ID.
Referenced by getPageEntryCopyTemplate(), VersionedRandomAllocationSegment::isPageIdAllocateCommitted(), VersionedRandomAllocationSegment::isPageIdAllocated(), isPageIdAllocated(), VersionedRandomAllocationSegment::isPageIdValid(), and isPageIdValid().
00389 { 00390 if (!DelegatingSegment::isPageIdAllocated(pageId)) { 00391 return false; 00392 } 00393 00394 uint iSegAlloc; 00395 ExtentNum extentNum; 00396 BlockNum iPageInExtent; 00397 splitPageId(pageId,iSegAlloc,extentNum,iPageInExtent); 00398 if (!iPageInExtent) { 00399 // header pages are valid but not allocated (from the 00400 // perspective of the RandomAllocationSegment, not the 00401 // underlying linear segment) 00402 if (testAllocation) { 00403 return false; 00404 } else { 00405 return true; 00406 } 00407 } 00408 PageOwnerId ownerId = getPageOwnerId(pageId, thisSegment); 00409 return (ownerId != UNALLOCATED_PAGE_OWNER_ID); 00410 }
virtual PageOwnerId RandomAllocationSegmentBase::getPageOwnerId | ( | PageId | pageId, | |
bool | thisSegment | |||
) | [protected, pure virtual] |
Retrieves the ownerId corresponding to a page entry.
pageId | PageId of the page whose owner we are retrieving | |
thisSegment | if true, retrieve page entry from this segment; otherwise, retrieve it from an alternative segment |
Implemented in RandomAllocationSegment, and VersionedRandomAllocationSegment.
Referenced by testPageId().
PageOwnerId RandomAllocationSegmentBase::getPageOwnerIdTemplate | ( | PageId | pageId, | |
bool | thisSegment | |||
) | [protected] |
Retrieves the ownerId corresponding to a page entry.
This template method allows the caller to specify different page entry types.
pageId | PageId of the page whose owner we are retrieving | |
thisSegment | if true, retrieve page entry from this segment; otherwise, retrieve it from an alternative segment |
Definition at line 262 of file RandomAllocationSegmentBaseImpl.h.
References getPageEntryCopy().
00265 { 00266 PageEntryT pageEntry; 00267 00268 getPageEntryCopy(pageId, pageEntry, false, thisSegment); 00269 return pageEntry.ownerId; 00270 }
virtual void RandomAllocationSegmentBase::freePageEntry | ( | ExtentNum | extentNum, | |
BlockNum | iPageInExtent | |||
) | [protected, pure virtual] |
Marks the page entry corresponding to a deallocated page as unallocated.
extentNum | absolute 0-based extent number | |
iPageInExtent | 0-based index of page in extent |
Implemented in RandomAllocationSegment, and VersionedRandomAllocationSegment.
Referenced by deallocatePageId().
void RandomAllocationSegmentBase::freePageEntryTemplate | ( | ExtentNum | extentNum, | |
BlockNum | iPageInExtent | |||
) | [protected] |
Marks the page entry corresponding to a deallocated page as unallocated.
The extent is specified by the the extentNum, the index of the page in the extent, and the segment where the extent allocation node originates from.
This template method allows the caller to specify different extent allocation node types.
extentNum | absolute 0-based extent number | |
iPageInExtent | 0-based index of deallocated page in extent |
Definition at line 225 of file RandomAllocationSegmentBaseImpl.h.
References getExtentAllocPageId(), Segment::getTracingSegment(), markPageEntryUnused(), Segment::pCache, and UNALLOCATED_PAGE_OWNER_ID.
Referenced by VersionedRandomAllocationSegment::freePageEntry(), and RandomAllocationSegment::freePageEntry().
00228 { 00229 SegmentAccessor segAccessor(getTracingSegment(), pCache); 00230 ExtentAllocLockT extentAllocLock(segAccessor); 00231 00232 extentAllocLock.lockExclusive(getExtentAllocPageId(extentNum)); 00233 ExtentAllocationNodeT &extentNode = extentAllocLock.getNodeForWrite(); 00234 PageEntryT &pageEntry = extentNode.getPageEntry(iPageInExtent); 00235 permAssert(pageEntry.ownerId != UNALLOCATED_PAGE_OWNER_ID); 00236 markPageEntryUnused(pageEntry); 00237 }
void RandomAllocationSegmentBase::markPageEntryUnused | ( | PageEntry & | pageEntry | ) | [protected, virtual] |
Marks a page entry as unused.
[in,out] | pageEntry | entry to be marked |
Reimplemented in VersionedRandomAllocationSegment.
Definition at line 136 of file RandomAllocationSegmentBase.cpp.
References NULL_PAGE_ID, PageEntry::ownerId, PageEntry::successorId, and UNALLOCATED_PAGE_OWNER_ID.
Referenced by formatExtentTemplate(), freePageEntryTemplate(), and VersionedRandomAllocationSegment::markPageEntryUnused().
00138 { 00139 pageEntry.ownerId = UNALLOCATED_PAGE_OWNER_ID; 00140 pageEntry.successorId = NULL_PAGE_ID; 00141 }
PageId RandomAllocationSegmentBase::getFirstSegAllocPageId | ( | ) | const [inline, protected] |
Definition at line 99 of file RandomAllocationSegmentBaseImpl.h.
References FIRST_LINEAR_PAGE_ID.
Referenced by allocatePageIdFromSegment(), and countAllocatedPages().
00100 { 00101 return FIRST_LINEAR_PAGE_ID; 00102 }
uint RandomAllocationSegmentBase::inferSegAllocCount | ( | ) | [protected] |
Infers the number of SegmentAllocationNodes from the size of the underlying segment.
Definition at line 143 of file RandomAllocationSegmentBase.cpp.
References DelegatingSegment::getAllocatedSizeInPages(), and nPagesPerSegAlloc.
Referenced by format().
00144 { 00145 BlockNum nPages = DelegatingSegment::getAllocatedSizeInPages(); 00146 // round up 00147 return nPages / nPagesPerSegAlloc + 00148 (nPages % nPagesPerSegAlloc ? 1 : 0); 00149 }
void RandomAllocationSegmentBase::format | ( | ) | [protected] |
Formats allocation pages based on current size of underlying segment, marking all pages as deallocated.
Definition at line 67 of file RandomAllocationSegmentBase.cpp.
References DelegatingSegment::ensureAllocatedSize(), formatPageExtents(), DelegatingSegment::getAllocatedSizeInPages(), SegNodeLock< Node >::getNodeForWrite(), getSegAllocPageId(), Segment::getTracingSegment(), inferSegAllocCount(), SegPageLock::lockExclusive(), min(), SegmentAllocationNode::nExtents, nExtentsPerSegAlloc, SegmentAllocationNode::nextSegAllocPageId, SegmentAllocationNode::nPagesPerExtent, nPagesPerExtent, NULL_PAGE_ID, Segment::pCache, and SegNodeLock< Node >::setMagicNumber().
Referenced by VersionedRandomAllocationSegment::deallocatePageRange(), and deallocatePageRange().
00068 { 00069 // calculate number of SegAllocNodes based on current segment size 00070 uint nSegAllocPages = inferSegAllocCount(); 00071 00072 // calculate number of extents in all but last SegAllocNode 00073 ExtentNum nExtents = (nSegAllocPages-1)*nExtentsPerSegAlloc; 00074 00075 // calculate number of pages in last SegAllocNode 00076 BlockNum nRemainderPages = DelegatingSegment::getAllocatedSizeInPages(); 00077 nRemainderPages -= (nExtents*nPagesPerExtent+nSegAllocPages); 00078 00079 if (nRemainderPages) { 00080 // last SegAllocNode is not full; add number of remainder extents, 00081 // rounding down 00082 nExtents += nRemainderPages / nPagesPerExtent; 00083 } else { 00084 // last SegAllocNode is full 00085 nExtents += nExtentsPerSegAlloc; 00086 } 00087 00088 // always format at least one extent; this is somewhat arbitrary, but helps 00089 // to avoid spurious problems with tiny segments in test cases 00090 if (!nExtents) { 00091 nSegAllocPages = 1; 00092 nExtents = 1; 00093 } 00094 00095 // make sure underlying segment is big enough 00096 bool bigEnough = DelegatingSegment::ensureAllocatedSize( 00097 nExtents*nPagesPerExtent + nSegAllocPages); 00098 permAssert(bigEnough); 00099 00100 // format each SegAllocNode 00101 00102 ExtentNum extentNum = 0; 00103 SegmentAccessor selfAccessor(getTracingSegment(), pCache); 00104 SegAllocLock segAllocLock(selfAccessor); 00105 for (uint iSegAlloc = 0; iSegAlloc < nSegAllocPages; iSegAlloc++) { 00106 PageId segAllocPageId = getSegAllocPageId(iSegAlloc); 00107 segAllocLock.lockExclusive(segAllocPageId); 00108 00109 // REVIEW: have to do setMagicNumber() explicitly since we skipped 00110 // allocation. Should figure out a way to indicate allocation of a 00111 // specific PageId. 00112 segAllocLock.setMagicNumber(); 00113 SegmentAllocationNode &segAllocNode = segAllocLock.getNodeForWrite(); 00114 00115 uint iNextSegAlloc = iSegAlloc + 1; 00116 if (iNextSegAlloc < nSegAllocPages) { 00117 // set up SegAllocNode chain 00118 segAllocNode.nextSegAllocPageId = getSegAllocPageId(iNextSegAlloc); 00119 } else { 00120 // terminate SegAllocNode chain at last node 00121 segAllocNode.nextSegAllocPageId = NULL_PAGE_ID; 00122 } 00123 00124 // format extent array 00125 segAllocNode.nPagesPerExtent = nPagesPerExtent; 00126 segAllocNode.nExtents = std::min(nExtents,nExtentsPerSegAlloc); 00127 nExtents -= segAllocNode.nExtents; 00128 00129 // format each extent node within the page 00130 formatPageExtents(segAllocNode, extentNum); 00131 } 00132 00133 permAssert(!nExtents); 00134 }
virtual void RandomAllocationSegmentBase::formatPageExtents | ( | SegmentAllocationNode & | segAllocNode, | |
ExtentNum & | extentNum | |||
) | [protected, pure virtual] |
Formats each of the extents within a segment allocation node.
[in] | segAllocNode | locked segment allocation node |
[in,out] | extentNum | on input, the initial absolute 0-based extent number that needs to be formatted; on output, the last extent number formatted + 1 |
Implemented in RandomAllocationSegment, and VersionedRandomAllocationSegment.
Referenced by format().
void RandomAllocationSegmentBase::formatPageExtentsTemplate | ( | SegmentAllocationNode & | segAllocNode, | |
ExtentNum & | extentNum | |||
) | [protected] |
Formats each of the extents within a segment allocation node.
This template method allows the caller to specify different extent allocation node types.
[in] | segAllocNode | locked segment allocation node |
[in,out] | extentNum | on input, the initial absolute 0-based extent number that needs to be formatted; on output, the last extent number formatted + 1 |
Definition at line 146 of file RandomAllocationSegmentBaseImpl.h.
References formatExtentTemplate(), getExtentAllocPageId(), SegmentAllocationNode::getExtentEntry(), Segment::getTracingSegment(), SegmentAllocationNode::nExtents, nExtentsPerSegAlloc, nPagesPerExtent, and Segment::pCache.
Referenced by VersionedRandomAllocationSegment::allocateExtAllocNodes(), VersionedRandomAllocationSegment::formatPageExtents(), and RandomAllocationSegment::formatPageExtents().
00149 { 00150 SegmentAccessor selfAccessor(getTracingSegment(), pCache); 00151 ExtentAllocLockT extentAllocLock(selfAccessor); 00152 uint startOffset = extentNum % nExtentsPerSegAlloc; 00153 for (uint i = startOffset; i < segAllocNode.nExtents; ++i, ++extentNum) { 00154 // -1 for the extent allocation node itself 00155 segAllocNode.getExtentEntry(i).nUnallocatedPages = 00156 nPagesPerExtent - 1; 00157 extentAllocLock.lockExclusive(getExtentAllocPageId(extentNum)); 00158 extentAllocLock.setMagicNumber(); 00159 formatExtentTemplate< 00160 ExtentAllocationNodeT, 00161 ExtentAllocLockT, 00162 PageEntryT>( 00163 extentAllocLock.getNodeForWrite()); 00164 } 00165 }
void RandomAllocationSegmentBase::formatExtentTemplate | ( | ExtentAllocationNodeT & | extentNode | ) | [protected] |
Formats one extent allocation.
This template method allows the caller to specify different extent allocation node types.
[in] | extentNode | locked extent allocation node |
Definition at line 168 of file RandomAllocationSegmentBaseImpl.h.
References ANON_PAGE_OWNER_ID, markPageEntryUnused(), and nPagesPerExtent.
Referenced by formatPageExtentsTemplate().
00170 { 00171 // mark all pages as free 00172 for (uint i = 0; i < nPagesPerExtent; i++) { 00173 PageEntryT &pageEntry = extentNode.getPageEntry(i); 00174 markPageEntryUnused(pageEntry); 00175 } 00176 00177 // mark the first entry representing the extent allocation node itself 00178 // as permanently allocated 00179 extentNode.getPageEntry(0).ownerId = ANON_PAGE_OWNER_ID; 00180 }
PageId RandomAllocationSegmentBase::allocatePageIdFromSegment | ( | PageOwnerId | ownerId, | |
SharedSegment | allocNodeSegment | |||
) | [protected] |
Allocates a page without locking it into memory.
The allocation nodes originate from a specified segment.
ownerId | the PageOwnerId of the object which will own this page, or ANON_PAGE_OWNER_ID for pages unassociated with an owner | |
allocNodeSegment | segment from which the allocation nodes originate |
Definition at line 151 of file RandomAllocationSegmentBase.cpp.
References allocateFromExtent(), allocateFromNewExtent(), DelegatingSegment::ensureAllocatedSize(), SegmentAllocationNode::getExtentEntry(), getFirstSegAllocPageId(), SegNodeLock< Node >::getNodeForRead(), SegNodeLock< Node >::getNodeForWrite(), getSegAllocPageId(), getSegAllocPageIdForWrite(), incrementPageCounters(), incrementPagesOccupiedCounter(), SegPageLock::lockExclusive(), makePageNum(), SegmentAllocationNode::nExtents, nExtentsPerSegAlloc, SegmentAllocationNode::nextSegAllocPageId, SegmentAllocationNode::nPagesPerExtent, nPagesPerExtent, NULL_PAGE_ID, SegmentAllocationNode::ExtentEntry::nUnallocatedPages, Segment::pCache, SegNodeLock< Node >::setMagicNumber(), undoSegAllocPageWrite(), and SegPageLock::unlock().
Referenced by VersionedRandomAllocationSegment::allocatePageId(), and RandomAllocationSegment::allocatePageId().
00154 { 00155 ExtentNum extentNum = 0; 00156 SegmentAccessor segAccessor(allocNodeSegment, pCache); 00157 SegAllocLock segAllocLock(segAccessor); 00158 00159 // find a SegAllocNode with free space 00160 PageId origSegAllocPageId = getFirstSegAllocPageId(); 00161 PageId segAllocPageId = getSegAllocPageIdForWrite(origSegAllocPageId); 00162 for (uint iSegAlloc = 0; ; ++iSegAlloc) { 00163 // Initially access the node for read because we may not actually 00164 // update it if all extents in the node are full. Once we need 00165 // to update the node, we'll acquire a writable node. 00166 segAllocLock.lockExclusive(segAllocPageId); 00167 SegmentAllocationNode const &readOnlySegAllocNode = 00168 segAllocLock.getNodeForRead(); 00169 00170 // check each extent 00171 for (uint i = 0; i < readOnlySegAllocNode.nExtents; ++i, ++extentNum) { 00172 SegmentAllocationNode::ExtentEntry const &readOnlyExtentEntry = 00173 readOnlySegAllocNode.getExtentEntry(i); 00174 if (readOnlyExtentEntry.nUnallocatedPages) { 00175 // found one, so get a writable node 00176 SegmentAllocationNode &writableSegAllocNode = 00177 segAllocLock.getNodeForWrite(); 00178 SegmentAllocationNode::ExtentEntry &writableExtentEntry = 00179 writableSegAllocNode.getExtentEntry(i); 00180 writableExtentEntry.nUnallocatedPages--; 00181 // explicit unlock to minimize contention window and avoid 00182 // deadlock with deallocatePageId; this is like a Southwest 00183 // airlines reservation: we've got a flight reserved, not a 00184 // particular seat on that flight, but we're guaranteed to find 00185 // a seat when we get on 00186 segAllocLock.unlock(); 00187 incrementPageCounters(); 00188 return allocateFromExtent(extentNum,ownerId); 00189 } 00190 } 00191 00192 if (readOnlySegAllocNode.nextSegAllocPageId != NULL_PAGE_ID) { 00193 // since there's no space on the current SegAllocNode, indicate 00194 // that we haven't allocated any new pages from it 00195 undoSegAllocPageWrite(origSegAllocPageId); 00196 00197 // try next SegAllocNode 00198 origSegAllocPageId = readOnlySegAllocNode.nextSegAllocPageId; 00199 segAllocPageId = getSegAllocPageIdForWrite(origSegAllocPageId); 00200 continue; 00201 } 00202 00203 // We have to extend the underlying segment, so we need to prevent 00204 // anyone else from trying to do the same thing at the same time. So 00205 // hold onto segAllocLock during this process. 00206 00207 if (readOnlySegAllocNode.nExtents < nExtentsPerSegAlloc) { 00208 // Try to allocate a new extent. The parameters to makePageNum 00209 // request just enough space to fit one more extent within the 00210 // current SegAllocNode. 00211 try { 00212 if (!DelegatingSegment::ensureAllocatedSize( 00213 makePageNum(extentNum,nPagesPerExtent))) 00214 { 00215 // couldn't grow 00216 undoSegAllocPageWrite(origSegAllocPageId); 00217 return NULL_PAGE_ID; 00218 } 00219 } catch (...) { 00220 undoSegAllocPageWrite(origSegAllocPageId); 00221 throw; 00222 } 00223 00224 // acquire a writable node now that we're actually updating it 00225 SegmentAllocationNode &writableSegAllocNode = 00226 segAllocLock.getNodeForWrite(); 00227 writableSegAllocNode.nExtents++; 00228 SegmentAllocationNode::ExtentEntry &writableExtentEntry = 00229 writableSegAllocNode.getExtentEntry( 00230 writableSegAllocNode.nExtents - 1); 00231 00232 // -2 = -1 for extent allocation node, -1 for page we're 00233 // about to allocate 00234 writableExtentEntry.nUnallocatedPages = nPagesPerExtent - 2; 00235 00236 incrementPageCounters(); 00237 // another increment for the extent page 00238 incrementPagesOccupiedCounter(); 00239 return allocateFromNewExtent(extentNum, ownerId); 00240 } 00241 00242 // since there's no space on the current SegAllocNode, indicate 00243 // that we haven't allocated any pages from its extents 00244 undoSegAllocPageWrite(origSegAllocPageId); 00245 00246 // Have to allocate a whole new SegAllocNode. The parameters to 00247 // makePageNum request enough space to fit the first extent of a new 00248 // SegAllocNode. 00249 if (!DelegatingSegment::ensureAllocatedSize( 00250 makePageNum(extentNum + 1,0))) 00251 { 00252 // couldn't grow 00253 return NULL_PAGE_ID; 00254 } 00255 00256 SegAllocLock newSegAllocLock(segAccessor); 00257 origSegAllocPageId = getSegAllocPageId(iSegAlloc + 1); 00258 segAllocPageId = getSegAllocPageIdForWrite(origSegAllocPageId); 00259 newSegAllocLock.lockExclusive(segAllocPageId); 00260 newSegAllocLock.setMagicNumber(); 00261 SegmentAllocationNode &newNode = newSegAllocLock.getNodeForWrite(); 00262 newNode.nPagesPerExtent = nPagesPerExtent; 00263 newNode.nExtents = 0; 00264 newNode.nextSegAllocPageId = NULL_PAGE_ID; 00265 // increment for the segment allocation node 00266 incrementPagesOccupiedCounter(); 00267 00268 // acquire a writable node to update the next page pointer 00269 SegmentAllocationNode &writableSegAllocNode = 00270 segAllocLock.getNodeForWrite(); 00271 writableSegAllocNode.nextSegAllocPageId = origSegAllocPageId; 00272 00273 // Carry on with the loop. We'll unlock and relock the node just 00274 // allocated, but that's not a big deal since allocating a new 00275 // SegAllocNode is very rare. 00276 } 00277 }
virtual PageId RandomAllocationSegmentBase::allocateFromExtent | ( | ExtentNum | extentNum, | |
PageOwnerId | ownerId | |||
) | [protected, pure virtual] |
Allocates a new page from an extent known to have space.
extentNum | absolute 0-based extent number from which to allocate | |
ownerId | PageOwnerId of owning object |
Implemented in RandomAllocationSegment, and VersionedRandomAllocationSegment.
Referenced by allocatePageIdFromSegment().
PageId RandomAllocationSegmentBase::allocateFromExtentTemplate | ( | ExtentNum | extentNum, | |
PageOwnerId | ownerId, | |||
SharedSegment | allocNodeSegment | |||
) | [protected] |
Allocates a new page from an extent known to have space.
The extent is specified by the absolute extent number and the segment where the extent allocation node originates from.
This template method allows the caller to specify different extent allocation node types.
extentNum | absolute 0-based extent number from which to allocate | |
ownerId | PageOwnerId of owning object | |
allocNodeSegment | segment that the allocation node page originates from |
Definition at line 127 of file RandomAllocationSegmentBaseImpl.h.
References getExtAllocPageIdForWrite(), Segment::pCache, and UNALLOCATED_PAGE_OWNER_ID.
Referenced by VersionedRandomAllocationSegment::allocateFromExtent(), and RandomAllocationSegment::allocateFromExtent().
00131 { 00132 permAssert(ownerId != UNALLOCATED_PAGE_OWNER_ID); 00133 00134 SegmentAccessor segAccessor(allocNodeSegment, pCache); 00135 ExtentAllocLockT extentAllocLock(segAccessor); 00136 extentAllocLock.lockExclusive(getExtAllocPageIdForWrite(extentNum)); 00137 ExtentAllocationNodeT &node = extentAllocLock.getNodeForWrite(); 00138 return 00139 allocateFromLockedExtentTemplate<ExtentAllocationNodeT, PageEntryT>( 00140 node, 00141 extentNum, 00142 ownerId); 00143 }
virtual PageId RandomAllocationSegmentBase::allocateFromNewExtent | ( | ExtentNum | extentNum, | |
PageOwnerId | ownerId | |||
) | [protected, pure virtual] |
Allocates a page from a new extent allocation node.
extentNum | absolute extent number from which to allocate | |
ownerId | PageOwnerId of owning object |
Implemented in RandomAllocationSegment, and VersionedRandomAllocationSegment.
Referenced by allocatePageIdFromSegment().
PageId RandomAllocationSegmentBase::allocateFromNewExtentTemplate | ( | ExtentNum | extentNum, | |
PageOwnerId | ownerId, | |||
SharedSegment | allocNodeSegment | |||
) | [protected] |
Allocates a page from a new extent allocation node.
The extent is specified by the absolute extent number and the segment where the extent allocation node originates from.
This template method allows the caller to specify different extent allocation node types.
extentNum | absolute 0-based extent number from which to allocate | |
ownerId | PageOwnerId of owning object | |
allocNodeSegment | segment that the allocation node page originates from |
Definition at line 183 of file RandomAllocationSegmentBaseImpl.h.
References getExtAllocPageIdForWrite(), and Segment::pCache.
Referenced by VersionedRandomAllocationSegment::allocateFromNewExtent(), and RandomAllocationSegment::allocateFromNewExtent().
00187 { 00188 SegmentAccessor segAccessor(allocNodeSegment, pCache); 00189 ExtentAllocLockT extentAllocLock(segAccessor); 00190 extentAllocLock.lockExclusive(getExtAllocPageIdForWrite(extentNum)); 00191 extentAllocLock.setMagicNumber(); 00192 ExtentAllocationNodeT &extentNode = extentAllocLock.getNodeForWrite(); 00193 formatExtentTemplate<ExtentAllocationNodeT, ExtentAllocLockT, PageEntryT>( 00194 extentNode); 00195 return 00196 allocateFromLockedExtentTemplate<ExtentAllocationNodeT, PageEntryT>( 00197 extentNode, 00198 extentNum, 00199 ownerId); 00200 }
PageId RandomAllocationSegmentBase::allocateFromLockedExtentTemplate | ( | ExtentAllocationNodeT & | extentNode, | |
ExtentNum | extentNum, | |||
PageOwnerId | ownerId | |||
) | [protected] |
Allocates a new page from an extent known to have space, with the extent allocation node already locked.
This template method allows the caller to specify different extent allocation node types.
[in] | extentNode | locked extent allocation node corresponding to extentNum |
extentNum | absolute extent number from which to allocate | |
ownerId | PageOwnerId of owning object |
Definition at line 203 of file RandomAllocationSegmentBaseImpl.h.
References Segment::getLinearPageId(), makePageNum(), nPagesPerExtent, and UNALLOCATED_PAGE_OWNER_ID.
00205 { 00206 // find a free page 00207 for (uint i = 0; i < nPagesPerExtent; i++) { 00208 PageEntryT &pageEntry = node.getPageEntry(i); 00209 if (pageEntry.ownerId == UNALLOCATED_PAGE_OWNER_ID) { 00210 if (i == 0) { 00211 // entry 0 is the extent allocation node itself so it 00212 // should never be marked as unallocated 00213 permAssert(false); 00214 } 00215 pageEntry.ownerId = ownerId; 00216 PageId pageId = getLinearPageId(makePageNum(extentNum,i)); 00217 return pageId; 00218 } 00219 } 00220 00221 permAssert(false); 00222 }
void RandomAllocationSegmentBase::setPageSuccessorTemplate | ( | PageId | pageId, | |
PageId | successorId, | |||
SharedSegment | allocNodeSegment | |||
) | [protected] |
Sets the successor pageId for a page.
This template method allows the caller to specify different extent allocation node types.
pageId | pageId of the page whose successor will be set | |
successorId | successor pageId | |
allocNodeSegment | segment that the allocation node page originates from |
Definition at line 240 of file RandomAllocationSegmentBaseImpl.h.
References getExtAllocPageIdForWrite(), isPageIdAllocated(), NULL_PAGE_ID, Segment::pCache, and splitPageId().
Referenced by VersionedRandomAllocationSegment::setPageSuccessor().
00244 { 00245 assert(isPageIdAllocated(pageId)); 00246 assert((successorId == NULL_PAGE_ID) || isPageIdAllocated(successorId)); 00247 00248 uint iSegAlloc; 00249 ExtentNum extentNum; 00250 BlockNum iPageInExtent; 00251 splitPageId(pageId, iSegAlloc, extentNum, iPageInExtent); 00252 permAssert(iPageInExtent); 00253 00254 SegmentAccessor segAccessor(allocNodeSegment, pCache); 00255 ExtentAllocLockT extentAllocLock(segAccessor); 00256 extentAllocLock.lockExclusive(getExtAllocPageIdForWrite(extentNum)); 00257 ExtentAllocationNodeT &node = extentAllocLock.getNodeForWrite(); 00258 node.getPageEntry(iPageInExtent).successorId = successorId; 00259 }
virtual PageId RandomAllocationSegmentBase::getSegAllocPageIdForRead | ( | PageId | origSegAllocPageId, | |
SharedSegment & | allocNodeSegment | |||
) | [protected, pure virtual] |
Retrieves the actual pageId corresponding to the SegmentAllocationNode that should be accessed when reading from the node.
origSegAllocPageId | original SegmentAllocationNode pageId | |
[out] | allocNodeSegment | segment from which the allocation node to be read originates |
Implemented in RandomAllocationSegment, and VersionedRandomAllocationSegment.
Referenced by countAllocatedPages().
virtual PageId RandomAllocationSegmentBase::getExtAllocPageIdForRead | ( | ExtentNum | extentNum, | |
SharedSegment & | allocNodeSegment | |||
) | [protected, pure virtual] |
Retrieves the actual pageId corresponding to the extent allocation node that should be accessed when reading from the node.
extentNum | absolute 0-based extent number | |
[out] | allocNodeSegment | segment from which the allocation node to be read originates |
Implemented in RandomAllocationSegment, and VersionedRandomAllocationSegment.
Referenced by getPageEntryCopyTemplate().
virtual void RandomAllocationSegmentBase::getPageEntryCopy | ( | PageId | pageId, | |
PageEntry & | pageEntryCopy, | |||
bool | isAllocated, | |||
bool | thisSegment | |||
) | [protected, pure virtual] |
Retrieves a copy of the page entry for a specified page.
pageId | pageId of the page whose page entry data we are retrieving | |
[out] | pageEntryCopy | copy of page entry retrieved |
isAllocated | if true, assert that the page is allocated | |
thisSegment | if true, retrieve page entry from this segment; otherwise, retrieve it from an alternative segment |
Implemented in RandomAllocationSegment, and VersionedRandomAllocationSegment.
Referenced by getPageOwnerIdTemplate().
void RandomAllocationSegmentBase::getPageEntryCopyTemplate | ( | PageId | pageId, | |
PageEntryT & | pageEntryCopy, | |||
bool | isAllocated, | |||
bool | thisSegment | |||
) | [protected] |
Retrieves a copy of the page entry for a specified page.
This template method allows the caller to specify different extent allocation node and page entry types.
pageId | pageId of the page whose page entry data we are retrieving | |
[out] | pageEntryCopy | copy of page entry retrieved |
isAllocated | if true, assert that the page is allocated | |
thisSegment | if true, retrieve page entry from this segment; otherwise, retrieve it from an alternative segment |
Definition at line 273 of file RandomAllocationSegmentBaseImpl.h.
References getExtAllocPageIdForRead(), getExtentAllocPageId(), Segment::getTracingSegment(), Segment::pCache, splitPageId(), and testPageId().
Referenced by VersionedRandomAllocationSegment::getPageEntryCopy().
00278 { 00279 if (isAllocated) { 00280 assert(testPageId(pageId, true, thisSegment)); 00281 } 00282 00283 ExtentNum extentNum; 00284 BlockNum iPageInExtent; 00285 uint iSegAlloc; 00286 splitPageId(pageId, iSegAlloc, extentNum, iPageInExtent); 00287 assert(iPageInExtent); 00288 00289 SharedSegment allocNodeSegment; 00290 PageId extentPageId; 00291 if (thisSegment) { 00292 allocNodeSegment = getTracingSegment(); 00293 extentPageId = getExtentAllocPageId(extentNum); 00294 } else { 00295 extentPageId = getExtAllocPageIdForRead(extentNum, allocNodeSegment); 00296 } 00297 00298 SegmentAccessor segAccessor(allocNodeSegment, pCache); 00299 ExtentAllocLockT extentAllocLock(segAccessor); 00300 extentAllocLock.lockShared(extentPageId); 00301 ExtentAllocationNodeT const &extentNode = 00302 extentAllocLock.getNodeForRead(); 00303 00304 PageEntryT const &pageEntry = 00305 extentNode.getPageEntry(iPageInExtent); 00306 00307 pageEntryCopy = pageEntry; 00308 }
BlockId RandomAllocationSegmentBase::translatePageId | ( | PageId | ) | [virtual] |
Maps from a PageId in this segment to a BlockId.
Reimplemented from DelegatingSegment.
Definition at line 377 of file RandomAllocationSegmentBase.cpp.
References isPageIdValid(), and DelegatingSegment::translatePageId().
Referenced by VersionedRandomAllocationSegment::locateDataPages(), and VersionedRandomAllocationSegment::restoreFromBackup().
00378 { 00379 assert( 00380 const_cast<RandomAllocationSegmentBase *>(this)->isPageIdValid(pageId)); 00381 00382 return DelegatingSegment::translatePageId(pageId); 00383 }
bool RandomAllocationSegmentBase::isPageIdAllocated | ( | PageId | pageId | ) | [virtual] |
Tests whether a PageId is allocated.
pageId | the PageId of interest |
Reimplemented from DelegatingSegment.
Reimplemented in VersionedRandomAllocationSegment.
Definition at line 417 of file RandomAllocationSegmentBase.cpp.
References testPageId().
Referenced by deallocatePageId(), and setPageSuccessorTemplate().
00418 { 00419 return testPageId(pageId,true,true); 00420 }
Segment::AllocationOrder RandomAllocationSegmentBase::getAllocationOrder | ( | ) | const [virtual] |
Reimplemented from DelegatingSegment.
Definition at line 372 of file RandomAllocationSegmentBase.cpp.
References Segment::RANDOM_ALLOCATION.
00373 { 00374 return RANDOM_ALLOCATION; 00375 }
BlockNum RandomAllocationSegmentBase::getAllocatedSizeInPages | ( | ) | [virtual] |
Reimplemented from DelegatingSegment.
Definition at line 422 of file RandomAllocationSegmentBase.cpp.
References nPagesAllocated.
Referenced by SnapshotSegmentTest::deallocateOldPages().
00423 { 00424 return nPagesAllocated; 00425 }
BlockNum RandomAllocationSegmentBase::getNumPagesOccupiedHighWater | ( | ) | [virtual] |
Returns the max number of pages occupied by this segment instance.
In other words, pages that are allocated but subsequently deallocated, are included in this count. Also, the count includes all pages used by the segment, including metadata pages.
Reimplemented from DelegatingSegment.
Definition at line 448 of file RandomAllocationSegmentBase.cpp.
References nPagesOccupiedHighWater.
00449 { 00450 return nPagesOccupiedHighWater; 00451 }
void RandomAllocationSegmentBase::deallocatePageRange | ( | PageId | startPageId, | |
PageId | endPageId | |||
) | [virtual] |
Deallocates a range of pages allocated from this segment.
Some segment implementations may impose restrictions on the range (e.g. individual pages only, entire segment truncation only, start-ranges, or end-ranges). The interpretation of the range may also vary by segment (e.g. for a LINEAR_ALLOCATION segment, it's a simple linear PageId range, while for a RANDOM_ALLOCATION segment, successors could be used).
Depending on the circumstances, it may be the responsibility of the segment to discard the corresponding blocks from the cache. The details vary by segment implementation.
startPageId | inclusive start of PageId range to deallocate, or default NULL_PAGE_ID for beginning of segment | |
endPageId | inclusive end of PageId range to deallocate, or default NULL_PAGE_ID for end of segment |
Reimplemented from DelegatingSegment.
Reimplemented in VersionedRandomAllocationSegment.
Definition at line 326 of file RandomAllocationSegmentBase.cpp.
References deallocatePageId(), format(), and NULL_PAGE_ID.
Referenced by VersionedRandomAllocationSegment::deallocateSinglePage().
00329 { 00330 permAssert(startPageId == endPageId); 00331 if (startPageId != NULL_PAGE_ID) { 00332 deallocatePageId(startPageId); 00333 } else { 00334 format(); 00335 } 00336 }
void RandomAllocationSegmentBase::initForUse | ( | ) | [virtual] |
Performs additional initialization required on the segment after it has been properly formatted.
Reimplemented from Segment.
Reimplemented in VersionedRandomAllocationSegment.
Definition at line 62 of file RandomAllocationSegmentBase.cpp.
References countAllocatedPages().
Referenced by VersionedRandomAllocationSegment::initForUse().
00063 { 00064 countAllocatedPages(); 00065 }
SharedSegment const& DelegatingSegment::getDelegateSegment | ( | ) | const [inline, inherited] |
Definition at line 53 of file DelegatingSegment.h.
Referenced by SegmentFactory::dynamicCast(), TracingSegment::getMappedPageListener(), TracingSegment::isWriteVersioned(), and TracingSegment::notifyAfterPageCheckpointFlush().
00054 { 00055 return pDelegateSegment; 00056 }
BlockNum DelegatingSegment::getNumPagesExtended | ( | ) | [virtual, inherited] |
Implements Segment.
Definition at line 57 of file DelegatingSegment.cpp.
References DelegatingSegment::pDelegateSegment.
00058 { 00059 return pDelegateSegment->getNumPagesExtended(); 00060 }
PageId DelegatingSegment::getPageSuccessor | ( | PageId | pageId | ) | [virtual, inherited] |
Determines the successor of a given PageId.
This is an optional interface only supported by segments with some concept of page ordering.
pageId | PageId for which the successor is to be found |
Implements Segment.
Reimplemented in CircularSegment, LinearViewSegment, RandomAllocationSegment, SnapshotRandomAllocationSegment, and VersionedRandomAllocationSegment.
Definition at line 62 of file DelegatingSegment.cpp.
References DelegatingSegment::pDelegateSegment.
Referenced by SnapshotRandomAllocationSegment::getPageSuccessor(), and LinearViewSegment::LinearViewSegment().
00063 { 00064 return pDelegateSegment->getPageSuccessor(pageId); 00065 }
void DelegatingSegment::setPageSuccessor | ( | PageId | pageId, | |
PageId | successorId | |||
) | [virtual, inherited] |
Sets the successor of a given PageId.
This is an optional interface only supported by segments with some concept of modifiable ordering.
pageId | PageId for which the successor is to be set | |
successorId | PageId of successor |
Implements Segment.
Reimplemented in CircularSegment, LinearViewSegment, RandomAllocationSegment, SnapshotRandomAllocationSegment, TracingSegment, and VersionedRandomAllocationSegment.
Definition at line 67 of file DelegatingSegment.cpp.
References DelegatingSegment::pDelegateSegment.
Referenced by LinearViewSegment::allocatePageId(), TracingSegment::setPageSuccessor(), and SnapshotRandomAllocationSegment::setPageSuccessor().
00068 { 00069 pDelegateSegment->setPageSuccessor(pageId,successorId); 00070 }
PageId DelegatingSegment::translateBlockId | ( | BlockId | ) | [virtual, inherited] |
Maps from a BlockId to a PageId in this segment.
Implements Segment.
Reimplemented in CircularSegment, LinearViewSegment, and TracingSegment.
Definition at line 77 of file DelegatingSegment.cpp.
References DelegatingSegment::pDelegateSegment.
Referenced by VersionedSegment::canFlushPage(), SnapshotRandomAllocationSegment::getMappedPageListener(), WALSegment::notifyAfterPageFlush(), WALSegment::notifyPageDirty(), VersionedSegment::notifyPageDirty(), TracingSegment::translateBlockId(), LinearViewSegment::translateBlockId(), and CircularSegment::translateBlockId().
00078 { 00079 return pDelegateSegment->translateBlockId(blockId); 00080 }
PageId DelegatingSegment::allocatePageId | ( | PageOwnerId | ownerId = ANON_PAGE_OWNER_ID |
) | [virtual, inherited] |
Allocates a page without locking it into memory.
ownerId | the PageOwnerId of the object which will own this page, or ANON_PAGE_OWNER_ID for pages unassociated with an owner |
Implements Segment.
Reimplemented in CircularSegment, LinearViewSegment, RandomAllocationSegment, SnapshotRandomAllocationSegment, TracingSegment, and VersionedRandomAllocationSegment.
Definition at line 82 of file DelegatingSegment.cpp.
References DelegatingSegment::pDelegateSegment.
Referenced by TracingSegment::allocatePageId(), SnapshotRandomAllocationSegment::allocatePageId(), and LinearViewSegment::allocatePageId().
00083 { 00084 return pDelegateSegment->allocatePageId(ownerId); 00085 }
bool DelegatingSegment::ensureAllocatedSize | ( | BlockNum | nPages | ) | [virtual, inherited] |
Allocates pages as needed to make getAllocatedSizeInPages() meet a lower bound.
The PageId's of the allocated pages are not returned, so this is mostly only meaningful for linear segments.
nPages | lower bound for getAllocatedSizeInPages() |
Reimplemented from Segment.
Reimplemented in TracingSegment.
Definition at line 87 of file DelegatingSegment.cpp.
References DelegatingSegment::pDelegateSegment.
Referenced by allocatePageIdFromSegment(), TracingSegment::ensureAllocatedSize(), format(), and VersionedRandomAllocationSegment::restoreFromBackup().
00088 { 00089 return pDelegateSegment->ensureAllocatedSize(nPages); 00090 }
void DelegatingSegment::delegatedCheckpoint | ( | Segment & | delegatingSegment, | |
CheckpointType | checkpointType | |||
) | [virtual, inherited] |
Helper for DelegatingSegment.
delegatingSegment | the Segment on which checkpoint was originally called | |
checkpointType | type of checkpoint requested |
Reimplemented from Segment.
Reimplemented in SnapshotRandomAllocationSegment, TracingSegment, and VersionedSegment.
Definition at line 142 of file DelegatingSegment.cpp.
References DelegatingSegment::pDelegateSegment.
Referenced by VersionedSegment::delegatedCheckpoint(), and TracingSegment::delegatedCheckpoint().
00144 { 00145 pDelegateSegment->delegatedCheckpoint(delegatingSegment,checkpointType); 00146 }
PageId DelegatingSegment::updatePage | ( | PageId | pageId, | |
bool | needsTranslation = false | |||
) | [virtual, inherited] |
Determines whether a page can be updated in-place, and if so, prepares the page for update.
pageId | pageId of the page being modified | |
needsTranslation | true if the pageId needs to be mapped to the appropriate update page; defaults to false |
Reimplemented from Segment.
Reimplemented in LinearViewSegment, and SnapshotRandomAllocationSegment.
Definition at line 148 of file DelegatingSegment.cpp.
References DelegatingSegment::pDelegateSegment.
Referenced by LinearViewSegment::updatePage().
00149 { 00150 return pDelegateSegment->updatePage(pageId, needsTranslation); 00151 }
void DelegatingSegment::notifyPageMap | ( | CachePage & | page | ) | [virtual, inherited] |
Receives notification from CacheImpl as soon as a page is mapped, before any I/O is initiated to retrieve the page contents.
Called with the page mutex held, so the implementation must take care to avoid deadlock.
page | the page being mapped |
Reimplemented from MappedPageListener.
Reimplemented in TracingSegment.
Definition at line 107 of file DelegatingSegment.cpp.
References DelegatingSegment::pDelegateSegment.
Referenced by TracingSegment::notifyPageMap().
00108 { 00109 pDelegateSegment->notifyPageMap(page); 00110 }
void DelegatingSegment::notifyPageUnmap | ( | CachePage & | page | ) | [virtual, inherited] |
Receives notification from CacheImpl just before a page is unmapped.
Called with the page mutex held, so the implementation must take care to avoid deadlock.
page | the page being unmapped |
Reimplemented from MappedPageListener.
Reimplemented in TracingSegment, and WALSegment.
Definition at line 112 of file DelegatingSegment.cpp.
References DelegatingSegment::pDelegateSegment.
Referenced by TracingSegment::notifyPageUnmap().
00113 { 00114 pDelegateSegment->notifyPageUnmap(page); 00115 }
void DelegatingSegment::notifyAfterPageRead | ( | CachePage & | page | ) | [virtual, inherited] |
Receives notification from CacheImpl after a page read completes.
Called with the page mutex held, so the implementation must take care to avoid deadlock.
page | the page read |
Reimplemented from MappedPageListener.
Reimplemented in TracingSegment.
Definition at line 117 of file DelegatingSegment.cpp.
References DelegatingSegment::pDelegateSegment.
Referenced by TracingSegment::notifyAfterPageRead().
00118 { 00119 pDelegateSegment->notifyAfterPageRead(page); 00120 }
void DelegatingSegment::notifyPageDirty | ( | CachePage & | page, | |
bool | bDataValid | |||
) | [virtual, inherited] |
Receives notification from CacheImpl the first time a page becomes dirty after it has been mapped (but before the contents have changed).
Allows some logging action to be taken; for example, making a backup copy of the unmodified page contents. Note that when called for a newly allocated page, the page contents are invalid. Because it is implied that the calling thread already has an exclusive lock on the page, no cache locks are held when called.
page | the page being modified | |
bDataValid | if true, the page data was already valid; if false, the data was invalid, but has now been marked valid since it's about to be written |
Reimplemented from MappedPageListener.
Reimplemented in SnapshotRandomAllocationSegment, TracingSegment, VersionedSegment, and WALSegment.
Definition at line 122 of file DelegatingSegment.cpp.
References DelegatingSegment::pDelegateSegment.
Referenced by WALSegment::notifyPageDirty(), VersionedSegment::notifyPageDirty(), TracingSegment::notifyPageDirty(), and SnapshotRandomAllocationSegment::notifyPageDirty().
00123 { 00124 pDelegateSegment->notifyPageDirty(page,bDataValid); 00125 }
void DelegatingSegment::notifyBeforePageFlush | ( | CachePage & | page | ) | [virtual, inherited] |
Receives notification from CacheImpl just before a dirty page is flushed to disk.
Allows some logging action to be taken; for example, flushing corresponding write-ahead log pages, or storing a checksum in the page header. Called with the page mutex held, so the implementation must take care to avoid deadlock.
page | the page to be flushed |
Reimplemented from MappedPageListener.
Reimplemented in TracingSegment.
Definition at line 127 of file DelegatingSegment.cpp.
References DelegatingSegment::pDelegateSegment.
Referenced by TracingSegment::notifyBeforePageFlush().
00128 { 00129 pDelegateSegment->notifyBeforePageFlush(page); 00130 }
void DelegatingSegment::notifyAfterPageFlush | ( | CachePage & | page | ) | [virtual, inherited] |
Receives notification from CacheImpl when a page flush completes successfully.
Called with the page mutex held, so the implementation must take care to avoid deadlock.
page | the page that was flushed |
Reimplemented from MappedPageListener.
Reimplemented in TracingSegment, and WALSegment.
Definition at line 132 of file DelegatingSegment.cpp.
References DelegatingSegment::pDelegateSegment.
Referenced by WALSegment::notifyAfterPageFlush(), and TracingSegment::notifyAfterPageFlush().
00133 { 00134 pDelegateSegment->notifyAfterPageFlush(page); 00135 }
bool DelegatingSegment::canFlushPage | ( | CachePage & | page | ) | [virtual, inherited] |
Informs CacheImpl whether a dirty page can safely be flushed to disk.
Called with the page mutex held, so the implementation must take care to avoid deadlock.
page | the page to be flushed |
Reimplemented from MappedPageListener.
Reimplemented in SnapshotRandomAllocationSegment, and VersionedSegment.
Definition at line 137 of file DelegatingSegment.cpp.
References DelegatingSegment::pDelegateSegment.
Referenced by VersionedSegment::canFlushPage().
00138 { 00139 return pDelegateSegment->canFlushPage(page); 00140 }
void Segment::setUsablePageSize | ( | uint | ) | [protected, inherited] |
Definition at line 70 of file Segment.cpp.
References Segment::cbUsablePerPage.
Referenced by DelegatingSegment::DelegatingSegment(), DynamicDelegatingSegment::DynamicDelegatingSegment(), Segment::Segment(), and VersionedSegment::VersionedSegment().
00071 { 00072 cbUsablePerPage = cb; 00073 }
PConstBuffer Segment::getReadableFooter | ( | CachePage & | page | ) | [protected, inherited] |
Definition at line 75 of file Segment.cpp.
References CachePage::getReadableData(), and Segment::getUsablePageSize().
Referenced by VersionedSegment::getPageVersion(), and VersionedSegment::recover().
00076 { 00077 return page.getReadableData() + getUsablePageSize(); 00078 }
Definition at line 80 of file Segment.cpp.
References Segment::getUsablePageSize(), and CachePage::getWritableData().
Referenced by VersionedSegment::notifyPageDirty().
00081 { 00082 return page.getWritableData() + getUsablePageSize(); 00083 }
PageId Segment::getLinearPageSuccessor | ( | PageId | pageId | ) | [protected, inherited] |
An implementation of getPageSuccessor suitable for LINEAR_ALLOCATION.
Definition at line 85 of file Segment.cpp.
References Segment::isPageIdAllocated(), and NULL_PAGE_ID.
Referenced by ScratchSegment::getPageSuccessor(), LinearViewSegment::getPageSuccessor(), LinearDeviceSegment::getPageSuccessor(), and CircularSegment::getPageSuccessor().
00086 { 00087 assert(isPageIdAllocated(pageId)); 00088 ++pageId; 00089 if (!isPageIdAllocated(pageId)) { 00090 return NULL_PAGE_ID; 00091 } 00092 return pageId; 00093 }
void Segment::setLinearPageSuccessor | ( | PageId | pageId, | |
PageId | successorId | |||
) | [protected, inherited] |
An implementation of setPageSuccessor suitable for LINEAR_ALLOCATION.
Definition at line 95 of file Segment.cpp.
References Segment::getLinearBlockNum(), and Segment::isPageIdAllocated().
Referenced by ScratchSegment::setPageSuccessor(), LinearViewSegment::setPageSuccessor(), LinearDeviceSegment::setPageSuccessor(), and CircularSegment::setPageSuccessor().
00096 { 00097 assert(isPageIdAllocated(pageId)); 00098 assert(isPageIdAllocated(successorId)); 00099 assert(getLinearBlockNum(successorId) 00100 == getLinearBlockNum(pageId) + 1); 00101 }
bool Segment::isLinearPageIdAllocated | ( | PageId | pageId | ) | [protected, inherited] |
An implementation of isPageIdAllocated suitable for LINEAR_ALLOCATION when deallocation holes are disallowed.
Definition at line 103 of file Segment.cpp.
References Segment::getAllocatedSizeInPages(), and Segment::getLinearBlockNum().
Referenced by ScratchSegment::isPageIdAllocated(), LinearViewSegment::isPageIdAllocated(), and LinearDeviceSegment::isPageIdAllocated().
00104 { 00105 if (getLinearBlockNum(pageId) >= getAllocatedSizeInPages()) { 00106 return false; 00107 } 00108 return true; 00109 }
SharedCache Segment::getCache | ( | ) | const [inline, inherited] |
Definition at line 358 of file Segment.h.
References Segment::pCache.
Referenced by ScratchSegment::getCache(), and TempSegDestructor::operator()().
00359 { 00360 return pCache; 00361 }
uint Segment::getFullPageSize | ( | ) | const [inherited] |
Definition at line 133 of file Segment.cpp.
References Segment::pCache.
Referenced by LinearDeviceSegment::ensureAllocatedSize(), LinearDeviceSegment::getAvailableDevicePages(), LinearDeviceSegment::LinearDeviceSegment(), VersionedRandomAllocationSegment::locateDataPages(), VersionedSegment::recover(), Segment::Segment(), and SegPageLock::swapBuffers().
00134 { 00135 return pCache->getPageSize(); 00136 }
uint Segment::getUsablePageSize | ( | ) | const [inline, inherited] |
Definition at line 363 of file Segment.h.
References Segment::cbUsablePerPage.
Referenced by VersionedSegment::computeChecksum(), DynamicDelegatingSegment::DynamicDelegatingSegment(), Segment::getReadableFooter(), Segment::getWritableFooter(), VersionedSegment::notifyPageDirty(), RandomAllocationSegment::RandomAllocationSegment(), RandomAllocationSegmentBase(), SegPageLock::swapBuffers(), VersionedRandomAllocationSegment::VersionedRandomAllocationSegment(), and VersionedSegment::VersionedSegment().
00364 { 00365 return cbUsablePerPage; 00366 }
SharedSegment Segment::getTracingSegment | ( | ) | [inherited] |
Definition at line 50 of file Segment.cpp.
References Segment::pTracingSegment.
Referenced by VersionedRandomAllocationSegment::allocateAllocNodes(), RandomAllocationSegment::allocateFromExtent(), RandomAllocationSegment::allocateFromNewExtent(), RandomAllocationSegment::allocatePageId(), VersionedRandomAllocationSegment::backupAllocationNodes(), VersionedRandomAllocationSegment::chainPageEntries(), SnapshotRandomAllocationSegment::commitChanges(), VersionedRandomAllocationSegment::copyPageEntryFromTemp(), VersionedRandomAllocationSegment::copyPageEntryToTemp(), deallocatePageId(), VersionedRandomAllocationSegment::findAllocPageIdForRead(), format(), formatPageExtentsTemplate(), freePageEntryTemplate(), RandomAllocationSegment::getExtAllocPageIdForRead(), VersionedRandomAllocationSegment::getOldestTxnId(), VersionedRandomAllocationSegment::getOldPageIds(), getPageEntryCopyTemplate(), RandomAllocationSegment::getSegAllocPageIdForRead(), VersionedRandomAllocationSegment::getTempAllocNodePage(), Segment::getTracingListener(), VersionedRandomAllocationSegment::locateDataPages(), VersionedRandomAllocationSegment::restoreFromBackup(), SnapshotRandomAllocationSegment::rollbackChanges(), RandomAllocationSegment::setPageSuccessor(), VersionedRandomAllocationSegment::updateExtentEntry(), and VersionedRandomAllocationSegment::validateFreePageCount().
00051 { 00052 SharedSegment sharedPtr = pTracingSegment.lock(); 00053 if (sharedPtr && sharedPtr.get()) { 00054 return sharedPtr; 00055 } else { 00056 return shared_from_this(); 00057 } 00058 }
void Segment::setTracingSegment | ( | WeakSegment | pTracingSegmentInit | ) | [inherited] |
Sets the tracing segment associated with this segment.
pTracingSegmentInit | the tracing segment |
Definition at line 60 of file Segment.cpp.
References Segment::pTracingSegment.
00061 { 00062 pTracingSegment = pTracingSegmentInit; 00063 }
void Segment::checkpoint | ( | CheckpointType | checkpointType = CHECKPOINT_FLUSH_ALL |
) | [inherited] |
Checkpoints this segment.
checkpointType | type of checkpoint to execute |
Definition at line 111 of file Segment.cpp.
References Segment::delegatedCheckpoint(), and Segment::pTracingSegment.
Referenced by Segment::closeImpl(), BackupRestoreTest::createSnapshotData(), BackupRestoreTest::executeSnapshotTxn(), and LcsClusterReplaceExecStreamTest::testClusterReplace().
00112 { 00113 // Note that we can't use getTracingSegment() here because that method 00114 // references the shared ptr associated with this segment, and the 00115 // shared segment may have already been freed during shutdown by the 00116 // time this method is called. 00117 SharedSegment sharedPtr = pTracingSegment.lock(); 00118 if (sharedPtr && sharedPtr.get()) { 00119 delegatedCheckpoint(*(sharedPtr.get()),checkpointType); 00120 } else { 00121 delegatedCheckpoint(*this,checkpointType); 00122 } 00123 }
MappedPageListener * Segment::getMappedPageListener | ( | BlockId | blockId | ) | [virtual, inherited] |
Returns the mapped page listener corresponding to a page.
blockId | blockId of the page whose page listener we are returning |
Reimplemented in DynamicDelegatingSegment, SnapshotRandomAllocationSegment, and TracingSegment.
Definition at line 153 of file Segment.cpp.
bool Segment::isWriteVersioned | ( | ) | [virtual, inherited] |
Reimplemented in DynamicDelegatingSegment, SnapshotRandomAllocationSegment, and TracingSegment.
Definition at line 158 of file Segment.cpp.
PageId Segment::getLinearPageId | ( | BlockNum | iPage | ) | [inline, static, inherited] |
Constructs a linear PageId based on a linear page number.
Definition at line 348 of file Segment.h.
Referenced by allocateFromLockedExtentTemplate(), ScratchSegment::allocatePageId(), LinearViewSegment::allocatePageId(), LinearDeviceSegment::allocatePageId(), CircularSegment::allocatePageId(), getExtentAllocPageId(), VersionedRandomAllocationSegment::getOldPageIds(), getSegAllocPageId(), Database::init(), VersionedRandomAllocationSegment::locateDataPages(), SegmentTestBase::lockPage(), SegmentTestBase::prefetchPage(), SegPageIterTest::testBoundedIter(), SegPageEntryIterTest::testBoundedIter(), ScratchSegment::translateBlockId(), LinearViewSegment::translateBlockId(), LinearDeviceSegment::translateBlockId(), CircularSegment::translateBlockId(), and CircularSegment::translatePageId().
BlockNum Segment::getLinearBlockNum | ( | PageId | pageId | ) | [inline, static, inherited] |
Obtains the linear page number from a linear PageId.
Definition at line 353 of file Segment.h.
References opaqueToInt().
Referenced by CircularSegment::CircularSegment(), LinearDeviceSegment::deallocatePageRange(), CircularSegment::deallocatePageRange(), Segment::isLinearPageIdAllocated(), CircularSegment::isPageIdAllocated(), SegmentTestBase::lockPage(), SegInputStream::readPrevBuffer(), Segment::setLinearPageSuccessor(), splitPageId(), CircularSegment::translateBlockId(), ScratchSegment::translatePageId(), LinearViewSegment::translatePageId(), LinearDeviceSegment::translatePageId(), CircularSegment::translatePageId(), and LinearViewSegment::updatePage().
00354 { 00355 return opaqueToInt(pageId); 00356 }
MappedPageListener * Segment::getTracingListener | ( | ) | [virtual, inherited] |
Retrieves the tracing wrapper corresponding to this listener if tracing is turned on.
Otherwise, returns this listener itself.
Implements MappedPageListener.
Definition at line 65 of file Segment.cpp.
References Segment::getTracingSegment().
00066 { 00067 return getTracingSegment().get(); 00068 }
MappedPageListener * MappedPageListener::notifyAfterPageCheckpointFlush | ( | CachePage & | page | ) | [virtual, inherited] |
Receives notification that a page has been flushed during a checkpoint.
Also determines if the listener on the page needs to be reset.
Note that if the page listener is reset, that page may not be unmapped during a CHECKPOINT_FLUSH_AND_UNMAP checkpoint call.
This method should be called immediately after the page flush has completed while the checkpoint is still in progress.
page | the page that was flushed |
Reimplemented in SnapshotRandomAllocationSegment, and TracingSegment.
Definition at line 62 of file MappedPageListener.cpp.
bool ClosableObject::isClosed | ( | ) | const [inline, inherited] |
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 }
friend class SegmentFactory [friend] |
Definition at line 140 of file RandomAllocationSegmentBase.h.
The maximum number of pages occupied by this segment instance.
Definition at line 74 of file RandomAllocationSegmentBase.h.
Referenced by countAllocatedPages(), getNumPagesOccupiedHighWater(), incrementPageCounters(), incrementPagesOccupiedCounter(), RandomAllocationSegmentBase(), and tallySegAllocNodePages().
The number of data pages allocated for this segment.
Definition at line 79 of file RandomAllocationSegmentBase.h.
Referenced by decrementPageCounters(), getAllocatedSizeInPages(), incrementPageCounters(), RandomAllocationSegmentBase(), and tallySegAllocNodePages().
The net number of deallocations on this segment.
New page allocations that occur after a deallocation offset this count.
Definition at line 85 of file RandomAllocationSegmentBase.h.
Referenced by decrementPageCounters(), incrementPageCounters(), and RandomAllocationSegmentBase().
Mutex used to ensure that only one thread is incrementing the page counters.
Definition at line 91 of file RandomAllocationSegmentBase.h.
Referenced by countAllocatedPages(), decrementPageCounters(), incrementPageCounters(), and incrementPagesOccupiedCounter().
BlockNum RandomAllocationSegmentBase::nPagesPerExtent [protected] |
Number of pages in one extent, including the extent allocation node itself (so actual data capacity per extent is one less).
This is immutable.
Definition at line 147 of file RandomAllocationSegmentBase.h.
Referenced by VersionedRandomAllocationSegment::allocateAllocNodes(), allocateFromLockedExtentTemplate(), allocatePageIdFromSegment(), VersionedRandomAllocationSegment::backupAllocationNodes(), deallocatePageId(), format(), formatExtentTemplate(), formatPageExtentsTemplate(), VersionedRandomAllocationSegment::getOldPageIds(), VersionedRandomAllocationSegment::locateDataPages(), makePageNum(), RandomAllocationSegment::RandomAllocationSegment(), VersionedRandomAllocationSegment::restoreFromBackup(), splitPageId(), tallySegAllocNodePages(), VersionedRandomAllocationSegment::validateFreePageCount(), and VersionedRandomAllocationSegment::VersionedRandomAllocationSegment().
Number of pages mapped by one SegmentAllocationNode, including the SegmentAllocationNode itself.
This is immutable.
Definition at line 153 of file RandomAllocationSegmentBase.h.
Referenced by getSegAllocPageId(), inferSegAllocCount(), RandomAllocationSegment::RandomAllocationSegment(), splitPageId(), and VersionedRandomAllocationSegment::VersionedRandomAllocationSegment().
Number of extents mapped by a full SegmentAllocationNode.
This is immutable.
Definition at line 159 of file RandomAllocationSegmentBase.h.
Referenced by VersionedRandomAllocationSegment::allocateExtAllocNodes(), allocatePageIdFromSegment(), VersionedRandomAllocationSegment::backupAllocationNodes(), deallocatePageId(), VersionedRandomAllocationSegment::deallocateSinglePage(), format(), formatPageExtentsTemplate(), VersionedRandomAllocationSegment::getOldPageIds(), VersionedRandomAllocationSegment::locateDataPages(), makePageNum(), RandomAllocationSegment::RandomAllocationSegment(), RandomAllocationSegmentBase(), VersionedRandomAllocationSegment::restoreFromBackup(), splitPageId(), VersionedRandomAllocationSegment::updateExtentEntry(), VersionedRandomAllocationSegment::validateFreePageCount(), and VersionedRandomAllocationSegment::VersionedRandomAllocationSegment().
SharedCache Segment::pCache [protected, inherited] |
Cache managing pages of this segment.
Definition at line 62 of file Segment.h.
Referenced by VersionedRandomAllocationSegment::allocateAllocNodes(), allocateFromExtentTemplate(), allocateFromNewExtentTemplate(), allocatePageIdFromSegment(), VersionedRandomAllocationSegment::backupAllocationNodes(), VersionedRandomAllocationSegment::chainPageEntries(), VersionedRandomAllocationSegment::copyPageEntryFromTemp(), VersionedRandomAllocationSegment::copyPageEntryToTemp(), deallocatePageId(), VersionedRandomAllocationSegment::deallocateSinglePage(), VersionedRandomAllocationSegment::deferDeallocation(), VersionedSegment::delegatedCheckpoint(), SnapshotRandomAllocationSegment::delegatedCheckpoint(), Segment::delegatedCheckpoint(), format(), formatPageExtentsTemplate(), freePageEntryTemplate(), Segment::getCache(), Segment::getFullPageSize(), VersionedRandomAllocationSegment::getOldestTxnId(), VersionedRandomAllocationSegment::getOldPageIds(), getPageEntryCopyTemplate(), VersionedRandomAllocationSegment::getTempAllocNodePage(), VersionedRandomAllocationSegment::initPageEntry(), VersionedRandomAllocationSegment::locateDataPages(), VersionedSegment::notifyPageDirty(), VersionedSegment::recover(), VersionedRandomAllocationSegment::restoreFromBackup(), setPageSuccessorTemplate(), tallySegAllocNodePages(), VersionedRandomAllocationSegment::uncommittedDeallocation(), VersionedRandomAllocationSegment::updateExtentEntry(), VersionedRandomAllocationSegment::updatePageEntry(), VersionedRandomAllocationSegment::updateTempPageEntry(), and VersionedRandomAllocationSegment::validateFreePageCount().
WeakSegment Segment::pTracingSegment [protected, inherited] |
The tracing segment associated with this segment, if tracing is turned on.
A weak_ptr is used due to the circular shared pointers between this segment and its tracing segment.
Definition at line 69 of file Segment.h.
Referenced by Segment::checkpoint(), Segment::getTracingSegment(), and Segment::setTracingSegment().
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().