QuotaCacheAccessor Class Reference

QuotaCacheAccessor is an implementation of CacheAccessor which keeps track of the number of locked pages and asserts that this never exceeds a given quota. More...

#include <QuotaCacheAccessor.h>

Inheritance diagram for QuotaCacheAccessor:

TransactionalCacheAccessor DelegatingCacheAccessor CacheAccessor List of all members.

Public Member Functions

 QuotaCacheAccessor (SharedQuotaCacheAccessor pSuperQuotaAccessor, SharedCacheAccessor pDelegate, uint maxLockedPages)
 Constructor.
virtual ~QuotaCacheAccessor ()
virtual uint getMaxLockedPages ()
 
Returns:
the page lock quota on this accessor

virtual void setMaxLockedPages (uint nPages)
 Sets the page lock quota on this accessor.
uint getLockedPageCount () const
 
Returns:
the current number of pages locked

virtual CachePagelockPage (BlockId blockId, LockMode lockMode, bool readIfUnmapped=true, MappedPageListener *pMappedPageListener=NULL, TxnId txnId=IMPLICIT_TXN_ID)
 Locks a page into memory with the specified concurrency mode.
virtual void unlockPage (CachePage &page, LockMode lockMode, TxnId txnId=IMPLICIT_TXN_ID)
 Releases lock held on page.
virtual void setTxnId (TxnId txnId)
 Sets a default TxnId to use for locking pages (to be used when IMPLICIT_TXN_ID is specified).
virtual TxnId getTxnId () const
 
Returns:
default TxnId associated with this accessor

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

virtual void getPrefetchParams (uint &prefetchPagesMax, uint &prefetchThrottleRate)
 Retrieves the current pre-fetch caching parameters that determine how many pages should be pre-fetched and how often the pre-fetches should occur.

Private Member Functions

void incrementUsage ()
void decrementUsage ()

Private Attributes

SharedQuotaCacheAccessor pSuperQuotaAccessor
uint maxLockedPages
AtomicCounter nPagesLocked

Detailed Description

QuotaCacheAccessor is an implementation of CacheAccessor which keeps track of the number of locked pages and asserts that this never exceeds a given quota.

It does not detect the case where the same page is locked twice.

QuotaCacheAccessor inherits TransactionalCacheAccessor functionality.

Definition at line 46 of file QuotaCacheAccessor.h.


Constructor & Destructor Documentation

QuotaCacheAccessor::QuotaCacheAccessor ( SharedQuotaCacheAccessor  pSuperQuotaAccessor,
SharedCacheAccessor  pDelegate,
uint  maxLockedPages 
) [explicit]

Constructor.

Parameters:
pSuperQuotaAccessor if non-singular, all pages locked are also charged against this super-quota; the super and sub quota limits and counts are maintained independently
pDelegate the underlying CacheAccessor
maxLockedPages 

Definition at line 29 of file QuotaCacheAccessor.cpp.

00033     : TransactionalCacheAccessor(pDelegateInit),
00034       pSuperQuotaAccessor(pSuperQuotaAccessorInit),
00035       maxLockedPages(maxLockedPagesInit)
00036 {
00037 }

QuotaCacheAccessor::~QuotaCacheAccessor (  )  [virtual]

Definition at line 39 of file QuotaCacheAccessor.cpp.

References nPagesLocked.

00040 {
00041     assert(!nPagesLocked);
00042 }


Member Function Documentation

void QuotaCacheAccessor::incrementUsage (  )  [private]

Definition at line 68 of file QuotaCacheAccessor.cpp.

References maxLockedPages, nPagesLocked, and pSuperQuotaAccessor.

Referenced by lockPage().

00069 {
00070     assert(nPagesLocked < maxLockedPages);
00071     ++nPagesLocked;
00072     if (pSuperQuotaAccessor) {
00073         pSuperQuotaAccessor->incrementUsage();
00074     }
00075 }

void QuotaCacheAccessor::decrementUsage (  )  [private]

Definition at line 77 of file QuotaCacheAccessor.cpp.

References nPagesLocked, and pSuperQuotaAccessor.

Referenced by unlockPage().

00078 {
00079     assert(nPagesLocked);
00080     --nPagesLocked;
00081     if (pSuperQuotaAccessor) {
00082         pSuperQuotaAccessor->decrementUsage();
00083     }
00084 }

uint QuotaCacheAccessor::getMaxLockedPages (  )  [virtual]

Returns:
the page lock quota on this accessor

Reimplemented from DelegatingCacheAccessor.

Definition at line 86 of file QuotaCacheAccessor.cpp.

References maxLockedPages.

Referenced by CacheTest::testQuotaCacheAccessor().

00087 {
00088     return maxLockedPages;
00089 }

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

Sets the page lock quota on this accessor.

Ignored for accessor implementations that don't support quotas.

Parameters:
nPages new quota

Reimplemented from DelegatingCacheAccessor.

Definition at line 91 of file QuotaCacheAccessor.cpp.

References maxLockedPages, and nPagesLocked.

00092 {
00093     assert(nPages >= nPagesLocked);
00094     maxLockedPages = nPages;
00095 }

uint QuotaCacheAccessor::getLockedPageCount (  )  const [inline]

Returns:
the current number of pages locked

Definition at line 84 of file QuotaCacheAccessor.h.

Referenced by CacheTest::testQuotaCacheAccessor().

00085     {
00086         return nPagesLocked;
00087     }

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

Locks a page into memory with the specified concurrency mode.

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

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

Notes on concurrency modes:

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

Reimplemented from TransactionalCacheAccessor.

Definition at line 44 of file QuotaCacheAccessor.cpp.

References incrementUsage(), and TransactionalCacheAccessor::lockPage().

Referenced by CacheTest::testQuotaCacheAccessor().

00050 {
00051     CachePage *pPage = TransactionalCacheAccessor::lockPage(
00052         blockId,lockMode,readIfUnmapped,pMappedPageListener,txnId);
00053     if (pPage) {
00054         incrementUsage();
00055     }
00056     return pPage;
00057 }

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

Releases lock held on page.

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

Reimplemented from TransactionalCacheAccessor.

Definition at line 59 of file QuotaCacheAccessor.cpp.

References decrementUsage(), and TransactionalCacheAccessor::unlockPage().

Referenced by CacheTest::testQuotaCacheAccessor().

00063 {
00064     decrementUsage();
00065     TransactionalCacheAccessor::unlockPage(page,lockMode,txnId);
00066 }

void TransactionalCacheAccessor::setTxnId ( TxnId  txnId  )  [virtual, inherited]

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

Not all CacheAccessor implementations support this behavior.

Parameters:
txnId new default txn ID

Reimplemented from DelegatingCacheAccessor.

Definition at line 65 of file TransactionalCacheAccessor.cpp.

References TransactionalCacheAccessor::implicitTxnId.

00066 {
00067     implicitTxnId = txnId;
00068 }

TxnId TransactionalCacheAccessor::getTxnId (  )  const [virtual, inherited]

Returns:
default TxnId associated with this accessor

Reimplemented from DelegatingCacheAccessor.

Definition at line 70 of file TransactionalCacheAccessor.cpp.

References TransactionalCacheAccessor::implicitTxnId.

00071 {
00072     return implicitTxnId;
00073 }

void DelegatingCacheAccessor::discardPage ( BlockId  blockId  )  [virtual, inherited]

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

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

Parameters:
blockId the BlockId of the page to be discarded

Implements CacheAccessor.

Definition at line 54 of file DelegatingCacheAccessor.cpp.

References DelegatingCacheAccessor::pDelegate.

00056 {
00057     pDelegate->discardPage(blockId);
00058 }

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

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

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

Implements CacheAccessor.

Definition at line 60 of file DelegatingCacheAccessor.cpp.

References DelegatingCacheAccessor::pDelegate.

00063 {
00064     return pDelegate->prefetchPage(blockId,pMappedPageListener);
00065 }

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

Hints that a contiguous run of pages should be prefetched.

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

Implements CacheAccessor.

Definition at line 67 of file DelegatingCacheAccessor.cpp.

References DelegatingCacheAccessor::pDelegate.

00070 {
00071     pDelegate->prefetchBatch(blockId,nPages,pMappedPageListener);
00072 }

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

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

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

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

Implements CacheAccessor.

Definition at line 74 of file DelegatingCacheAccessor.cpp.

References DelegatingCacheAccessor::pDelegate.

00075 {
00076     pDelegate->flushPage(page,async);
00077 }

void DelegatingCacheAccessor::nicePage ( CachePage page  )  [virtual, inherited]

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

Parameters:
page the page to be marked

Implements CacheAccessor.

Definition at line 79 of file DelegatingCacheAccessor.cpp.

References DelegatingCacheAccessor::pDelegate.

00080 {
00081     pDelegate->nicePage(page);
00082 }

SharedCache DelegatingCacheAccessor::getCache (  )  [virtual, inherited]

Returns:
the underlying Cache accessed by this CacheAccessor

Implements CacheAccessor.

Definition at line 84 of file DelegatingCacheAccessor.cpp.

References DelegatingCacheAccessor::pDelegate.

00085 {
00086     return pDelegate->getCache();
00087 }

void DelegatingCacheAccessor::getPrefetchParams ( uint prefetchPagesMax,
uint prefetchThrottleRate 
) [virtual, inherited]

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

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

Implements CacheAccessor.

Definition at line 109 of file DelegatingCacheAccessor.cpp.

References DelegatingCacheAccessor::pDelegate.

00112 {
00113     pDelegate->getPrefetchParams(prefetchPagesMax, prefetchThrottleRate);
00114 }


Member Data Documentation

SharedQuotaCacheAccessor QuotaCacheAccessor::pSuperQuotaAccessor [private]

Definition at line 49 of file QuotaCacheAccessor.h.

Referenced by decrementUsage(), and incrementUsage().

uint QuotaCacheAccessor::maxLockedPages [private]

Definition at line 50 of file QuotaCacheAccessor.h.

Referenced by getMaxLockedPages(), incrementUsage(), and setMaxLockedPages().

AtomicCounter QuotaCacheAccessor::nPagesLocked [private]

Definition at line 51 of file QuotaCacheAccessor.h.

Referenced by decrementUsage(), incrementUsage(), setMaxLockedPages(), and ~QuotaCacheAccessor().


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