CircularSegment Class Reference

CircularSegment implements circular page allocation in terms of an underlying LINEAR_ALLOCATION segment. More...

#include <CircularSegment.h>

Inheritance diagram for CircularSegment:

DelegatingSegment Segment MappedPageListener ClosableObject List of all members.

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 ~CircularSegment ()
virtual BlockNum getAllocatedSizeInPages ()
 
Returns:
number of pages allocated from this segment

virtual BlockId translatePageId (PageId)
 Maps from a PageId in this segment to a BlockId.
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 void deallocatePageRange (PageId startPageId, PageId endPageId)
 Deallocates a range of pages allocated from this segment.
virtual bool isPageIdAllocated (PageId pageId)
 Tests whether a PageId is allocated.
virtual AllocationOrder getAllocationOrder () const
 
Returns:
the AllocationOrder for this segment

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.
SharedSegment const & getDelegateSegment () const
virtual BlockNum getNumPagesOccupiedHighWater ()
 Returns the max number of pages occupied by this segment instance.
virtual BlockNum getNumPagesExtended ()
 
Returns:
the number of incremental pages added to this instance of the segment

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
 
Returns:
the Cache for this Segment

uint getFullPageSize () const
 
Returns:
the full size of pages stored in this segment; this is the same as the size of underlying cache pages

uint getUsablePageSize () const
 
Returns:
the full size of pages stored in this segment minus the size for any footer information stored at the end of each page

virtual void initForUse ()
 Performs additional initialization required on the segment after it has been properly formatted.
SharedSegment getTracingSegment ()
 
Returns:
tracing segment associated with this segment if tracing is turned on; otherwise, returns the segment itself

void setTracingSegment (WeakSegment pTracingSegmentInit)
 Sets the tracing segment associated with this segment.
void checkpoint (CheckpointType checkpointType=CHECKPOINT_FLUSH_ALL)
 Checkpoints this segment.
virtual MappedPageListenergetMappedPageListener (BlockId blockId)
 Returns the mapped page listener corresponding to a page.
virtual bool isWriteVersioned ()
 
Returns:
true if the segment supports versioning

virtual MappedPageListenergetTracingListener ()
 Retrieves the tracing wrapper corresponding to this listener if tracing is turned on.
virtual MappedPageListenernotifyAfterPageCheckpointFlush (CachePage &page)
 Receives notification that a page has been flushed during a checkpoint.
bool isClosed () const
 
Returns:
whether the object has been closed

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

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

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

 CircularSegment (SharedSegment delegateSegment, SharedCheckpointProvider pCheckpointProvider, PageId oldestPageId, PageId newestPageId)

Private Attributes

SharedCheckpointProvider pCheckpointProvider
BlockNum oldestPageNum
BlockNum nextPageNum
BlockNum nPages
BlockNum checkpointThreshold1
BlockNum checkpointThreshold2

Friends

class SegmentFactory

Detailed Description

CircularSegment implements circular page allocation in terms of an underlying LINEAR_ALLOCATION segment.

See the design docs for more detail.

Deallocation of individual pages is not supported; however, the caller may deallocate runs of oldest pages by calling deallocatePageRange with NULL_PAGE_ID for startPageId; all pages up to and including the specified endPageId will be deallocated. This must be done periodically to prevent the allocation point from wrapping around to the oldest allocated page, or an assertion violation results.

Definition at line 46 of file CircularSegment.h.


Member Typedef Documentation

typedef std::hash_map<PageId,PageId> Segment::PageMap [protected, inherited]

Definition at line 56 of file Segment.h.

typedef PageMap::const_iterator Segment::PageMapConstIter [protected, inherited]

Definition at line 57 of file Segment.h.


Member Enumeration Documentation

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.

Enumerator:
RANDOM_ALLOCATION  Random order.
ASCENDING_ALLOCATION  Later calls always return greater PageIds, but not necessarily consecutively.
CONSECUTIVE_ALLOCATION  PageIds are returned in consecutive ascending order of BlockNum; the DeviceId is always the same.
LINEAR_ALLOCATION  PageIds are returned in consecutive ascending order starting with 0; all bytes of the PageId are used (no division into DeviceId/BlockNum), yielding maximum range.

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     };


Constructor & Destructor Documentation

CircularSegment::CircularSegment ( SharedSegment  delegateSegment,
SharedCheckpointProvider  pCheckpointProvider,
PageId  oldestPageId,
PageId  newestPageId 
) [explicit, private]

Definition at line 30 of file CircularSegment.cpp.

References checkpointThreshold1, checkpointThreshold2, DelegatingSegment::getAllocatedSizeInPages(), Segment::getLinearBlockNum(), Segment::LINEAR_ALLOCATION, nextPageNum, nPages, NULL_PAGE_ID, and oldestPageNum.

00035     : DelegatingSegment(pDelegateSegment),
00036       pCheckpointProvider(pCheckpointProviderInit)
00037 {
00038     assert(pDelegateSegment->getAllocationOrder() == LINEAR_ALLOCATION);
00039     nPages = DelegatingSegment::getAllocatedSizeInPages();
00040     if (oldestPageId == NULL_PAGE_ID) {
00041         assert(newestPageId == NULL_PAGE_ID);
00042         oldestPageNum = 0;
00043         nextPageNum = 0;
00044     } else {
00045         oldestPageNum = getLinearBlockNum(oldestPageId);
00046         if (newestPageId != NULL_PAGE_ID) {
00047             nextPageNum = getLinearBlockNum(newestPageId) + 1;
00048             assert(oldestPageNum < nextPageNum);
00049             assert((nextPageNum - oldestPageNum) <= nPages);
00050         } else {
00051             nextPageNum = oldestPageNum + nPages;
00052         }
00053     }
00054 
00055     // REVIEW:  parameterize this
00056     checkpointThreshold1 = nPages / 3;
00057     checkpointThreshold2 = 2*checkpointThreshold1;
00058 }

CircularSegment::~CircularSegment (  )  [virtual]

Definition at line 60 of file CircularSegment.cpp.

00061 {
00062 }


Member Function Documentation

BlockNum CircularSegment::getAllocatedSizeInPages (  )  [virtual]

Returns:
number of pages allocated from this segment

Reimplemented from DelegatingSegment.

Definition at line 64 of file CircularSegment.cpp.

References nextPageNum, and oldestPageNum.

Referenced by allocatePageId().

00065 {
00066     return (nextPageNum - oldestPageNum);
00067 }

BlockId CircularSegment::translatePageId ( PageId   )  [virtual]

Maps from a PageId in this segment to a BlockId.

Reimplemented from DelegatingSegment.

Definition at line 69 of file CircularSegment.cpp.

References Segment::getLinearBlockNum(), Segment::getLinearPageId(), isPageIdAllocated(), nPages, and DelegatingSegment::translatePageId().

00070 {
00071     assert(isPageIdAllocated(pageId));
00072     BlockNum pageNum = getLinearBlockNum(pageId);
00073     BlockNum blockNum = pageNum % nPages;
00074     return DelegatingSegment::translatePageId(
00075         Segment::getLinearPageId(blockNum));
00076 }

PageId CircularSegment::translateBlockId ( BlockId   )  [virtual]

Maps from a BlockId to a PageId in this segment.

Reimplemented from DelegatingSegment.

Definition at line 78 of file CircularSegment.cpp.

References Segment::getLinearBlockNum(), Segment::getLinearPageId(), nextPageNum, nPages, oldestPageNum, and DelegatingSegment::translateBlockId().

00079 {
00080     assert(nextPageNum > oldestPageNum);
00081     PageId pageId = DelegatingSegment::translateBlockId(blockId);
00082     BlockNum blockNum = getLinearBlockNum(pageId);
00083     BlockNum nBlocks = nPages;
00084     assert(blockNum < nBlocks);
00085     BlockNum oldestBlockNum = oldestPageNum % nBlocks;
00086     BlockNum nextBlockNum = nextPageNum % nBlocks;
00087     BlockNum pageNum;
00088     if (nextBlockNum > oldestBlockNum) {
00089         assert(blockNum >= oldestBlockNum);
00090         assert(blockNum < nextBlockNum);
00091         pageNum = nextPageNum - (nextBlockNum - blockNum);
00092     } else {
00093         if (blockNum < nextBlockNum) {
00094             pageNum = nextPageNum - (nextBlockNum - blockNum);
00095         } else {
00096             assert(blockNum >= oldestBlockNum);
00097             pageNum = oldestPageNum + (blockNum - oldestBlockNum);
00098         }
00099     }
00100     return Segment::getLinearPageId(pageNum);
00101 }

PageId CircularSegment::allocatePageId ( PageOwnerId  ownerId = ANON_PAGE_OWNER_ID  )  [virtual]

Allocates a page without locking it into memory.

Parameters:
ownerId the PageOwnerId of the object which will own this page, or ANON_PAGE_OWNER_ID for pages unassociated with an owner
Returns:
the PageId of the allocated page, or NULL_PAGE_ID if none could be allocated

Reimplemented from DelegatingSegment.

Definition at line 103 of file CircularSegment.cpp.

References CHECKPOINT_FLUSH_FUZZY, checkpointThreshold1, checkpointThreshold2, getAllocatedSizeInPages(), Segment::getLinearPageId(), isMAXU(), nextPageNum, nPages, NULL_PAGE_ID, and pCheckpointProvider.

00104 {
00105     uint nAllocated = getAllocatedSizeInPages();
00106 
00107     // all full
00108     if (nAllocated >= nPages) {
00109         return NULL_PAGE_ID;
00110     }
00111 
00112     if ((nAllocated == checkpointThreshold1)
00113         || (nAllocated == checkpointThreshold2))
00114     {
00115         // getting low, try a checkpoint
00116         if (pCheckpointProvider) {
00117             pCheckpointProvider->requestCheckpoint(CHECKPOINT_FLUSH_FUZZY);
00118         }
00119     }
00120 
00121     // This wraparound should never be hit in practice.  If it is, a
00122     // restart which truncates logs should fix it.
00123     assert(!isMAXU(nextPageNum + 1));
00124 
00125     PageId pageId = Segment::getLinearPageId(nextPageNum);
00126     ++nextPageNum;
00127     return pageId;
00128 }

void CircularSegment::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.

Parameters:
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.

Definition at line 130 of file CircularSegment.cpp.

References Segment::getLinearBlockNum(), isPageIdAllocated(), nextPageNum, NULL_PAGE_ID, and oldestPageNum.

00131 {
00132     assert(startPageId == NULL_PAGE_ID);
00133     if (endPageId == NULL_PAGE_ID) {
00134         oldestPageNum = nextPageNum;
00135     } else {
00136         assert(isPageIdAllocated(endPageId));
00137         BlockNum pageNum = getLinearBlockNum(endPageId);
00138         oldestPageNum = pageNum + 1;
00139     }
00140 }

bool CircularSegment::isPageIdAllocated ( PageId  pageId  )  [virtual]

Tests whether a PageId is allocated.

Parameters:
pageId the PageId of interest
Returns:
true iff the PageId is currently allocated in this segment

Reimplemented from DelegatingSegment.

Definition at line 142 of file CircularSegment.cpp.

References Segment::getLinearBlockNum(), nextPageNum, and oldestPageNum.

Referenced by deallocatePageRange(), and translatePageId().

00143 {
00144     BlockNum pageNum = getLinearBlockNum(pageId);
00145     return (pageNum >= oldestPageNum) && (pageNum < nextPageNum);
00146 }

Segment::AllocationOrder CircularSegment::getAllocationOrder (  )  const [virtual]

Returns:
the AllocationOrder for this segment

Reimplemented from DelegatingSegment.

Definition at line 148 of file CircularSegment.cpp.

References Segment::LINEAR_ALLOCATION.

00149 {
00150     return LINEAR_ALLOCATION;
00151 }

PageId CircularSegment::getPageSuccessor ( PageId  pageId  )  [virtual]

Determines the successor of a given PageId.

This is an optional interface only supported by segments with some concept of page ordering.

Parameters:
pageId PageId for which the successor is to be found
Returns:
successor PageId

Reimplemented from DelegatingSegment.

Definition at line 153 of file CircularSegment.cpp.

References Segment::getLinearPageSuccessor().

00154 {
00155     // Don't delegate this!
00156     return getLinearPageSuccessor(pageId);
00157 }

void CircularSegment::setPageSuccessor ( PageId  pageId,
PageId  successorId 
) [virtual]

Sets the successor of a given PageId.

This is an optional interface only supported by segments with some concept of modifiable ordering.

Parameters:
pageId PageId for which the successor is to be set
successorId PageId of successor

Reimplemented from DelegatingSegment.

Definition at line 159 of file CircularSegment.cpp.

References Segment::setLinearPageSuccessor().

00160 {
00161     // Don't delegate this!
00162     setLinearPageSuccessor(pageId,successorId);
00163 }

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::getNumPagesOccupiedHighWater (  )  [virtual, inherited]

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.

Returns:
the max number of pages occupied by a segment

Implements Segment.

Reimplemented in RandomAllocationSegmentBase.

Definition at line 52 of file DelegatingSegment.cpp.

References DelegatingSegment::pDelegateSegment.

00053 {
00054     return pDelegateSegment->getNumPagesOccupiedHighWater();
00055 }

BlockNum DelegatingSegment::getNumPagesExtended (  )  [virtual, inherited]

Returns:
the number of incremental pages added to this instance of the segment

Implements Segment.

Definition at line 57 of file DelegatingSegment.cpp.

References DelegatingSegment::pDelegateSegment.

00058 {
00059     return pDelegateSegment->getNumPagesExtended();
00060 }

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.

Parameters:
nPages lower bound for getAllocatedSizeInPages()
Returns:
true if enough pages could be allocated; false if not

Reimplemented from Segment.

Reimplemented in TracingSegment.

Definition at line 87 of file DelegatingSegment.cpp.

References DelegatingSegment::pDelegateSegment.

Referenced by RandomAllocationSegmentBase::allocatePageIdFromSegment(), TracingSegment::ensureAllocatedSize(), RandomAllocationSegmentBase::format(), and VersionedRandomAllocationSegment::restoreFromBackup().

00088 {
00089     return pDelegateSegment->ensureAllocatedSize(nPages);
00090 }

void DelegatingSegment::delegatedCheckpoint ( Segment delegatingSegment,
CheckpointType  checkpointType 
) [virtual, inherited]

Helper for DelegatingSegment.

Parameters:
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.

Parameters:
pageId pageId of the page being modified
needsTranslation true if the pageId needs to be mapped to the appropriate update page; defaults to false
Returns:
NULL_PAGE_ID if the page can be updated in place; otherwise, the pageId of the page that should be used when updates are made to the page

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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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 }

PBuffer Segment::getWritableFooter ( CachePage page  )  [protected, inherited]

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 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 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]

Returns:
the Cache for this Segment

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]

Returns:
the full size of pages stored in this segment; this is the same as the size of underlying cache pages

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]

Returns:
the full size of pages stored in this segment minus the size for any footer information stored at the end of each page

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::RandomAllocationSegmentBase(), SegPageLock::swapBuffers(), VersionedRandomAllocationSegment::VersionedRandomAllocationSegment(), and VersionedSegment::VersionedSegment().

00364 {
00365     return cbUsablePerPage;
00366 }

void Segment::initForUse (  )  [virtual, inherited]

Performs additional initialization required on the segment after it has been properly formatted.

Reimplemented in RandomAllocationSegmentBase, and VersionedRandomAllocationSegment.

Definition at line 163 of file Segment.cpp.

00164 {
00165 }

SharedSegment Segment::getTracingSegment (  )  [inherited]

Returns:
tracing segment associated with this segment if tracing is turned on; otherwise, returns the segment itself

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(), RandomAllocationSegmentBase::deallocatePageId(), VersionedRandomAllocationSegment::findAllocPageIdForRead(), RandomAllocationSegmentBase::format(), RandomAllocationSegmentBase::formatPageExtentsTemplate(), RandomAllocationSegmentBase::freePageEntryTemplate(), RandomAllocationSegment::getExtAllocPageIdForRead(), VersionedRandomAllocationSegment::getOldestTxnId(), VersionedRandomAllocationSegment::getOldPageIds(), RandomAllocationSegmentBase::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.

Parameters:
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.

Parameters:
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.

Parameters:
blockId blockId of the page whose page listener we are returning
Returns:
segment corresponding to mapped page listener

Reimplemented in DynamicDelegatingSegment, SnapshotRandomAllocationSegment, and TracingSegment.

Definition at line 153 of file Segment.cpp.

00154 {
00155     return this;
00156 }

bool Segment::isWriteVersioned (  )  [virtual, inherited]

Returns:
true if the segment supports versioning

Reimplemented in DynamicDelegatingSegment, SnapshotRandomAllocationSegment, and TracingSegment.

Definition at line 158 of file Segment.cpp.

00159 {
00160     return false;
00161 }

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 RandomAllocationSegmentBase::allocateFromLockedExtentTemplate(), ScratchSegment::allocatePageId(), LinearViewSegment::allocatePageId(), LinearDeviceSegment::allocatePageId(), allocatePageId(), RandomAllocationSegmentBase::getExtentAllocPageId(), VersionedRandomAllocationSegment::getOldPageIds(), RandomAllocationSegmentBase::getSegAllocPageId(), Database::init(), VersionedRandomAllocationSegment::locateDataPages(), SegmentTestBase::lockPage(), SegmentTestBase::prefetchPage(), SegPageIterTest::testBoundedIter(), SegPageEntryIterTest::testBoundedIter(), ScratchSegment::translateBlockId(), LinearViewSegment::translateBlockId(), LinearDeviceSegment::translateBlockId(), translateBlockId(), and translatePageId().

00349 {
00350     return PageId(iPage);
00351 }

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(), LinearDeviceSegment::deallocatePageRange(), deallocatePageRange(), Segment::isLinearPageIdAllocated(), isPageIdAllocated(), SegmentTestBase::lockPage(), SegInputStream::readPrevBuffer(), Segment::setLinearPageSuccessor(), RandomAllocationSegmentBase::splitPageId(), translateBlockId(), ScratchSegment::translatePageId(), LinearViewSegment::translatePageId(), LinearDeviceSegment::translatePageId(), 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.

Returns:
tracing segment corresponding to a listener

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.

Parameters:
page the page that was flushed
Returns:
NULL if the listener on the page does not need to be reset; otherwise, returns the listener that the page should be reset to

Reimplemented in SnapshotRandomAllocationSegment, and TracingSegment.

Definition at line 62 of file MappedPageListener.cpp.

00064 {
00065     return NULL;
00066 }

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

Returns:
whether the object has been closed

Definition at line 58 of file ClosableObject.h.

00059     {
00060         return !needsClose;
00061     }

void ClosableObject::close (  )  [inherited]

Closes this object, releasing any unallocated resources.

Reimplemented in CollectExecStream, CorrelationJoinExecStream, LcsClusterAppendExecStream, and LcsClusterReplaceExecStream.

Definition at line 39 of file ClosableObject.cpp.

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

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

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


Friends And Related Function Documentation

friend class SegmentFactory [friend]

Definition at line 49 of file CircularSegment.h.


Member Data Documentation

SharedCheckpointProvider CircularSegment::pCheckpointProvider [private]

Definition at line 51 of file CircularSegment.h.

Referenced by allocatePageId().

BlockNum CircularSegment::oldestPageNum [private]

Definition at line 53 of file CircularSegment.h.

Referenced by CircularSegment(), deallocatePageRange(), getAllocatedSizeInPages(), isPageIdAllocated(), and translateBlockId().

BlockNum CircularSegment::nextPageNum [private]

Definition at line 56 of file CircularSegment.h.

Referenced by allocatePageId(), CircularSegment(), deallocatePageRange(), getAllocatedSizeInPages(), isPageIdAllocated(), and translateBlockId().

BlockNum CircularSegment::nPages [private]

Definition at line 58 of file CircularSegment.h.

Referenced by allocatePageId(), CircularSegment(), translateBlockId(), and translatePageId().

BlockNum CircularSegment::checkpointThreshold1 [private]

Definition at line 60 of file CircularSegment.h.

Referenced by allocatePageId(), and CircularSegment().

BlockNum CircularSegment::checkpointThreshold2 [private]

Definition at line 60 of file CircularSegment.h.

Referenced by allocatePageId(), and CircularSegment().

SharedCache Segment::pCache [protected, inherited]

Cache managing pages of this segment.

Definition at line 62 of file Segment.h.

Referenced by VersionedRandomAllocationSegment::allocateAllocNodes(), RandomAllocationSegmentBase::allocateFromExtentTemplate(), RandomAllocationSegmentBase::allocateFromNewExtentTemplate(), RandomAllocationSegmentBase::allocatePageIdFromSegment(), VersionedRandomAllocationSegment::backupAllocationNodes(), VersionedRandomAllocationSegment::chainPageEntries(), VersionedRandomAllocationSegment::copyPageEntryFromTemp(), VersionedRandomAllocationSegment::copyPageEntryToTemp(), RandomAllocationSegmentBase::deallocatePageId(), VersionedRandomAllocationSegment::deallocateSinglePage(), VersionedRandomAllocationSegment::deferDeallocation(), VersionedSegment::delegatedCheckpoint(), SnapshotRandomAllocationSegment::delegatedCheckpoint(), Segment::delegatedCheckpoint(), RandomAllocationSegmentBase::format(), RandomAllocationSegmentBase::formatPageExtentsTemplate(), RandomAllocationSegmentBase::freePageEntryTemplate(), Segment::getCache(), Segment::getFullPageSize(), VersionedRandomAllocationSegment::getOldestTxnId(), VersionedRandomAllocationSegment::getOldPageIds(), RandomAllocationSegmentBase::getPageEntryCopyTemplate(), VersionedRandomAllocationSegment::getTempAllocNodePage(), VersionedRandomAllocationSegment::initPageEntry(), VersionedRandomAllocationSegment::locateDataPages(), VersionedSegment::notifyPageDirty(), VersionedSegment::recover(), VersionedRandomAllocationSegment::restoreFromBackup(), RandomAllocationSegmentBase::setPageSuccessorTemplate(), RandomAllocationSegmentBase::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().


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