SnapshotRandomAllocationSegment Class Reference

SnapshotRandomAllocationSegment implements a random allocation segment that provides a consistent view of the data in the segment based on a specified point in time. More...

#include <SnapshotRandomAllocationSegment.h>

Inheritance diagram for SnapshotRandomAllocationSegment:

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

 SnapshotRandomAllocationSegment (SharedSegment delegateSegment, SharedSegment versionedSegment, TxnId snapshotCsnInit, bool readOnlyCommittedData)
TxnId getSnapshotCsn ()
 
Returns:
the csn associated with the snapshot segment

void commitChanges (TxnId commitCsn)
 Commits page entry changes.
void rollbackChanges ()
 Rolls back page entry changes.
void versionPage (PageId destAnchorPageId, PageId srcAnchorPageId)
 Adds a source page chain into a destination page chain.
void setForceCacheUnmap ()
 Indicates that a checkpoint should be always be executed, even if no pages are dirty when flushing and unmapping cache entries.
virtual BlockId translatePageId (PageId pageId)
 Maps from a PageId in this segment to a BlockId.
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 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 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 void delegatedCheckpoint (Segment &delegatingSegment, CheckpointType checkpointType)
 Helper for DelegatingSegment.
virtual MappedPageListenernotifyAfterPageCheckpointFlush (CachePage &page)
 Receives notification that a page has been flushed during a checkpoint.
virtual bool canFlushPage (CachePage &page)
 Informs CacheImpl whether a dirty page can safely be flushed to disk.
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 isWriteVersioned ()
 
Returns:
true if the segment supports versioning

SharedSegment const & getDelegateSegment () const
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 translateBlockId (BlockId)
 Maps from a BlockId to a PageId in this segment.
virtual bool ensureAllocatedSize (BlockNum nPages)
 Allocates pages as needed to make getAllocatedSizeInPages() meet a lower bound.
virtual bool isPageIdAllocated (PageId pageId)
 Tests whether a PageId is allocated.
virtual AllocationOrder getAllocationOrder () const
 
Returns:
the AllocationOrder for this segment

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 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.
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 MappedPageListenergetTracingListener ()
 Retrieves the tracing wrapper corresponding to this listener if tracing is turned on.
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

PageId getSnapshotId (PageId pageId)
 Retrieves the pageId corresponding to this segment's snapshot of a specified page.
void incrPageUpdateCount (PageId pageId, PageOwnerId ownerId, ModifiedPageEntry::ModType modType)
 Increments the counters that keep track of the number of modifications made to a page entry as well as allocations/deallocations.
PageId getAnchorPageId (PageId snapshotId)
 Retrieves the pageId of the anchor page corresponding to a snapshot page.
bool isPageNewlyAllocated (PageId pageId)
 Determines whether a snapshot page corresponds to a newly allocated one.
void chainPageEntries (PageId pageId, PageId versionChainId, PageId successorId)
 Chains one page to another.

Private Attributes

ModifiedPageEntryMap modPageEntriesMap
 Keeps track of the number of modifications made to the page entry and extent entry corresponding to a page.
PageMap snapshotPageMap
 Maintains a mapping between a pageId and the snapshot page for this segment.
SXMutex modPageMapMutex
 Mutex that ensures only a single thread is modifying modPageEntriesMap.
StrictMutex snapshotPageMapMutex
 Mutex protecting the snapshotPageMap.
VersionedRandomAllocationSegmentpVersionedRandomSegment
 Underlying segment that provides versioning of pages.
TxnId snapshotCsn
 The commit sequence number used to determine which pages to read.
bool readOnlyCommittedData
 True if only committed data should be read by the segment.
bool needPageFlush
 If true, some snapshot page has been modified and therefore pages need to be flushed during a checkpoint call.
bool forceCacheUnmap
 If true, always issue the checkpoint to remove entries from the cache when flushing and unmapping cache entries.

Detailed Description

SnapshotRandomAllocationSegment implements a random allocation segment that provides a consistent view of the data in the segment based on a specified point in time.

All pages read are as of that specified point in time. If a page is updated, and this is the first time the page is being updated, a new copy of the page is created and used for the remaining lifetime of the segment.

This segment delegates much of its work to its underlying VersionedRandomAllocationSegment. That segment is responsible for the actual underlying data storage.

Definition at line 48 of file SnapshotRandomAllocationSegment.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

SnapshotRandomAllocationSegment::SnapshotRandomAllocationSegment ( SharedSegment  delegateSegment,
SharedSegment  versionedSegment,
TxnId  snapshotCsnInit,
bool  readOnlyCommittedData 
) [explicit]

Definition at line 32 of file SnapshotRandomAllocationSegment.cpp.

References forceCacheUnmap, needPageFlush, pVersionedRandomSegment, readOnlyCommittedData, and snapshotCsn.

00037     : DelegatingSegment(delegateSegment)
00038 {
00039     pVersionedRandomSegment =
00040         SegmentFactory::dynamicCast<VersionedRandomAllocationSegment *>(
00041             versionedSegment);
00042     assert(pVersionedRandomSegment);
00043 
00044     snapshotCsn = snapshotCsnInit;
00045     readOnlyCommittedData = readOnlyCommittedDataInit;
00046     needPageFlush = false;
00047     forceCacheUnmap = false;
00048 }


Member Function Documentation

PageId SnapshotRandomAllocationSegment::getSnapshotId ( PageId  pageId  )  [private]

Retrieves the pageId corresponding to this segment's snapshot of a specified page.

Parameters:
pageId pageId of the desired page
Returns:
snapshot pageId corresponding to the desired pageId

Definition at line 61 of file SnapshotRandomAllocationSegment.cpp.

References VersionedPageEntry::allocationCsn, getAnchorPageId(), VersionedRandomAllocationSegment::getLatestPageEntryCopy(), PageEntry::ownerId, pVersionedRandomSegment, readOnlyCommittedData, snapshotCsn, snapshotPageMap, snapshotPageMapMutex, UNCOMMITTED_PAGE_OWNER_ID, and VersionedPageEntry::versionChainPageId.

Referenced by getPageSuccessor(), setPageSuccessor(), translatePageId(), and updatePage().

00062 {
00063     StrictMutexGuard mutexGuard(snapshotPageMapMutex);
00064 
00065     // If possible, use the mapping we've previously cached
00066     PageMapConstIter pSnapshotPageId = snapshotPageMap.find(pageId);
00067     if (pSnapshotPageId != snapshotPageMap.end()) {
00068         return pSnapshotPageId->second;
00069     }
00070 
00071     VersionedPageEntry pageEntry;
00072     pVersionedRandomSegment->getLatestPageEntryCopy(pageId, pageEntry);
00073     // Handle the special case where there's no chain
00074     if (pageEntry.versionChainPageId == pageId) {
00075         assert(snapshotCsn >= pageEntry.allocationCsn);
00076         snapshotPageMap[pageId] = pageId;
00077         return pageId;
00078     }
00079 
00080     // If we have to walk through the page chain, then we need to be starting
00081     // from the anchor.  Note that there's no need to acquire the deallocation
00082     // mutex while walking through the page chain looking for the appropriate
00083     // snapshot page because we always start at the anchor and walk from
00084     // newer pages to older pages.  Therefore, we should never try reading
00085     // the pageEntry for an older page that's going to be deallocated.
00086     assert(pageId == getAnchorPageId(pageId));
00087     PageId chainPageId = pageEntry.versionChainPageId;
00088     do {
00089         pVersionedRandomSegment->getLatestPageEntryCopy(chainPageId, pageEntry);
00090         if (snapshotCsn >= pageEntry.allocationCsn) {
00091             // only consider uncommitted pageEntry's if they correspond to
00092             // the current txn
00093             if ((!readOnlyCommittedData &&
00094                     pageEntry.ownerId == UNCOMMITTED_PAGE_OWNER_ID &&
00095                     snapshotCsn == pageEntry.allocationCsn) ||
00096                 pageEntry.ownerId != UNCOMMITTED_PAGE_OWNER_ID)
00097             {
00098                 snapshotPageMap[pageId] = chainPageId;
00099                 return chainPageId;
00100             }
00101         }
00102         // permAssert to prevent an infinite loop
00103         permAssert(chainPageId != pageId);
00104         chainPageId = pageEntry.versionChainPageId;
00105     } while (true);
00106 }

void SnapshotRandomAllocationSegment::incrPageUpdateCount ( PageId  pageId,
PageOwnerId  ownerId,
ModifiedPageEntry::ModType  modType 
) [private]

Increments the counters that keep track of the number of modifications made to a page entry as well as allocations/deallocations.

This method assumes that the caller has already acquired an exclusive mutex on modPageEntriesMap.

Parameters:
pageId the pageId of the page whose counters are being incremented
ownerId the ownerId that will be set on the page entry when it's committed; only used in the case of a page allocation
modType type of modification made to the page entry (i.e., allocated, deallocated, or modified)

Definition at line 131 of file SnapshotRandomAllocationSegment.cpp.

References ModifiedPageEntry::ALLOCATED, ModifiedPageEntry::DEALLOCATED, SXMutex::isLocked(), LOCKMODE_X, modPageEntriesMap, modPageMapMutex, and needPageFlush.

Referenced by allocatePageId(), chainPageEntries(), deallocatePageRange(), and setPageSuccessor().

00135 {
00136     assert(modPageMapMutex.isLocked(LOCKMODE_X));
00137 
00138     needPageFlush = true;
00139 
00140     // Add an entry into the map if it's not there yet.  Otherwise, increment
00141     // the count for the existing entry.
00142     ModifiedPageEntryMapIter iter = modPageEntriesMap.find(pageId);
00143     SharedModifiedPageEntry pModPageEntry;
00144     if (iter == modPageEntriesMap.end()) {
00145         pModPageEntry = SharedModifiedPageEntry(new ModifiedPageEntry());
00146         pModPageEntry->updateCount = 0;
00147         pModPageEntry->allocationCount = 0;
00148         pModPageEntry->lastModType = modType;
00149         pModPageEntry->ownerId = ownerId;
00150     } else {
00151         pModPageEntry = iter->second;
00152         // Once we've deallocated a page, we should not be reusing the
00153         // pageId
00154         assert(pModPageEntry->lastModType != ModifiedPageEntry::DEALLOCATED);
00155     }
00156 
00157     // Update counts corresponding to updates to the SegmentAllocationNode
00158     if (modType == ModifiedPageEntry::ALLOCATED) {
00159         pModPageEntry->allocationCount++;
00160         assert(pModPageEntry->allocationCount <= 1);
00161         pModPageEntry->lastModType = modType;
00162         pModPageEntry->ownerId = ownerId;
00163     } else if (modType == ModifiedPageEntry::DEALLOCATED) {
00164         pModPageEntry->lastModType = modType;
00165     }
00166 
00167     // Update count corresponding to the VersionedExtentAllocationNode
00168     pModPageEntry->updateCount++;
00169 
00170     if (iter == modPageEntriesMap.end()) {
00171         modPageEntriesMap.insert(
00172             ModifiedPageEntryMap::value_type(pageId, pModPageEntry));
00173     }
00174 }

PageId SnapshotRandomAllocationSegment::getAnchorPageId ( PageId  snapshotId  )  [private]

Retrieves the pageId of the anchor page corresponding to a snapshot page.

Parameters:
snapshotId the pageId of the snapshot page
Returns:
pageId of the anchor page

Definition at line 176 of file SnapshotRandomAllocationSegment.cpp.

References VersionedPageEntry::allocationCsn, VersionedRandomAllocationSegment::getDeallocationMutex(), VersionedRandomAllocationSegment::getLatestPageEntryCopy(), NULL_PAGE_ID, NULL_TXN_ID, pVersionedRandomSegment, and VersionedPageEntry::versionChainPageId.

Referenced by getSnapshotId(), updatePage(), and versionPage().

00177 {
00178     // Acquire the deallocation mutex to prevent the page chain from being
00179     // modified while we're walking through it
00180     SXMutexSharedGuard(pVersionedRandomSegment->getDeallocationMutex());
00181 
00182     // Walk the page chain to find the anchor, looking for the entry with
00183     // the minimum allocationCsn.
00184     PageId chainPageId = snapshotId;
00185     VersionedPageEntry pageEntry;
00186     PageId anchorPageId = NULL_PAGE_ID;
00187     TxnId minCsn = NULL_TXN_ID;
00188     do {
00189         pVersionedRandomSegment->getLatestPageEntryCopy(chainPageId, pageEntry);
00190         if (chainPageId == snapshotId || pageEntry.allocationCsn < minCsn) {
00191             minCsn = pageEntry.allocationCsn;
00192             anchorPageId = chainPageId;
00193         } else if (pageEntry.allocationCsn > minCsn) {
00194             break;
00195         }
00196         chainPageId = pageEntry.versionChainPageId;
00197     } while (chainPageId != snapshotId);
00198 
00199     return anchorPageId;
00200 }

bool SnapshotRandomAllocationSegment::isPageNewlyAllocated ( PageId  pageId  )  [private]

Determines whether a snapshot page corresponds to a newly allocated one.

Parameters:
pageId pageId of the page in question
Returns:
true if the page is newly allocated; false otherwise

Definition at line 341 of file SnapshotRandomAllocationSegment.cpp.

References ModifiedPageEntry::ALLOCATED, modPageEntriesMap, and modPageMapMutex.

Referenced by getMappedPageListener(), and updatePage().

00342 {
00343     SXMutexSharedGuard mapGuard(modPageMapMutex);
00344 
00345     ModifiedPageEntryMapIter iter = modPageEntriesMap.find(pageId);
00346     if (iter != modPageEntriesMap.end()) {
00347         SharedModifiedPageEntry pModPageEntry = iter->second;
00348         if (pModPageEntry->lastModType == ModifiedPageEntry::ALLOCATED) {
00349             return true;
00350         }
00351     }
00352     return false;
00353 }

void SnapshotRandomAllocationSegment::chainPageEntries ( PageId  pageId,
PageId  versionChainId,
PageId  successorId 
) [private]

Chains one page to another.

Also may set the successorId of the first page.

Parameters:
pageId the pageId of the page that the second parameter will be chained to
versionChainId the pageId of the page to be chained to the first parameter
successorId if not set to NULL_PAGE_ID, the successorId of the pageEntry corresponding to the first parameter is set

Definition at line 326 of file SnapshotRandomAllocationSegment.cpp.

References ANON_PAGE_OWNER_ID, VersionedRandomAllocationSegment::chainPageEntries(), incrPageUpdateCount(), ModifiedPageEntry::MODIFIED, and pVersionedRandomSegment.

Referenced by updatePage(), and versionPage().

00330 {
00331     pVersionedRandomSegment->chainPageEntries(
00332         pageId,
00333         versionChainPageId,
00334         successorId);
00335     incrPageUpdateCount(
00336         pageId,
00337         ANON_PAGE_OWNER_ID,
00338         ModifiedPageEntry::MODIFIED);
00339 }

TxnId SnapshotRandomAllocationSegment::getSnapshotCsn (  ) 

Returns:
the csn associated with the snapshot segment

Definition at line 50 of file SnapshotRandomAllocationSegment.cpp.

References snapshotCsn.

00051 {
00052     return snapshotCsn;
00053 }

void SnapshotRandomAllocationSegment::commitChanges ( TxnId  commitCsn  ) 

Commits page entry changes.

Parameters:
commitCsn sequence number to write into pageEntry's on commit

Definition at line 355 of file SnapshotRandomAllocationSegment.cpp.

References Segment::getTracingSegment(), modPageEntriesMap, modPageMapMutex, pVersionedRandomSegment, readOnlyCommittedData, snapshotPageMap, and VersionedRandomAllocationSegment::updateAllocNodes().

Referenced by SnapshotSegmentTestBase::commitChanges(), BackupRestoreTest::createSnapshotData(), BackupRestoreTest::executeSnapshotTxn(), LcsClusterReplaceExecStreamTest::testClusterReplace(), and CmdInterpreter::visit().

00356 {
00357     assert(!readOnlyCommittedData);
00358     SXMutexExclusiveGuard mapGuard(modPageMapMutex);
00359 
00360     pVersionedRandomSegment->updateAllocNodes(
00361         modPageEntriesMap,
00362         commitCsn,
00363         true,
00364         getTracingSegment());
00365     modPageEntriesMap.clear();
00366     snapshotPageMap.clear();
00367 }

void SnapshotRandomAllocationSegment::rollbackChanges (  ) 

Rolls back page entry changes.

Definition at line 369 of file SnapshotRandomAllocationSegment.cpp.

References Segment::getTracingSegment(), modPageEntriesMap, modPageMapMutex, NULL_TXN_ID, pVersionedRandomSegment, readOnlyCommittedData, snapshotPageMap, and VersionedRandomAllocationSegment::updateAllocNodes().

Referenced by SnapshotSegmentTestBase::commitChanges().

00370 {
00371     assert(!readOnlyCommittedData);
00372     SXMutexExclusiveGuard mapGuard(modPageMapMutex);
00373 
00374     pVersionedRandomSegment->updateAllocNodes(
00375         modPageEntriesMap,
00376         NULL_TXN_ID,
00377         false,
00378         getTracingSegment());
00379     modPageEntriesMap.clear();
00380     snapshotPageMap.clear();
00381 }

void SnapshotRandomAllocationSegment::versionPage ( PageId  destAnchorPageId,
PageId  srcAnchorPageId 
)

Adds a source page chain into a destination page chain.

All pages in the source chain must be newer than the pages in the destination chain.

Parameters:
destAnchorPageId pageId of the anchor page of the destination page chain
srcAnchorPageId pageId of the anchor page of the source page chain

Definition at line 453 of file SnapshotRandomAllocationSegment.cpp.

References VersionedPageEntry::allocationCsn, chainPageEntries(), getAnchorPageId(), VersionedRandomAllocationSegment::getLatestPageEntryCopy(), modPageMapMutex, NULL_PAGE_ID, pVersionedRandomSegment, readOnlyCommittedData, snapshotPageMap, snapshotPageMapMutex, and VersionedPageEntry::versionChainPageId.

Referenced by LbmSplicerExecStream::execute(), and LcsClusterReplaceExecStream::getTupleForLoad().

00456 {
00457     assert(!readOnlyCommittedData);
00458     assert(destAnchorPageId == getAnchorPageId(destAnchorPageId));
00459     assert(srcAnchorPageId == getAnchorPageId(srcAnchorPageId));
00460 
00461     VersionedPageEntry pageEntry;
00462     pVersionedRandomSegment->getLatestPageEntryCopy(
00463         destAnchorPageId,
00464         pageEntry);
00465     TxnId largestDestCsn = pageEntry.allocationCsn;
00466     if (pageEntry.versionChainPageId != destAnchorPageId) {
00467         pVersionedRandomSegment->getLatestPageEntryCopy(
00468             pageEntry.versionChainPageId,
00469             pageEntry);
00470         largestDestCsn = pageEntry.allocationCsn;
00471     }
00472 
00473     SXMutexExclusiveGuard mapGuard(modPageMapMutex);
00474 
00475     // Link the destination anchor to the page following the source anchor,
00476     // and then link the source anchor to the original page following the
00477     // destination anchor.
00478     pVersionedRandomSegment->getLatestPageEntryCopy(
00479         srcAnchorPageId,
00480         pageEntry);
00481     assert(pageEntry.allocationCsn >= largestDestCsn);
00482     PageId pageIdAfterSrcAnchor = pageEntry.versionChainPageId;
00483     pVersionedRandomSegment->getLatestPageEntryCopy(
00484         destAnchorPageId,
00485         pageEntry);
00486     PageId pageIdAfterDestAnchor = pageEntry.versionChainPageId;
00487 
00488     chainPageEntries(destAnchorPageId, pageIdAfterSrcAnchor, NULL_PAGE_ID);
00489     chainPageEntries(srcAnchorPageId, pageIdAfterDestAnchor, NULL_PAGE_ID);
00490 
00491     StrictMutexGuard mutexGuard(snapshotPageMapMutex);
00492     snapshotPageMap[destAnchorPageId] = pageIdAfterSrcAnchor;
00493 }

void SnapshotRandomAllocationSegment::setForceCacheUnmap (  ) 

Indicates that a checkpoint should be always be executed, even if no pages are dirty when flushing and unmapping cache entries.

This is required in cases where we need to discard old entries from the cache.

Definition at line 394 of file SnapshotRandomAllocationSegment.cpp.

References forceCacheUnmap.

Referenced by SnapshotSegmentTestBase::setForceCacheUnmap().

00395 {
00396     forceCacheUnmap = true;
00397 }

BlockId SnapshotRandomAllocationSegment::translatePageId ( PageId  pageId  )  [virtual]

Maps from a PageId in this segment to a BlockId.

Reimplemented from DelegatingSegment.

Definition at line 55 of file SnapshotRandomAllocationSegment.cpp.

References getSnapshotId(), and DelegatingSegment::translatePageId().

00056 {
00057     PageId snapshotId = getSnapshotId(pageId);
00058     return DelegatingSegment::translatePageId(snapshotId);
00059 }

PageId SnapshotRandomAllocationSegment::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 108 of file SnapshotRandomAllocationSegment.cpp.

References DelegatingSegment::getPageSuccessor(), and getSnapshotId().

00109 {
00110     PageId snapshotId = getSnapshotId(pageId);
00111     return DelegatingSegment::getPageSuccessor(snapshotId);
00112 }

void SnapshotRandomAllocationSegment::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 114 of file SnapshotRandomAllocationSegment.cpp.

References ANON_PAGE_OWNER_ID, getSnapshotId(), incrPageUpdateCount(), ModifiedPageEntry::MODIFIED, modPageMapMutex, readOnlyCommittedData, and DelegatingSegment::setPageSuccessor().

00116 {
00117     assert(!readOnlyCommittedData);
00118 
00119     // The successor should be set in the latest page version.  The
00120     // pageId passed in may correspond to the anchor.
00121     PageId snapshotId = getSnapshotId(pageId);
00122     DelegatingSegment::setPageSuccessor(snapshotId, successorId);
00123 
00124     SXMutexExclusiveGuard mapGuard(modPageMapMutex);
00125     incrPageUpdateCount(
00126         snapshotId,
00127         ANON_PAGE_OWNER_ID,
00128         ModifiedPageEntry::MODIFIED);
00129 }

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

Reimplemented from DelegatingSegment.

Definition at line 202 of file SnapshotRandomAllocationSegment.cpp.

References ModifiedPageEntry::ALLOCATED, DelegatingSegment::allocatePageId(), ANON_PAGE_OWNER_ID, incrPageUpdateCount(), VersionedRandomAllocationSegment::initPageEntry(), ModifiedPageEntry::MODIFIED, modPageMapMutex, pVersionedRandomSegment, readOnlyCommittedData, snapshotCsn, and UNCOMMITTED_PAGE_OWNER_ID.

Referenced by updatePage().

00203 {
00204     assert(!readOnlyCommittedData);
00205     SXMutexExclusiveGuard mapGuard(modPageMapMutex);
00206 
00207     PageId pageId =
00208         DelegatingSegment::allocatePageId(UNCOMMITTED_PAGE_OWNER_ID);
00209     incrPageUpdateCount(pageId, ownerId, ModifiedPageEntry::ALLOCATED);
00210     pVersionedRandomSegment->initPageEntry(
00211         pageId,
00212         pageId,
00213         snapshotCsn);
00214     incrPageUpdateCount(
00215         pageId,
00216         ANON_PAGE_OWNER_ID,
00217         ModifiedPageEntry::MODIFIED);
00218     return pageId;
00219 }

void SnapshotRandomAllocationSegment::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 221 of file SnapshotRandomAllocationSegment.cpp.

References ANON_PAGE_OWNER_ID, ModifiedPageEntry::DEALLOCATED, DelegatingSegment::deallocatePageRange(), VersionedRandomAllocationSegment::getLatestPageEntryCopy(), incrPageUpdateCount(), modPageMapMutex, NULL_PAGE_ID, pVersionedRandomSegment, readOnlyCommittedData, snapshotPageMap, snapshotPageMapMutex, and VersionedPageEntry::versionChainPageId.

00224 {
00225     assert(!readOnlyCommittedData);
00226     permAssert(startPageId != NULL_PAGE_ID);
00227     permAssert(startPageId == endPageId);
00228 
00229     SXMutexExclusiveGuard mapGuard(modPageMapMutex);
00230     StrictMutexGuard mutexGuard(snapshotPageMapMutex);
00231 
00232     // Mark the pages in the page chain as deallocation-deferred.  The actual
00233     // deallocation of these pages will be done by an ALTER SYSTEM DEALLOCATE
00234     // OLD.
00235 
00236     // Note that we cannot discard snapshot pages from cache because they
00237     // really haven't been freed yet and still may be referenced by other
00238     // threads.  The pages will be removed from the cache when they are
00239     // actually freed.
00240 
00241     PageId chainPageId = startPageId;
00242     VersionedPageEntry pageEntry;
00243     do {
00244         pVersionedRandomSegment->getLatestPageEntryCopy(chainPageId, pageEntry);
00245         DelegatingSegment::deallocatePageRange(chainPageId, chainPageId);
00246         incrPageUpdateCount(
00247             chainPageId,
00248             ANON_PAGE_OWNER_ID,
00249             ModifiedPageEntry::DEALLOCATED);
00250         snapshotPageMap.erase(chainPageId);
00251 
00252         chainPageId = pageEntry.versionChainPageId;
00253     } while (chainPageId != startPageId);
00254 }

PageId SnapshotRandomAllocationSegment::updatePage ( PageId  pageId,
bool  needsTranslation = false 
) [virtual]

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 DelegatingSegment.

Definition at line 256 of file SnapshotRandomAllocationSegment.cpp.

References allocatePageId(), chainPageEntries(), getAnchorPageId(), VersionedRandomAllocationSegment::getLatestPageEntryCopy(), getSnapshotId(), isPageNewlyAllocated(), modPageMapMutex, NULL_PAGE_ID, PageEntry::ownerId, pVersionedRandomSegment, readOnlyCommittedData, snapshotPageMap, snapshotPageMapMutex, PageEntry::successorId, and VersionedPageEntry::versionChainPageId.

00259 {
00260     assert(!readOnlyCommittedData);
00261 
00262     PageId anchorPageId;
00263     PageId snapshotId;
00264     PageOwnerId ownerId;
00265 
00266     // If the snapshot page is newly allocated, then we can update the page
00267     // in-place.  The page we would have updated should be the page chained
00268     // from the anchor, which corresponds to the latest version of the page.
00269     // That, in turn, should correspond to the snapshot we would have read.
00270 
00271     if (needsTranslation) {
00272         assert(pageId == getAnchorPageId(pageId));
00273         VersionedPageEntry pageEntry;
00274         pVersionedRandomSegment->getLatestPageEntryCopy(pageId, pageEntry);
00275         assert(pageEntry.versionChainPageId == getSnapshotId(pageId));
00276         if (isPageNewlyAllocated(pageEntry.versionChainPageId)) {
00277             return NULL_PAGE_ID;
00278         }
00279 
00280         anchorPageId = pageId;
00281         snapshotId = pageEntry.versionChainPageId;
00282         ownerId = pageEntry.ownerId;
00283 
00284     } else {
00285         if (isPageNewlyAllocated(pageId)) {
00286             return NULL_PAGE_ID;
00287         }
00288         VersionedPageEntry pageEntry;
00289         anchorPageId = getAnchorPageId(pageId);
00290         pVersionedRandomSegment->getLatestPageEntryCopy(
00291             anchorPageId,
00292             pageEntry);
00293         assert(pageEntry.versionChainPageId == pageId);
00294         assert(pageId == getSnapshotId(anchorPageId));
00295 
00296         snapshotId = pageId;
00297         ownerId = pageEntry.ownerId;
00298     }
00299 
00300     // Otherwise, this is the first time we're modifying the page.
00301     // Allocate a new page and chain it into the existing version chain.
00302     // Also set the successor page on the new page to the successor set
00303     // on the current snapshot page.
00304 
00305     PageId newPageId = allocatePageId(ownerId);
00306 
00307     SXMutexExclusiveGuard mapGuard(modPageMapMutex);
00308 
00309     VersionedPageEntry pageEntry;
00310     pVersionedRandomSegment->getLatestPageEntryCopy(snapshotId, pageEntry);
00311     chainPageEntries(
00312         newPageId,
00313         snapshotId,
00314         pageEntry.successorId);
00315     chainPageEntries(anchorPageId, newPageId, NULL_PAGE_ID);
00316 
00317     // Store a mapping of the new page to itself so when we later need to
00318     // update that page, our cached mapping will tell us to directly
00319     // access that page.
00320     StrictMutexGuard mutexGuard(snapshotPageMapMutex);
00321     snapshotPageMap[newPageId] = newPageId;
00322     snapshotPageMap[anchorPageId] = newPageId;
00323     return newPageId;
00324 }

MappedPageListener * SnapshotRandomAllocationSegment::getMappedPageListener ( BlockId  blockId  )  [virtual]

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 from Segment.

Definition at line 383 of file SnapshotRandomAllocationSegment.cpp.

References isPageNewlyAllocated(), pVersionedRandomSegment, and DelegatingSegment::translateBlockId().

00385 {
00386     PageId snapshotId = translateBlockId(blockId);
00387     if (isPageNewlyAllocated(snapshotId)) {
00388         return this;
00389     } else {
00390         return pVersionedRandomSegment;
00391     }
00392 }

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

Helper for DelegatingSegment.

Parameters:
delegatingSegment the Segment on which checkpoint was originally called
checkpointType type of checkpoint requested

Reimplemented from DelegatingSegment.

Definition at line 399 of file SnapshotRandomAllocationSegment.cpp.

References CHECKPOINT_FLUSH_AND_UNMAP, forceCacheUnmap, needPageFlush, and Segment::pCache.

00402 {
00403     // Execute the checkpoint only if we have dirty pages or if we're in a
00404     // mode where we need to execute the checkpoint to discard old entries from
00405     // the cache.
00406     //
00407     // Note that we need to define this method to avoid calling
00408     // delegatedCheckpoint on the underlying VersionedRandomAllocationSegment.
00409     if (needPageFlush ||
00410         (checkpointType == CHECKPOINT_FLUSH_AND_UNMAP && forceCacheUnmap))
00411     {
00412         MappedPageListenerPredicate pagePredicate(delegatingSegment);
00413         pCache->checkpointPages(pagePredicate,checkpointType);
00414         needPageFlush = false;
00415     }
00416 }

MappedPageListener * SnapshotRandomAllocationSegment::notifyAfterPageCheckpointFlush ( CachePage page  )  [virtual]

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 from MappedPageListener.

Definition at line 419 of file SnapshotRandomAllocationSegment.cpp.

References pVersionedRandomSegment, and readOnlyCommittedData.

00421 {
00422     assert(!readOnlyCommittedData);
00423     return pVersionedRandomSegment;
00424 }

bool SnapshotRandomAllocationSegment::canFlushPage ( CachePage page  )  [virtual]

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 DelegatingSegment.

Definition at line 426 of file SnapshotRandomAllocationSegment.cpp.

References readOnlyCommittedData.

00427 {
00428     assert(!readOnlyCommittedData);
00429 
00430     // We can always flush snapshot pages since dirty snapshot pages are
00431     // always new so we don't have to worry about flushing corresponding
00432     // log pages
00433     return true;
00434 }

void SnapshotRandomAllocationSegment::notifyPageDirty ( CachePage page,
bool  bDataValid 
) [virtual]

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 DelegatingSegment.

Definition at line 436 of file SnapshotRandomAllocationSegment.cpp.

References DelegatingSegment::notifyPageDirty(), and readOnlyCommittedData.

00439 {
00440     assert(!readOnlyCommittedData);
00441 
00442     // Since snapshot pages are always new, we only need to call notifyPageDirty
00443     // when the page is first allocated.  That is indicated by bDataValid being
00444     // false.  bDataValid will be passed in as true in the case where we're
00445     // copying an existing page into a newly allocated snapshot page.
00446     // Since we've already called notifyPageDirty on the newly allocated
00447     // snapshot page, there's no need to call it again.
00448     if (!bDataValid) {
00449         DelegatingSegment::notifyPageDirty(page, bDataValid);
00450     }
00451 }

bool SnapshotRandomAllocationSegment::isWriteVersioned (  )  [virtual]

Returns:
true if the segment supports versioning

Reimplemented from Segment.

Definition at line 495 of file SnapshotRandomAllocationSegment.cpp.

00496 {
00497     return true;
00498 }

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

Returns:
number of pages allocated from this segment

Implements Segment.

Reimplemented in CircularSegment, LinearViewSegment, and RandomAllocationSegmentBase.

Definition at line 47 of file DelegatingSegment.cpp.

References DelegatingSegment::pDelegateSegment.

Referenced by CircularSegment::CircularSegment(), RandomAllocationSegmentBase::format(), and RandomAllocationSegmentBase::inferSegAllocCount().

00048 {
00049     return pDelegateSegment->getAllocatedSizeInPages();
00050 }

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 }

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(), getMappedPageListener(), WALSegment::notifyAfterPageFlush(), WALSegment::notifyPageDirty(), VersionedSegment::notifyPageDirty(), TracingSegment::translateBlockId(), LinearViewSegment::translateBlockId(), and CircularSegment::translateBlockId().

00078 {
00079     return pDelegateSegment->translateBlockId(blockId);
00080 }

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 }

bool DelegatingSegment::isPageIdAllocated ( PageId  pageId  )  [virtual, inherited]

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.

Reimplemented in CircularSegment, LinearViewSegment, RandomAllocationSegmentBase, and VersionedRandomAllocationSegment.

Definition at line 97 of file DelegatingSegment.cpp.

References DelegatingSegment::pDelegateSegment.

Referenced by RandomAllocationSegmentBase::testPageId().

00098 {
00099     return pDelegateSegment->isPageIdAllocated(pageId);
00100 }

Segment::AllocationOrder DelegatingSegment::getAllocationOrder (  )  const [virtual, inherited]

Returns:
the AllocationOrder for this segment

Implements Segment.

Reimplemented in CircularSegment, LinearViewSegment, and RandomAllocationSegmentBase.

Definition at line 102 of file DelegatingSegment.cpp.

References DelegatingSegment::pDelegateSegment.

Referenced by RandomAllocationSegmentBase::RandomAllocationSegmentBase(), and WALSegment::WALSegment().

00103 {
00104     return pDelegateSegment->getAllocationOrder();
00105 }

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

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

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(), 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(), 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 }

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(), CircularSegment::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(), 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(), 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.

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 }

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

Returns:
whether the object has been closed

Definition at line 58 of file ClosableObject.h.

00059     {
00060         return !needsClose;
00061     }

void ClosableObject::close (  )  [inherited]

Closes this object, releasing any unallocated resources.

Reimplemented in CollectExecStream, CorrelationJoinExecStream, LcsClusterAppendExecStream, and LcsClusterReplaceExecStream.

Definition at line 39 of file ClosableObject.cpp.

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

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

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


Member Data Documentation

ModifiedPageEntryMap SnapshotRandomAllocationSegment::modPageEntriesMap [private]

Keeps track of the number of modifications made to the page entry and extent entry corresponding to a page.

Definition at line 55 of file SnapshotRandomAllocationSegment.h.

Referenced by commitChanges(), incrPageUpdateCount(), isPageNewlyAllocated(), and rollbackChanges().

PageMap SnapshotRandomAllocationSegment::snapshotPageMap [private]

Maintains a mapping between a pageId and the snapshot page for this segment.

Definition at line 61 of file SnapshotRandomAllocationSegment.h.

Referenced by commitChanges(), deallocatePageRange(), getSnapshotId(), rollbackChanges(), updatePage(), and versionPage().

SXMutex SnapshotRandomAllocationSegment::modPageMapMutex [private]

Mutex that ensures only a single thread is modifying modPageEntriesMap.

It also ensures that the map is in sync with the allocations and deallocations in the underlying VersionedRandomAllocationSegment.

In cases where both modPageMapMutex and snapshotPageMapMutex need to be acquired, modPageMapMutex should be acquired first.

Definition at line 79 of file SnapshotRandomAllocationSegment.h.

Referenced by allocatePageId(), commitChanges(), deallocatePageRange(), incrPageUpdateCount(), isPageNewlyAllocated(), rollbackChanges(), setPageSuccessor(), updatePage(), and versionPage().

StrictMutex SnapshotRandomAllocationSegment::snapshotPageMapMutex [private]

Mutex protecting the snapshotPageMap.

In cases where both modPageMapMutex and snapshotPageMapMutex need to be acquired, modPageMapMutex should be acquired first.

Definition at line 88 of file SnapshotRandomAllocationSegment.h.

Referenced by deallocatePageRange(), getSnapshotId(), updatePage(), and versionPage().

VersionedRandomAllocationSegment* SnapshotRandomAllocationSegment::pVersionedRandomSegment [private]

Underlying segment that provides versioning of pages.

Definition at line 93 of file SnapshotRandomAllocationSegment.h.

Referenced by allocatePageId(), chainPageEntries(), commitChanges(), deallocatePageRange(), getAnchorPageId(), getMappedPageListener(), getSnapshotId(), notifyAfterPageCheckpointFlush(), rollbackChanges(), SnapshotRandomAllocationSegment(), updatePage(), and versionPage().

TxnId SnapshotRandomAllocationSegment::snapshotCsn [private]

The commit sequence number used to determine which pages to read.

Definition at line 98 of file SnapshotRandomAllocationSegment.h.

Referenced by allocatePageId(), getSnapshotCsn(), getSnapshotId(), and SnapshotRandomAllocationSegment().

bool SnapshotRandomAllocationSegment::readOnlyCommittedData [private]

True if only committed data should be read by the segment.

This includes not reading uncommitted data created by the current transaction.

Definition at line 105 of file SnapshotRandomAllocationSegment.h.

Referenced by allocatePageId(), canFlushPage(), commitChanges(), deallocatePageRange(), getSnapshotId(), notifyAfterPageCheckpointFlush(), notifyPageDirty(), rollbackChanges(), setPageSuccessor(), SnapshotRandomAllocationSegment(), updatePage(), and versionPage().

bool SnapshotRandomAllocationSegment::needPageFlush [private]

If true, some snapshot page has been modified and therefore pages need to be flushed during a checkpoint call.

Definition at line 111 of file SnapshotRandomAllocationSegment.h.

Referenced by delegatedCheckpoint(), incrPageUpdateCount(), and SnapshotRandomAllocationSegment().

bool SnapshotRandomAllocationSegment::forceCacheUnmap [private]

If true, always issue the checkpoint to remove entries from the cache when flushing and unmapping cache entries.

Otherwise, only checkpoint pages if at least one page was dirtied.

Definition at line 118 of file SnapshotRandomAllocationSegment.h.

Referenced by delegatedCheckpoint(), setForceCacheUnmap(), and SnapshotRandomAllocationSegment().

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(), 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:46 2009 for Fennel by  doxygen 1.5.1