ScratchSegment Class Reference

ScratchSegment is an implementation of Segment which allocates scratch pages from the cache. More...

#include <ScratchSegment.h>

Inheritance diagram for ScratchSegment:

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

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 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 AllocationOrder getAllocationOrder () const
 
Returns:
the AllocationOrder for this segment

virtual CachePagelockPage (BlockId blockId, LockMode lockMode, bool readIfUnmapped=true, MappedPageListener *pMappedPageListener=NULL, TxnId txnId=IMPLICIT_TXN_ID)
 Locks a page into memory with the specified concurrency mode.
virtual void unlockPage (CachePage &page, LockMode lockMode, TxnId txnId=IMPLICIT_TXN_ID)
 Releases lock held on page.
virtual void discardPage (BlockId blockId)
 Unmaps a page from the cache if already mapped, discarding its contents if dirty.
virtual bool prefetchPage (BlockId blockId, MappedPageListener *pMappedPageListener=NULL)
 Hints that a page should be prefetched in preparation for a future lock request.
virtual void prefetchBatch (BlockId blockId, uint nPages, MappedPageListener *pMappedPageListener=NULL)
 Hints that a contiguous run of pages should be prefetched.
virtual void flushPage (CachePage &page, bool async)
 Forces the contents of a dirty page to its mapped location.
virtual void nicePage (CachePage &page)
 Marks a page as nice, indicating that it is very unlikely the page's mapping will be needed again any time soon, so it is a good candidate for victimization.
virtual SharedCache getCache ()
 
Returns:
the underlying Cache accessed by this CacheAccessor

virtual uint getMaxLockedPages ()
 
Returns:
the page lock quota on this accessor

virtual void setMaxLockedPages (uint nPages)
 Sets the page lock quota on this accessor.
virtual void setTxnId (TxnId txnId)
 Sets a default TxnId to use for locking pages (to be used when IMPLICIT_TXN_ID is specified).
virtual TxnId getTxnId () const
 
Returns:
default TxnId associated with this accessor

virtual void getPrefetchParams (uint &nPagesPerBatch, uint &nBatchPrefetches)
 Retrieves the current pre-fetch caching parameters that determine how many pages should be pre-fetched and how often the pre-fetches should occur.
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 void delegatedCheckpoint (Segment &delegatingSegment, CheckpointType checkpointType)
 Helper for DelegatingSegment.
virtual bool ensureAllocatedSize (BlockNum nPages)
 Allocates pages as needed to make getAllocatedSizeInPages() meet a lower bound.
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 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 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 bool canFlushPage (CachePage &page)
 Informs CacheImpl whether a dirty page can safely be flushed to disk.
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 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 Types

typedef std::vector< CachePage * > PageList
typedef PageList::iterator PageListIter

Private Member Functions

 ScratchSegment (SharedCache pCache, uint nPagesMax)
virtual void closeImpl ()
 Must be implemented by derived class to release any resources.
void clearPages ()

Private Attributes

BlockNum nPagesMax
 Limit on number of pages allocated, or MAXU for unlimited.
PageList pages
 Scratch pages allocated so far.
StrictMutex mutex
 Mutex protecting page list.

Friends

class SegmentFactory

Detailed Description

ScratchSegment is an implementation of Segment which allocates scratch pages from the cache.

See the design docs for more detail.

Definition at line 40 of file ScratchSegment.h.


Member Typedef Documentation

typedef std::vector<CachePage *> ScratchSegment::PageList [private]

Definition at line 45 of file ScratchSegment.h.

typedef PageList::iterator ScratchSegment::PageListIter [private]

Definition at line 46 of file ScratchSegment.h.

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

ScratchSegment::ScratchSegment ( SharedCache  pCache,
uint  nPagesMax 
) [explicit, private]

Definition at line 32 of file ScratchSegment.cpp.

References nPagesMax.

00035     : Segment(pCache)
00036 {
00037     nPagesMax = nPagesMaxInit;
00038 }


Member Function Documentation

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

Must be implemented by derived class to release any resources.

Reimplemented from Segment.

Definition at line 40 of file ScratchSegment.cpp.

References clearPages().

00041 {
00042     // this overrides Segment::closeImpl; we know exactly which pages to
00043     // discard, so we can skip the full-cache sweep
00044     clearPages();
00045 }

void ScratchSegment::clearPages (  )  [private]

Definition at line 47 of file ScratchSegment.cpp.

References getCache(), LOCKMODE_X, and pages.

Referenced by closeImpl(), and deallocatePageRange().

00048 {
00049     // TODO:  separate unlockScratchPage method in Cache
00050 
00051     for (PageListIter ppPage = pages.begin(); ppPage != pages.end(); ++ppPage) {
00052         CachePage &page = **ppPage;
00053         getCache()->unlockPage(page,LOCKMODE_X);
00054     }
00055     pages.clear();
00056 }

BlockId ScratchSegment::translatePageId ( PageId   )  [virtual]

Maps from a PageId in this segment to a BlockId.

Implements Segment.

Definition at line 58 of file ScratchSegment.cpp.

References Segment::getLinearBlockNum(), isPageIdAllocated(), Cache::NULL_DEVICE_ID, CompoundId::setBlockNum(), and CompoundId::setDeviceId().

00059 {
00060     assert(isPageIdAllocated(pageId));
00061     BlockId blockId(0);
00062     CompoundId::setDeviceId(blockId,Cache::NULL_DEVICE_ID);
00063     CompoundId::setBlockNum(
00064         blockId,
00065         getLinearBlockNum(pageId));
00066     return blockId;
00067 }

PageId ScratchSegment::translateBlockId ( BlockId   )  [virtual]

Maps from a BlockId to a PageId in this segment.

Implements Segment.

Definition at line 69 of file ScratchSegment.cpp.

References CompoundId::getBlockNum(), and Segment::getLinearPageId().

00070 {
00071     return getLinearPageId(CompoundId::getBlockNum(blockId));
00072 }

PageId ScratchSegment::allocatePageId ( PageOwnerId  ownerId  )  [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

Implements Segment.

Definition at line 89 of file ScratchSegment.cpp.

References getAllocatedSizeInPages(), getCache(), Segment::getLinearPageId(), mutex, nPagesMax, NULL_PAGE_ID, and pages.

00090 {
00091     StrictMutexGuard mutexGuard(mutex);
00092 
00093     // nothing to do with PageOwnerId
00094 
00095     if (getAllocatedSizeInPages() >= nPagesMax) {
00096         return NULL_PAGE_ID;
00097     }
00098 
00099     BlockNum blockNum = pages.size();
00100     CachePage &page = getCache()->lockScratchPage(blockNum);
00101     pages.push_back(&page);
00102     return getLinearPageId(blockNum);
00103 }

void ScratchSegment::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

Implements Segment.

Definition at line 105 of file ScratchSegment.cpp.

References clearPages(), mutex, and NULL_PAGE_ID.

00106 {
00107     assert(startPageId == NULL_PAGE_ID);
00108     assert(endPageId == NULL_PAGE_ID);
00109 
00110     StrictMutexGuard mutexGuard(mutex);
00111     clearPages();
00112 }

bool ScratchSegment::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

Implements Segment.

Definition at line 114 of file ScratchSegment.cpp.

References Segment::isLinearPageIdAllocated().

Referenced by translatePageId().

00115 {
00116     return isLinearPageIdAllocated(pageId);
00117 }

BlockNum ScratchSegment::getAllocatedSizeInPages (  )  [virtual]

Returns:
number of pages allocated from this segment

Implements Segment.

Definition at line 74 of file ScratchSegment.cpp.

References pages.

Referenced by allocatePageId(), and getNumPagesOccupiedHighWater().

00075 {
00076     return pages.size();
00077 }

BlockNum ScratchSegment::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.

Returns:
the max number of pages occupied by a segment

Implements Segment.

Definition at line 79 of file ScratchSegment.cpp.

References getAllocatedSizeInPages().

00080 {
00081     return getAllocatedSizeInPages();
00082 }

BlockNum ScratchSegment::getNumPagesExtended (  )  [virtual]

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

Implements Segment.

Definition at line 84 of file ScratchSegment.cpp.

00085 {
00086     return BlockNum(0);
00087 }

PageId ScratchSegment::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

Implements Segment.

Definition at line 119 of file ScratchSegment.cpp.

References Segment::getLinearPageSuccessor().

00120 {
00121     return getLinearPageSuccessor(pageId);
00122 }

void ScratchSegment::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

Implements Segment.

Definition at line 124 of file ScratchSegment.cpp.

References Segment::setLinearPageSuccessor().

00125 {
00126     setLinearPageSuccessor(pageId,successorId);
00127 }

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

Returns:
the AllocationOrder for this segment

Implements Segment.

Definition at line 129 of file ScratchSegment.cpp.

References Segment::LINEAR_ALLOCATION.

00130 {
00131     return LINEAR_ALLOCATION;
00132 }

CachePage * ScratchSegment::lockPage ( BlockId  blockId,
LockMode  lockMode,
bool  readIfUnmapped = true,
MappedPageListener pMappedPageListener = NULL,
TxnId  txnId = IMPLICIT_TXN_ID 
) [virtual]

Locks a page into memory with the specified concurrency mode.

When the page contents are no longer needed, the caller must invoke the unlockPage() method with the same concurrency mode to release it. If the desired page is already locked by another thread with an incompatible concurrency mode, blocks until the page becomes available (unless the lock mode is of the NoWait variety, in which case returns NULL immediately). Note that NoWait locking only applies to lock contention, not I/O, so if an unmapped page is locked in NoWait mode, blocks until the read completes.

The device referenced by the requested blockId must already be registered with the cache and must remain registered for the duration of the lock.

Notes on concurrency modes:

Parameters:
blockId the BlockId of the page to be locked
lockMode the desired concurrency mode
readIfUnmapped if true (the default) the page data is read as part of mapping; if false, the page data is left invalid until first write (used when allocating a new block with invalid contents)
pMappedPageListener optional listener to receive notifications when this page is written; if specified, it must match all prior and subsequent lock requests for the same page mapping
txnId optional TxnId to associate with lock; default is IMPLICIT_TXN_ID, which uses current thread ID as an implicit TxnId
Returns:
the locked CachePage, or NULL if a NoWait attempt failed

Implements CacheAccessor.

Definition at line 134 of file ScratchSegment.cpp.

References CompoundId::getBlockNum(), CompoundId::getDeviceId(), mutex, Cache::NULL_DEVICE_ID, and pages.

00140 {
00141     StrictMutexGuard mutexGuard(mutex);
00142 
00143     assert(CompoundId::getDeviceId(blockId) == Cache::NULL_DEVICE_ID);
00144     BlockNum blockNum = CompoundId::getBlockNum(blockId);
00145     assert(blockNum < pages.size());
00146     // TODO:  should assert(pMappedPageListener == this), but that doesn't work
00147     // when tracing is enabled
00148     return pages[blockNum];
00149 }

void ScratchSegment::unlockPage ( CachePage page,
LockMode  lockMode,
TxnId  txnId = IMPLICIT_TXN_ID 
) [virtual]

Releases lock held on page.

Parameters:
page the page to be unlocked
lockMode must correspond to value passed to Cache::lockPage; however, for pages locked with NOWAIT, the equivalent unlock type should be normal (e.g. LOCKMODE_S instead of LOCKMODE_S_NOWAIT)
txnId must correspond to value passed to Cache::lockPage

Implements CacheAccessor.

Definition at line 151 of file ScratchSegment.cpp.

00155 {
00156     // ignore; pages remain locked until segment is closed
00157 }

void ScratchSegment::discardPage ( BlockId  blockId  )  [virtual]

Unmaps a page from the cache if already mapped, discarding its contents if dirty.

The caller must ensure that no other thread has the page locked.

Parameters:
blockId the BlockId of the page to be discarded

Implements CacheAccessor.

Definition at line 161 of file ScratchSegment.cpp.

00163 {
00164 }

bool ScratchSegment::prefetchPage ( BlockId  blockId,
MappedPageListener pMappedPageListener = NULL 
) [virtual]

Hints that a page should be prefetched in preparation for a future lock request.

Parameters:
blockId the BlockId of the page to be prefetched
pMappedPageListener optional listener to receive notifications when this page is written; if specified, it must match all prior and subsequent lock requests for the same page mapping
Returns:
true if the pre-fetch request was successful

Implements CacheAccessor.

Definition at line 166 of file ScratchSegment.cpp.

00169 {
00170     return false;
00171 }

void ScratchSegment::prefetchBatch ( BlockId  blockId,
uint  nPages,
MappedPageListener pMappedPageListener = NULL 
) [virtual]

Hints that a contiguous run of pages should be prefetched.

Parameters:
blockId the BlockId of the first page to be prefetched; more will be prefetched depending on the configured batch size
nPages number of pages in batch
pMappedPageListener optional listener to receive notifications when this page is written; if specified, it must match all prior and subsequent lock requests for the same page mapping

Implements CacheAccessor.

Definition at line 173 of file ScratchSegment.cpp.

00176 {
00177 }

void ScratchSegment::flushPage ( CachePage page,
bool  async 
) [virtual]

Forces the contents of a dirty page to its mapped location.

Page must already be locked in exclusive mode. For an asynchronous flush, the caller must ensure that the page contents remain unchanged until the flush completes.

Parameters:
page the page to be flushed
async true to schedle async write and return immediately; false to wait for write to complete

Implements CacheAccessor.

Definition at line 179 of file ScratchSegment.cpp.

00180 {
00181 }

void ScratchSegment::nicePage ( CachePage page  )  [virtual]

Marks a page as nice, indicating that it is very unlikely the page's mapping will be needed again any time soon, so it is a good candidate for victimization.

Parameters:
page the page to be marked

Implements CacheAccessor.

Definition at line 183 of file ScratchSegment.cpp.

00184 {
00185     // ignore
00186 }

SharedCache ScratchSegment::getCache (  )  [virtual]

Returns:
the underlying Cache accessed by this CacheAccessor

Implements CacheAccessor.

Definition at line 188 of file ScratchSegment.cpp.

References Segment::getCache().

Referenced by allocatePageId(), clearPages(), and getMaxLockedPages().

00189 {
00190     return Segment::getCache();
00191 }

uint ScratchSegment::getMaxLockedPages (  )  [virtual]

Returns:
the page lock quota on this accessor

Implements CacheAccessor.

Definition at line 193 of file ScratchSegment.cpp.

References getCache(), isMAXU(), and nPagesMax.

00194 {
00195     if (isMAXU(nPagesMax)) {
00196         return getCache()->getMaxLockedPages();
00197     } else {
00198         return nPagesMax;
00199     }
00200 }

void ScratchSegment::setMaxLockedPages ( uint  nPages  )  [virtual]

Sets the page lock quota on this accessor.

Ignored for accessor implementations that don't support quotas.

Parameters:
nPages new quota

Implements CacheAccessor.

Definition at line 202 of file ScratchSegment.cpp.

References mutex, nPagesMax, and pages.

00203 {
00204     StrictMutexGuard mutexGuard(mutex);
00205     assert(nPages >= pages.size());
00206     nPagesMax = nPages;
00207 }

void ScratchSegment::setTxnId ( TxnId  txnId  )  [virtual]

Sets a default TxnId to use for locking pages (to be used when IMPLICIT_TXN_ID is specified).

Not all CacheAccessor implementations support this behavior.

Parameters:
txnId new default txn ID

Implements CacheAccessor.

Definition at line 209 of file ScratchSegment.cpp.

00210 {
00211 }

TxnId ScratchSegment::getTxnId (  )  const [virtual]

Returns:
default TxnId associated with this accessor

Implements CacheAccessor.

Definition at line 213 of file ScratchSegment.cpp.

References IMPLICIT_TXN_ID.

00214 {
00215     return IMPLICIT_TXN_ID;
00216 }

void ScratchSegment::getPrefetchParams ( uint nPagesPerBatch,
uint nBatchPrefetches 
) [virtual]

Retrieves the current pre-fetch caching parameters that determine how many pages should be pre-fetched and how often the pre-fetches should occur.

Parameters:
[out] prefetchPagesMax max number of outstanding pre-fetch pages
[out] prefetchThrottleRate the number of successful pre-fetches that have to occur before the pre-fetch rate is throttled back up, in the event that it has been throttled down due to rejected requests

Implements CacheAccessor.

Definition at line 218 of file ScratchSegment.cpp.

00221 {
00222 }

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

void Segment::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 in DelegatingSegment, DynamicDelegatingSegment, LinearDeviceSegment, SnapshotRandomAllocationSegment, TracingSegment, and VersionedSegment.

Definition at line 125 of file Segment.cpp.

References Segment::pCache.

Referenced by Segment::checkpoint(), and LinearDeviceSegment::delegatedCheckpoint().

00128 {
00129     MappedPageListenerPredicate pagePredicate(delegatingSegment);
00130     pCache->checkpointPages(pagePredicate,checkpointType);
00131 }

bool Segment::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 in DelegatingSegment, DynamicDelegatingSegment, LinearDeviceSegment, and TracingSegment.

Definition at line 138 of file Segment.cpp.

References Segment::allocatePageId(), Segment::getAllocatedSizeInPages(), and NULL_PAGE_ID.

00139 {
00140     while (getAllocatedSizeInPages() < nPages) {
00141         if (allocatePageId() == NULL_PAGE_ID) {
00142             return false;
00143         }
00144     }
00145     return true;
00146 }

PageId Segment::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 in DelegatingSegment, DynamicDelegatingSegment, LinearViewSegment, and SnapshotRandomAllocationSegment.

Definition at line 148 of file Segment.cpp.

References NULL_PAGE_ID.

00149 {
00150     return NULL_PAGE_ID;
00151 }

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(), allocatePageId(), LinearViewSegment::allocatePageId(), LinearDeviceSegment::allocatePageId(), CircularSegment::allocatePageId(), RandomAllocationSegmentBase::getExtentAllocPageId(), VersionedRandomAllocationSegment::getOldPageIds(), RandomAllocationSegmentBase::getSegAllocPageId(), Database::init(), VersionedRandomAllocationSegment::locateDataPages(), SegmentTestBase::lockPage(), SegmentTestBase::prefetchPage(), SegPageIterTest::testBoundedIter(), SegPageEntryIterTest::testBoundedIter(), translateBlockId(), LinearViewSegment::translateBlockId(), LinearDeviceSegment::translateBlockId(), CircularSegment::translateBlockId(), and CircularSegment::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::CircularSegment(), LinearDeviceSegment::deallocatePageRange(), CircularSegment::deallocatePageRange(), Segment::isLinearPageIdAllocated(), CircularSegment::isPageIdAllocated(), SegmentTestBase::lockPage(), SegInputStream::readPrevBuffer(), Segment::setLinearPageSuccessor(), RandomAllocationSegmentBase::splitPageId(), CircularSegment::translateBlockId(), 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.

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 }

void MappedPageListener::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 in DelegatingSegment, DynamicDelegatingSegment, and TracingSegment.

Definition at line 29 of file MappedPageListener.cpp.

Referenced by CacheImpl< PageT, VictimPolicyT >::mapPage().

00030 {
00031 }

void MappedPageListener::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 in DelegatingSegment, DynamicDelegatingSegment, TracingSegment, and WALSegment.

Definition at line 33 of file MappedPageListener.cpp.

00034 {
00035 }

void MappedPageListener::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 in DelegatingSegment, DynamicDelegatingSegment, and TracingSegment.

Definition at line 37 of file MappedPageListener.cpp.

Referenced by CacheImpl< PageT, VictimPolicyT >::notifyTransferCompletion().

00038 {
00039 }

void MappedPageListener::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 in DelegatingSegment, DynamicDelegatingSegment, SnapshotRandomAllocationSegment, TracingSegment, VersionedSegment, and WALSegment.

Definition at line 41 of file MappedPageListener.cpp.

00042 {
00043 }

bool MappedPageListener::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 in DelegatingSegment, DynamicDelegatingSegment, SnapshotRandomAllocationSegment, and VersionedSegment.

Definition at line 53 of file MappedPageListener.cpp.

Referenced by CacheImpl< PageT, VictimPolicyT >::flushPage().

00054 {
00055     return true;
00056 }

void MappedPageListener::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 in DelegatingSegment, DynamicDelegatingSegment, and TracingSegment.

Definition at line 45 of file MappedPageListener.cpp.

00046 {
00047 }

void MappedPageListener::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 in DelegatingSegment, DynamicDelegatingSegment, TracingSegment, and WALSegment.

Definition at line 49 of file MappedPageListener.cpp.

Referenced by CacheImpl< PageT, VictimPolicyT >::notifyTransferCompletion().

00050 {
00051 }

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 43 of file ScratchSegment.h.


Member Data Documentation

BlockNum ScratchSegment::nPagesMax [private]

Limit on number of pages allocated, or MAXU for unlimited.

Definition at line 51 of file ScratchSegment.h.

Referenced by allocatePageId(), getMaxLockedPages(), ScratchSegment(), and setMaxLockedPages().

PageList ScratchSegment::pages [private]

Scratch pages allocated so far.

Definition at line 56 of file ScratchSegment.h.

Referenced by allocatePageId(), clearPages(), getAllocatedSizeInPages(), lockPage(), and setMaxLockedPages().

StrictMutex ScratchSegment::mutex [private]

Mutex protecting page list.

Definition at line 61 of file ScratchSegment.h.

Referenced by allocatePageId(), deallocatePageRange(), lockPage(), and setMaxLockedPages().

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:45 2009 for Fennel by  doxygen 1.5.1