TracingSegment Class Reference

TracingSegment implements tracing for the Segment interface. More...

#include <TracingSegment.h>

Inheritance diagram for TracingSegment:

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

 TracingSegment (SharedSegment delegateSegment, SharedTraceTarget pTraceTarget, std::string sourceName)
 Constructs a new TracingSegment.
virtual ~TracingSegment ()
virtual void setPageSuccessor (PageId pageId, PageId successorId)
 Sets the successor of a given PageId.
virtual BlockId translatePageId (PageId)
 Maps from a PageId in this segment to a BlockId.
virtual PageId translateBlockId (BlockId)
 Maps from a BlockId to a PageId in this segment.
virtual PageId allocatePageId (PageOwnerId ownerId=ANON_PAGE_OWNER_ID)
 Allocates a page without locking it into memory.
virtual bool ensureAllocatedSize (BlockNum nPages)
 Allocates pages as needed to make getAllocatedSizeInPages() meet a lower bound.
virtual void deallocatePageRange (PageId startPageId, PageId endPageId)
 Deallocates a range of pages allocated from this segment.
virtual void delegatedCheckpoint (Segment &delegatingSegment, CheckpointType checkpointType)
 Helper for DelegatingSegment.
virtual MappedPageListenergetMappedPageListener (BlockId blockId)
 Returns the mapped page listener corresponding to a page.
virtual bool isWriteVersioned ()
 
Returns:
true if the segment supports versioning

virtual void notifyPageMap (CachePage &page)
 Receives notification from CacheImpl as soon as a page is mapped, before any I/O is initiated to retrieve the page contents.
virtual void notifyPageUnmap (CachePage &page)
 Receives notification from CacheImpl just before a page is unmapped.
virtual void notifyAfterPageRead (CachePage &page)
 Receives notification from CacheImpl after a page read completes.
virtual void notifyPageDirty (CachePage &page, bool bDataValid)
 Receives notification from CacheImpl the first time a page becomes dirty after it has been mapped (but before the contents have changed).
virtual void notifyBeforePageFlush (CachePage &page)
 Receives notification from CacheImpl just before a dirty page is flushed to disk.
virtual void notifyAfterPageFlush (CachePage &page)
 Receives notification from CacheImpl when a page flush completes successfully.
virtual MappedPageListenernotifyAfterPageCheckpointFlush (CachePage &page)
 Receives notification that a page has been flushed during a checkpoint.
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 getPageSuccessor (PageId pageId)
 Determines the successor of a given PageId.
virtual bool isPageIdAllocated (PageId pageId)
 Tests whether a PageId is allocated.
virtual AllocationOrder getAllocationOrder () const
 
Returns:
the AllocationOrder for 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 bool canFlushPage (CachePage &page)
 Informs CacheImpl whether a dirty page can safely be flushed to disk.
SharedCache getCache () const
 
Returns:
the Cache for this Segment

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

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

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

void setTracingSegment (WeakSegment pTracingSegmentInit)
 Sets the tracing segment associated with this segment.
void checkpoint (CheckpointType checkpointType=CHECKPOINT_FLUSH_ALL)
 Checkpoints this segment.
virtual 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.
virtual void initTraceSource (SharedTraceTarget pTraceTarget, std::string name)
 For use when initialization has to be deferred until after construction.
void trace (TraceLevel level, std::string message) const
 Records a trace message.
bool isTracing () const
 
Returns:
true iff tracing is enabled for this source

bool isTracingLevel (TraceLevel level) const
 Determines whether a particular level is being traced.
TraceTargetgetTraceTarget () const
 
Returns:
the TraceTarget for this source

SharedTraceTarget getSharedTraceTarget () const
 
Returns:
the SharedTraceTarget for this source

std::string getTraceSourceName () const
 Gets the name of this source.
void setTraceSourceName (std::string const &n)
 Sets the name of this source.
TraceLevel getMinimumTraceLevel () const
void disableTracing ()

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

Detailed Description

TracingSegment implements tracing for the Segment interface.

Definition at line 35 of file TracingSegment.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

TracingSegment::TracingSegment ( SharedSegment  delegateSegment,
SharedTraceTarget  pTraceTarget,
std::string  sourceName 
) [explicit]

Constructs a new TracingSegment.

Parameters:
delegateSegment the underlying segment
pTraceTarget the target for trace messages
sourceName the source name for trace messages

Definition at line 34 of file TracingSegment.cpp.

References TRACE_FINE.

00038     : DelegatingSegment(pDelegateSegment),
00039       TraceSource(pTraceTarget,sourceName)
00040 {
00041     FENNEL_TRACE(TRACE_FINE,"constructor");
00042 }

TracingSegment::~TracingSegment (  )  [virtual]

Definition at line 44 of file TracingSegment.cpp.

References TRACE_FINE.

00045 {
00046     FENNEL_TRACE(TRACE_FINE,"destructor");
00047 }


Member Function Documentation

void TracingSegment::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 49 of file TracingSegment.cpp.

References DelegatingSegment::setPageSuccessor(), and TRACE_FINER.

00050 {
00051     FENNEL_TRACE(
00052         TRACE_FINER,
00053         "setPageSuccessor of PageId " << std::hex << pageId
00054         << " to PageId " << std::hex << successorId);
00055     DelegatingSegment::setPageSuccessor(pageId,successorId);
00056 }

BlockId TracingSegment::translatePageId ( PageId   )  [virtual]

Maps from a PageId in this segment to a BlockId.

Reimplemented from DelegatingSegment.

Definition at line 58 of file TracingSegment.cpp.

References TRACE_FINEST, and DelegatingSegment::translatePageId().

00059 {
00060     BlockId blockId = DelegatingSegment::translatePageId(pageId);
00061     FENNEL_TRACE(
00062         TRACE_FINEST,
00063         "translatePageId " << std::hex << pageId << " returns BlockId "
00064         << std::hex << blockId);
00065     return blockId;
00066 }

PageId TracingSegment::translateBlockId ( BlockId   )  [virtual]

Maps from a BlockId to a PageId in this segment.

Reimplemented from DelegatingSegment.

Definition at line 68 of file TracingSegment.cpp.

References TRACE_FINEST, and DelegatingSegment::translateBlockId().

00069 {
00070     PageId pageId = DelegatingSegment::translateBlockId(blockId);
00071     FENNEL_TRACE(
00072         TRACE_FINEST,
00073         "translateBlockId " << std::hex << blockId << " returns PageId "
00074         << std::hex << pageId);
00075     return pageId;
00076 }

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

Allocates a page without locking it into memory.

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

Reimplemented from DelegatingSegment.

Definition at line 78 of file TracingSegment.cpp.

References DelegatingSegment::allocatePageId(), and TRACE_FINE.

00079 {
00080     PageId pageId = DelegatingSegment::allocatePageId(ownerId);
00081     FENNEL_TRACE(
00082         TRACE_FINE,
00083         "allocatePageId for PageOwnerId " << std::hex << ownerId
00084         << " returns PageId " << std::hex << pageId);
00085     return pageId;
00086 }

bool TracingSegment::ensureAllocatedSize ( BlockNum  nPages  )  [virtual]

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

Definition at line 88 of file TracingSegment.cpp.

References DelegatingSegment::ensureAllocatedSize(), and TRACE_FINE.

00089 {
00090     bool b = DelegatingSegment::ensureAllocatedSize(nPages);
00091     FENNEL_TRACE(
00092         TRACE_FINE,
00093         "ensureAllocatedSize of " << nPages << " pages"
00094         << " returns " << b);
00095     return b;
00096 }

void TracingSegment::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 98 of file TracingSegment.cpp.

References DelegatingSegment::deallocatePageRange(), and TRACE_FINE.

00099 {
00100     FENNEL_TRACE(
00101         TRACE_FINE,
00102         "deallocatePageRange " << std::hex << startPageId << ", "
00103         << std::hex << endPageId);
00104     DelegatingSegment::deallocatePageRange(startPageId,endPageId);
00105 }

void TracingSegment::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 161 of file TracingSegment.cpp.

References DelegatingSegment::delegatedCheckpoint(), and TRACE_FINER.

00164 {
00165     FENNEL_TRACE(
00166         TRACE_FINER,
00167         "checkpoint type=" << checkpointType);
00168     DelegatingSegment::delegatedCheckpoint(delegatingSegment,checkpointType);
00169 }

MappedPageListener * TracingSegment::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 171 of file TracingSegment.cpp.

References DelegatingSegment::getDelegateSegment(), MappedPageListener::getTracingListener(), and TRACE_FINEST.

00172 {
00173     // We need to retrieve the listener associated with the delegating
00174     // segment, and then map the return value back to the parent tracing
00175     // segment.
00176     MappedPageListener *pListener =
00177         getDelegateSegment()->getMappedPageListener(blockId);
00178     FENNEL_TRACE(
00179         TRACE_FINEST,
00180         "getMappedPageListener for blockId " << std::hex << blockId
00181             << " = " << std::hex << pListener);
00182 
00183     return pListener->getTracingListener();
00184 }

bool TracingSegment::isWriteVersioned (  )  [virtual]

Returns:
true if the segment supports versioning

Reimplemented from Segment.

Definition at line 209 of file TracingSegment.cpp.

References DelegatingSegment::getDelegateSegment(), and TRACE_FINEST.

00210 {
00211     bool b = getDelegateSegment()->isWriteVersioned();
00212     FENNEL_TRACE(TRACE_FINEST,"isWriteVersioned returns " << b);
00213     return b;
00214 }

void TracingSegment::notifyPageMap ( CachePage page  )  [virtual]

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

Definition at line 107 of file TracingSegment.cpp.

References CachePage::getBlockId(), DelegatingSegment::notifyPageMap(), and TRACE_FINEST.

00108 {
00109     FENNEL_TRACE(
00110         TRACE_FINEST,
00111         "notifyPageMap @" << &page << " BlockId "
00112         << std::hex << page.getBlockId());
00113     DelegatingSegment::notifyPageMap(page);
00114 }

void TracingSegment::notifyPageUnmap ( CachePage page  )  [virtual]

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

Definition at line 116 of file TracingSegment.cpp.

References CachePage::getBlockId(), DelegatingSegment::notifyPageUnmap(), and TRACE_FINEST.

00117 {
00118     FENNEL_TRACE(
00119         TRACE_FINEST,
00120         "notifyPageUnmap @" << &page << " BlockId "
00121         << std::hex << page.getBlockId());
00122     DelegatingSegment::notifyPageUnmap(page);
00123 }

void TracingSegment::notifyAfterPageRead ( CachePage page  )  [virtual]

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

Definition at line 125 of file TracingSegment.cpp.

References CachePage::getBlockId(), DelegatingSegment::notifyAfterPageRead(), and TRACE_FINEST.

00126 {
00127     FENNEL_TRACE(
00128         TRACE_FINEST,
00129         "notifyAfterPageRead @" << &page << " BlockId "
00130         << std::hex << page.getBlockId());
00131     DelegatingSegment::notifyAfterPageRead(page);
00132 }

void TracingSegment::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 134 of file TracingSegment.cpp.

References CachePage::getBlockId(), DelegatingSegment::notifyPageDirty(), and TRACE_FINER.

00135 {
00136     FENNEL_TRACE(
00137         TRACE_FINER,
00138         "notifyPageDirty @" << &page << " BlockId "
00139         << std::hex << page.getBlockId());
00140     DelegatingSegment::notifyPageDirty(page,bDataValid);
00141 }

void TracingSegment::notifyBeforePageFlush ( CachePage page  )  [virtual]

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

Definition at line 143 of file TracingSegment.cpp.

References CachePage::getBlockId(), DelegatingSegment::notifyBeforePageFlush(), and TRACE_FINER.

00144 {
00145     FENNEL_TRACE(
00146         TRACE_FINER,
00147         "notifyBeforePageFlush @" << &page << " BlockId "
00148         << std::hex << page.getBlockId());
00149     DelegatingSegment::notifyBeforePageFlush(page);
00150 }

void TracingSegment::notifyAfterPageFlush ( CachePage page  )  [virtual]

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

Definition at line 152 of file TracingSegment.cpp.

References CachePage::getBlockId(), DelegatingSegment::notifyAfterPageFlush(), and TRACE_FINER.

00153 {
00154     FENNEL_TRACE(
00155         TRACE_FINER,
00156         "notifyAfterPageFlush @" << &page << " BlockId "
00157         << std::hex << page.getBlockId());
00158     DelegatingSegment::notifyAfterPageFlush(page);
00159 }

MappedPageListener * TracingSegment::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 186 of file TracingSegment.cpp.

References CachePage::getBlockId(), DelegatingSegment::getDelegateSegment(), MappedPageListener::getTracingListener(), and TRACE_FINER.

00188 {
00189     // We need to retrieve the listener associated with the delegating
00190     // segment, and then map the return value back to the parent tracing
00191     // segment.
00192     MappedPageListener *pListener =
00193         getDelegateSegment()->notifyAfterPageCheckpointFlush(page);
00194     if (pListener == NULL) {
00195         FENNEL_TRACE(
00196             TRACE_FINER,
00197             "notifyAfterPageCheckpointFlush for blockId " << std::hex <<
00198                 page.getBlockId() << " = NULL");
00199         return pListener;
00200     } else {
00201         FENNEL_TRACE(
00202             TRACE_FINER,
00203             "notifyAfterPageCheckpointFlush for blockId " << std::hex <<
00204                 page.getBlockId() << " = " << std::hex << pListener);
00205         return pListener->getTracingListener();
00206     }
00207 }

SharedSegment const& DelegatingSegment::getDelegateSegment (  )  const [inline, inherited]

Definition at line 53 of file DelegatingSegment.h.

Referenced by SegmentFactory::dynamicCast(), getMappedPageListener(), isWriteVersioned(), and 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::getPageSuccessor ( PageId  pageId  )  [virtual, inherited]

Determines the successor of a given PageId.

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

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

Implements Segment.

Reimplemented in CircularSegment, LinearViewSegment, RandomAllocationSegment, SnapshotRandomAllocationSegment, and VersionedRandomAllocationSegment.

Definition at line 62 of file DelegatingSegment.cpp.

References DelegatingSegment::pDelegateSegment.

Referenced by SnapshotRandomAllocationSegment::getPageSuccessor(), and LinearViewSegment::LinearViewSegment().

00063 {
00064     return pDelegateSegment->getPageSuccessor(pageId);
00065 }

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 }

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

Determines whether a page can be updated in-place, and if so, prepares the page for update.

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

Reimplemented from Segment.

Reimplemented in LinearViewSegment, and SnapshotRandomAllocationSegment.

Definition at line 148 of file DelegatingSegment.cpp.

References DelegatingSegment::pDelegateSegment.

Referenced by LinearViewSegment::updatePage().

00149 {
00150     return pDelegateSegment->updatePage(pageId, needsTranslation);
00151 }

bool DelegatingSegment::canFlushPage ( CachePage page  )  [virtual, inherited]

Informs CacheImpl whether a dirty page can safely be flushed to disk.

Called with the page mutex held, so the implementation must take care to avoid deadlock.

Parameters:
page the page to be flushed

Reimplemented from MappedPageListener.

Reimplemented in SnapshotRandomAllocationSegment, and VersionedSegment.

Definition at line 137 of file DelegatingSegment.cpp.

References DelegatingSegment::pDelegateSegment.

Referenced by VersionedSegment::canFlushPage().

00138 {
00139     return pDelegateSegment->canFlushPage(page);
00140 }

void Segment::setUsablePageSize ( uint   )  [protected, inherited]

Definition at line 70 of file Segment.cpp.

References Segment::cbUsablePerPage.

Referenced by DelegatingSegment::DelegatingSegment(), DynamicDelegatingSegment::DynamicDelegatingSegment(), Segment::Segment(), and VersionedSegment::VersionedSegment().

00071 {
00072     cbUsablePerPage = cb;
00073 }

PConstBuffer Segment::getReadableFooter ( CachePage page  )  [protected, inherited]

Definition at line 75 of file Segment.cpp.

References CachePage::getReadableData(), and Segment::getUsablePageSize().

Referenced by VersionedSegment::getPageVersion(), and VersionedSegment::recover().

00076 {
00077     return page.getReadableData() + getUsablePageSize();
00078 }

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

Definition at line 80 of file Segment.cpp.

References Segment::getUsablePageSize(), and CachePage::getWritableData().

Referenced by VersionedSegment::notifyPageDirty().

00081 {
00082     return page.getWritableData() + getUsablePageSize();
00083 }

PageId Segment::getLinearPageSuccessor ( PageId  pageId  )  [protected, inherited]

An implementation of getPageSuccessor suitable for LINEAR_ALLOCATION.

Definition at line 85 of file Segment.cpp.

References Segment::isPageIdAllocated(), and NULL_PAGE_ID.

Referenced by ScratchSegment::getPageSuccessor(), LinearViewSegment::getPageSuccessor(), LinearDeviceSegment::getPageSuccessor(), and 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(), 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 }

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 }

void TraceSource::initTraceSource ( SharedTraceTarget  pTraceTarget,
std::string  name 
) [virtual, inherited]

For use when initialization has to be deferred until after construction.

Parameters:
pTraceTarget the TraceTarget to which messages will be sent
name the name of this source

Definition at line 46 of file TraceSource.cpp.

References TraceSource::isTracing(), TraceSource::minimumLevel, TraceSource::name, TraceSource::pTraceTarget, and TRACE_OFF.

Referenced by TestBase::beforeTestCase(), TestBase::TestBase(), and TraceSource::TraceSource().

00049 {
00050     assert(!pTraceTarget.get());
00051 
00052     pTraceTarget = pTraceTargetInit;
00053     name = nameInit;
00054     if (isTracing()) {
00055         minimumLevel = pTraceTarget->getSourceTraceLevel(name);
00056     } else {
00057         minimumLevel = TRACE_OFF;
00058     }
00059 }

void TraceSource::trace ( TraceLevel  level,
std::string  message 
) const [inherited]

Records a trace message.

Normally only called via FENNEL_TRACE.

Parameters:
level severity level of event being trace
message the text of the message

Definition at line 61 of file TraceSource.cpp.

References TraceSource::getTraceTarget(), TraceSource::isTracing(), TraceSource::name, and TraceTarget::notifyTrace().

Referenced by Calculator::exec(), and ExecStreamScheduler::traceStreamBufferContents().

00062 {
00063     if (isTracing()) {
00064         getTraceTarget().notifyTrace(name,level,message);
00065     }
00066 }

bool TraceSource::isTracing (  )  const [inline, inherited]

Returns:
true iff tracing is enabled for this source

Definition at line 88 of file TraceSource.h.

Referenced by TraceSource::initTraceSource(), CalcExecStream::prepare(), and TraceSource::trace().

00089     {
00090         return pTraceTarget.get() ? true : false;
00091     }

bool TraceSource::isTracingLevel ( TraceLevel  level  )  const [inline, inherited]

Determines whether a particular level is being traced.

Parameters:
level trace level to test
Returns:
true iff tracing is enabled for the given level

Definition at line 100 of file TraceSource.h.

Referenced by ExecStreamScheduler::addGraph(), SimpleExecStreamGovernor::assignCachePages(), SimpleExecStreamGovernor::distributeCachePages(), Calculator::exec(), ExecStreamScheduler::ExecStreamScheduler(), LcsClusterNodeWriter::getLastClusterPageForWrite(), LcsClusterNodeWriter::moveFromTempToIndex(), JavaSinkExecStream::stuffByteBuffer(), and ExecStreamScheduler::traceStreamBuffers().

00101     {
00102         return level >= minimumLevel;
00103     }

TraceTarget& TraceSource::getTraceTarget (  )  const [inline, inherited]

Returns:
the TraceTarget for this source

Definition at line 108 of file TraceSource.h.

Referenced by TraceSource::trace().

00109     {
00110         assert(isTracing());
00111         return *(pTraceTarget.get());
00112     }

SharedTraceTarget TraceSource::getSharedTraceTarget (  )  const [inline, inherited]

Returns:
the SharedTraceTarget for this source

Definition at line 117 of file TraceSource.h.

Referenced by Database::init(), LcsClusterAppendExecStream::initLoad(), and CalcExecStream::prepare().

00118     {
00119         return pTraceTarget;
00120     }

std::string TraceSource::getTraceSourceName (  )  const [inline, inherited]

Gets the name of this source.

Useful to construct nested names for subcomponents that are also TraceSources.

Returns:
the name

Definition at line 127 of file TraceSource.h.

Referenced by LcsClusterAppendExecStream::initLoad().

00128     {
00129         return name;
00130     }

void TraceSource::setTraceSourceName ( std::string const &  n  )  [inline, inherited]

Sets the name of this source.

Useful to construct dynamic names for fine-grained filtering.

Definition at line 136 of file TraceSource.h.

00137     {
00138         name = n;
00139     }

TraceLevel TraceSource::getMinimumTraceLevel (  )  const [inline, inherited]

Definition at line 141 of file TraceSource.h.

00142     {
00143         return minimumLevel;
00144     }

void TraceSource::disableTracing (  )  [inherited]

Definition at line 68 of file TraceSource.cpp.

References TraceSource::minimumLevel, TraceSource::pTraceTarget, and TRACE_OFF.

Referenced by TestBase::afterTestCase().

00069 {
00070     pTraceTarget.reset();
00071     minimumLevel = TRACE_OFF;
00072 }


Member Data Documentation

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