Zero  0.1.0
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | List of all members
zero::buffer_pool::PageEvictioner Class Referenceabstract

Page evictioner for the buffer pool. More...

#include <page_evictioner.hpp>

Inheritance diagram for zero::buffer_pool::PageEvictioner:
worker_thread_t thread_wrapper_t zero::buffer_pool::PageEvictionerCAR< on_page_unfix > zero::buffer_pool::PageEvictionerLeanStore< cooling_stage_size_ppm > zero::buffer_pool::PageEvictionerSelectAndFilter< selector_class, filter_class, filter_early >

Public Member Functions

 PageEvictioner (const BufferPool *bufferPool)
 Constructs an abstract page evictioner. More...
 
 PageEvictioner (const PageEvictioner &)=delete
 Explicitly deleted copy constructor of an abstract page evictioner. More...
 
PageEvictioneroperator= (const PageEvictioner &)=delete
 Explicitly deleted assignment operator of an abstract page evictioner. More...
 
virtual ~PageEvictioner ()
 Destructs an abstract page evictioner. More...
 
virtual bf_idx pickVictim () noexcept=0
 Selects a page to be evicted from the buffer pool. More...
 
virtual void updateOnPageHit (bf_idx idx) noexcept=0
 Updates the eviction statistics on page hit. More...
 
virtual void updateOnPageUnfix (bf_idx idx) noexcept=0
 Updates the eviction statistics on page unfix. More...
 
virtual void updateOnPageMiss (bf_idx idx, PageID pid) noexcept=0
 Updates the eviction statistics on page miss. More...
 
virtual void updateOnPageFixed (bf_idx idx) noexcept=0
 Updates the eviction statistics of fixed (i.e. used) pages during eviction. More...
 
virtual void updateOnPageDirty (bf_idx idx) noexcept=0
 Updates the eviction statistics of dirty pages during eviction. More...
 
virtual void updateOnPageBlocked (bf_idx idx) noexcept=0
 Updates the eviction statistics of pages that cannot be evicted at all. More...
 
virtual void updateOnPageSwizzled (bf_idx idx) noexcept=0
 Updates the eviction statistics of pages containing swizzled pointers during eviction. More...
 
virtual void updateOnPageExplicitlyUnbuffered (bf_idx idx) noexcept=0
 Updates the eviction statistics on explicit unbuffer. More...
 
virtual void updateOnPointerSwizzling (bf_idx idx) noexcept=0
 Updates the eviction statistics of pages when its pointer got swizzled in its parent page. More...
 
virtual void releaseInternalLatches () noexcept=0
 Releases the internal latches. More...
 
bool evictOne (bf_idx &victim)
 Evicts a page from the buffer pool. More...
 
- Public Member Functions inherited from worker_thread_t
 worker_thread_t (int inverval_ms=-1)
 
virtual ~worker_thread_t ()
 
void wakeup (bool wait=false, int rounds_to_wait=-1)
 
void stop ()
 
void wait_for_round (long round=0)
 
long get_rounds_completed () const
 
bool is_busy () const
 
- Public Member Functions inherited from thread_wrapper_t
 thread_wrapper_t ()
 
virtual ~thread_wrapper_t ()
 
virtual void before_run ()
 
virtual void after_run ()
 
void spawn ()
 
void fork ()
 
void join ()
 

Protected Member Functions

bool _doEviction (bf_idx victim) noexcept
 Evicts a page from the buffer pool. More...
 
- Protected Member Functions inherited from worker_thread_t
bool should_exit () const
 
void notify_one ()
 
void notify_all ()
 
void quit ()
 

Protected Attributes

const bool _maintainEMLSN
 Maintain the page's EMLSNs on eviction. More...
 
const bool _flushDirty
 Flush dirty pages. More...
 
const bool _logEvictions
 Log page evictions. More...
 
const uint_fast32_t _evictionBatchSize
 Target value of free buffer frames. More...
 
const uint_fast32_t _maxAttempts
 Maximum number of unsuccessful picks of eviction victims. More...
 
const uint_fast32_t _wakeupCleanerAttempts = 42
 Number of unsuccessful picks of eviction victims before waking up the page cleaner. More...
 

Static Protected Attributes

static constexpr bool _enabledSwizzling = POINTER_SWIZZLER::usesPointerSwizzling
 Pointer swizzling used in the buffer pool. More...
 

Private Member Functions

bool _unswizzleAndUpdateEMLSN (bf_idx victim) noexcept
 Unswizzles the pointer in the parent page and updates the EMLSN of that page. More...
 
void _flushDirtyPage (const bf_tree_cb_t &victimControlBlock) noexcept
 Flush the specified page. More...
 
void do_work () override
 Function evicting pages in the eviction thread. More...
 

Detailed Description

Page evictioner for the buffer pool.

This is the abstract class for page eviction which implements common functionality required for all page evictioners independent of the used algorithm. All those page evictioners should inherit from this class.

Note
This class is strongly coupled to the buffer pool and some other components of Zero. The inheriting page evictioners implementing specific page eviction algorithms do not need to be coupled to all those components but should just rely on the implementations of evictOne(), _unswizzleAndUpdateEMLSN(), _flushDirtyPage() and do_work().

Constructor & Destructor Documentation

§ PageEvictioner() [1/2]

zero::buffer_pool::PageEvictioner::PageEvictioner ( const BufferPool bufferPool)
explicit

Constructs an abstract page evictioner.

This constructor initializes the member variables according to specifications of the BufferPool and settings from the sm_options.

Note
Due to the fact that this is a constructor of an abstract class, this can only be called from within the member initializer list of a constructor of an inheriting class.
Parameters
bufferPoolThe buffer pool this page evictioner is responsible for.

§ PageEvictioner() [2/2]

zero::buffer_pool::PageEvictioner::PageEvictioner ( const PageEvictioner )
delete

Explicitly deleted copy constructor of an abstract page evictioner.

The copy constructor of an abstract page evictioner is explicitly removed because a page evictioner depends on its corresponding buffer pool and there can only be one buffer pool per Zero instance.

§ ~PageEvictioner()

zero::buffer_pool::PageEvictioner::~PageEvictioner ( )
virtual

Destructs an abstract page evictioner.

Member Function Documentation

§ _doEviction()

zero::buffer_pool::PageEvictioner::_doEviction ( bf_idx  victim)
protectednoexcept

Evicts a page from the buffer pool.

Evicts the page from the specified buffer pool frame by:

  • Unswizzling its pointer in its parent (if needed)
  • Updating its EMLSN (if needed)
  • Preparing the corresponding bf_tree_cb_t for the eviction
  • Flushing the page to the database (if needed and allowed)
  • Logging the eviction (if supposed to)
  • Adding the page for recovery (if NoDB is used)
  • Removing the page from the Hashtable
  • Releasing the latch of the buffer frame
Postcondition
The buffer frame at index victim is not used (if this is successful) and it is not latched. If _flushDirty is set and if the page was dirty, the page is flushed to the database and if _logEvictions is set, a log record of type evict_page_log is in the log.
Parameters
victimThe index of the buffer frame from which the page should be evicted.
Returns
Returns true if the page could successfully be evicted, otherwise false .

§ _flushDirtyPage()

zero::buffer_pool::PageEvictioner::_flushDirtyPage ( const bf_tree_cb_t victimControlBlock)
privatenoexcept

Flush the specified page.

Writes the specified page to the database file.

Precondition
Specified bf_tree_cb_t is latched in exclusive mode and corresponds to a used buffer frame.
Parameters
victimControlBlockThe control block that corresponds to the buffer frame whose contained page gets flushed.

§ _unswizzleAndUpdateEMLSN()

zero::buffer_pool::PageEvictioner::_unswizzleAndUpdateEMLSN ( bf_idx  victim)
privatenoexcept

Unswizzles the pointer in the parent page and updates the EMLSN of that page.

In case swizzling is enabled, this unswizzles the pointer in the parent page. Additionally, this updates the parent EMLSN. This two operations are kept in a single method because both require looking up the parent, latching, etc., so we save some work.

Parameters
victimThe buffer frame index where the page that gets evicted can be found.
Returns
true if the updates to the parent page were successfully completed and not required, false otherwise.

§ do_work()

zero::buffer_pool::PageEvictioner::do_work ( )
overrideprivatevirtual

Function evicting pages in the eviction thread.

Runs in the eviction thread (executed when the eviction thread gets woken up and when terminated it terminates the eviction thread) and evicts pages as long as there are not _evictionBatchSize free buffer frames in the BufferPool.

Implements worker_thread_t.

§ evictOne()

zero::buffer_pool::PageEvictioner::evictOne ( bf_idx victim)

Evicts a page from the buffer pool.

Selects a page for eviction and executes the eviction of it.

Parameters
[out]victimThe index of the buffer frame from which the page was evicted.
Returns
Returns true if the victim could successfully be evicted, otherwise false .

§ operator=()

zero::buffer_pool::PageEvictioner::operator= ( const PageEvictioner )
delete

Explicitly deleted assignment operator of an abstract page evictioner.

The assignment operator of an abstract page evictioner is explicitly removed because a page evictioner depends on its corresponding buffer pool and there can only be one buffer pool per Zero instance.

§ pickVictim()

zero::buffer_pool::PageEvictioner::pickVictim ( )
pure virtualnoexcept

Selects a page to be evicted from the buffer pool.

Selects a page to be evicted according to the selected page eviction strategy.

Postcondition
The picked victim is latched in latch_mode_t::LATCH_EX mode as the buffer pool frame will be changed during eviction (page will be removed).
Note
This member function must be implemented by every specific page evictioner which inherits from this abstract page evictioner.
Returns
The buffer frame that can be freed or 0 if no eviction victim could be found.

Implemented in zero::buffer_pool::PageEvictionerSelectAndFilter< selector_class, filter_class, filter_early >, zero::buffer_pool::PageEvictionerCAR< on_page_unfix >, and zero::buffer_pool::PageEvictionerLeanStore< cooling_stage_size_ppm >.

§ releaseInternalLatches()

zero::buffer_pool::PageEvictioner::releaseInternalLatches ( )
pure virtualnoexcept

Releases the internal latches.

Some methods of page evictioners hold internal latches beyond the invocation of one method but expect another method to be called later to release those internal latches. This should be used to explicitly release those latches.

Implemented in zero::buffer_pool::PageEvictionerCAR< on_page_unfix >, zero::buffer_pool::PageEvictionerSelectAndFilter< selector_class, filter_class, filter_early >, and zero::buffer_pool::PageEvictionerLeanStore< cooling_stage_size_ppm >.

§ updateOnPageBlocked()

zero::buffer_pool::PageEvictioner::updateOnPageBlocked ( bf_idx  idx)
pure virtualnoexcept

Updates the eviction statistics of pages that cannot be evicted at all.

Updates the statistics according to the selected page eviction strategy when a page cannot be evicted at all.

Note
This member function must be implemented by every specific page evictioner which inherits from this abstract page evictioner.
Parameters
idxThe buffer frame index of the BufferPool which corresponding frame contains a page that cannot be evicted at all.

Implemented in zero::buffer_pool::PageEvictionerCAR< on_page_unfix >, zero::buffer_pool::PageEvictionerSelectAndFilter< selector_class, filter_class, filter_early >, and zero::buffer_pool::PageEvictionerLeanStore< cooling_stage_size_ppm >.

§ updateOnPageDirty()

zero::buffer_pool::PageEvictioner::updateOnPageDirty ( bf_idx  idx)
pure virtualnoexcept

Updates the eviction statistics of dirty pages during eviction.

Updates the statistics according to the selected page eviction strategy when a page was discovered dirty during eviction.

Note
This member function must be implemented by every specific page evictioner which inherits from this abstract page evictioner.
Parameters
idxThe buffer frame index of the BufferPool that was picked for eviction while the corresponding frame contained a dirty page.

Implemented in zero::buffer_pool::PageEvictionerCAR< on_page_unfix >, and zero::buffer_pool::PageEvictionerSelectAndFilter< selector_class, filter_class, filter_early >.

§ updateOnPageExplicitlyUnbuffered()

zero::buffer_pool::PageEvictioner::updateOnPageExplicitlyUnbuffered ( bf_idx  idx)
pure virtualnoexcept

Updates the eviction statistics on explicit unbuffer.

Updates the statistics according to the selected page eviction strategy when a page got explicitly unbuffered.

Note
This member function must be implemented by every specific page evictioner which inherits from this abstract page evictioner.
Parameters
idxThe buffer frame index of the BufferPool whose corresponding frame is freed explicitly.

Implemented in zero::buffer_pool::PageEvictionerCAR< on_page_unfix >, zero::buffer_pool::PageEvictionerSelectAndFilter< selector_class, filter_class, filter_early >, and zero::buffer_pool::PageEvictionerLeanStore< cooling_stage_size_ppm >.

§ updateOnPageFixed()

zero::buffer_pool::PageEvictioner::updateOnPageFixed ( bf_idx  idx)
pure virtualnoexcept

Updates the eviction statistics of fixed (i.e. used) pages during eviction.

Updates the statistics according to the selected page eviction strategy when a page was discovered fixed during eviction.

Note
This member function must be implemented by every specific page evictioner which inherits from this abstract page evictioner.
Parameters
idxThe buffer frame index of the BufferPool that was picked for eviction while the corresponding frame was fixed.

Implemented in zero::buffer_pool::PageEvictionerCAR< on_page_unfix >, zero::buffer_pool::PageEvictionerSelectAndFilter< selector_class, filter_class, filter_early >, and zero::buffer_pool::PageEvictionerLeanStore< cooling_stage_size_ppm >.

§ updateOnPageHit()

zero::buffer_pool::PageEvictioner::updateOnPageHit ( bf_idx  idx)
pure virtualnoexcept

Updates the eviction statistics on page hit.

Updates the statistics according to the selected page eviction strategy when a page hit occurred.

Warning
If a page eviction strategy is sensitive to recognizing the same page reference multiple times, implement this different from updateOnPageUnfix().
Note
This member function must be implemented by every specific page evictioner which inherits from this abstract page evictioner.
Parameters
idxThe buffer frame index of the BufferPool on which a page hit occurred.

Implemented in zero::buffer_pool::PageEvictionerCAR< on_page_unfix >, zero::buffer_pool::PageEvictionerSelectAndFilter< selector_class, filter_class, filter_early >, and zero::buffer_pool::PageEvictionerLeanStore< cooling_stage_size_ppm >.

§ updateOnPageMiss()

zero::buffer_pool::PageEvictioner::updateOnPageMiss ( bf_idx  idx,
PageID  pid 
)
pure virtualnoexcept

Updates the eviction statistics on page miss.

Updates the statistics according to the selected page eviction strategy when a page miss occurred.

Note
This member function must be implemented by every specific page evictioner which inherits from this abstract page evictioner.
Parameters
idxThe buffer frame index of the BufferPool on which a page miss occurred.
pidThe PageID of the generic_page that was loaded into the buffer frame with index idx .

Implemented in zero::buffer_pool::PageEvictionerCAR< on_page_unfix >, zero::buffer_pool::PageEvictionerSelectAndFilter< selector_class, filter_class, filter_early >, and zero::buffer_pool::PageEvictionerLeanStore< cooling_stage_size_ppm >.

§ updateOnPageSwizzled()

zero::buffer_pool::PageEvictioner::updateOnPageSwizzled ( bf_idx  idx)
pure virtualnoexcept

Updates the eviction statistics of pages containing swizzled pointers during eviction.

Updates the statistics according to the selected page eviction strategy when a page was discovered containing swizzled pointers during eviction.

Note
This member function must be implemented by every specific page evictioner which inherits from this abstract page evictioner.
Parameters
idxThe buffer frame index of the BufferPool that was picked for eviction while the corresponding frame contained a page with swizzled pointers.

Implemented in zero::buffer_pool::PageEvictionerCAR< on_page_unfix >, zero::buffer_pool::PageEvictionerSelectAndFilter< selector_class, filter_class, filter_early >, and zero::buffer_pool::PageEvictionerLeanStore< cooling_stage_size_ppm >.

§ updateOnPageUnfix()

zero::buffer_pool::PageEvictioner::updateOnPageUnfix ( bf_idx  idx)
pure virtualnoexcept

Updates the eviction statistics on page unfix.

Updates the statistics according to the selected page eviction strategy when a page unfix occurred.

Warning
If a page eviction strategy is sensitive to recognizing the same page reference multiple times, implement this different from updateOnPageHit().
Note
This member function must be implemented by every specific page evictioner which inherits from this abstract page evictioner.
Parameters
idxThe buffer frame index of the BufferPool on which a page unfix occurred.

Implemented in zero::buffer_pool::PageEvictionerCAR< on_page_unfix >, zero::buffer_pool::PageEvictionerSelectAndFilter< selector_class, filter_class, filter_early >, and zero::buffer_pool::PageEvictionerLeanStore< cooling_stage_size_ppm >.

§ updateOnPointerSwizzling()

zero::buffer_pool::PageEvictioner::updateOnPointerSwizzling ( bf_idx  idx)
pure virtualnoexcept

Updates the eviction statistics of pages when its pointer got swizzled in its parent page.

Updates the statistics according to the selected page eviction strategy when the pointer of a page got swizzled in its parent page.

Note
This member function must be implemented by every specific page evictioner which inherits from this abstract page evictioner.
Parameters
idxThe buffer frame index of the BufferPool whose pointer got swizzled in its corresponding parent page.

Implemented in zero::buffer_pool::PageEvictionerCAR< on_page_unfix >, zero::buffer_pool::PageEvictionerSelectAndFilter< selector_class, filter_class, filter_early >, and zero::buffer_pool::PageEvictionerLeanStore< cooling_stage_size_ppm >.

Member Data Documentation

§ _enabledSwizzling

zero::buffer_pool::PageEvictioner::_enabledSwizzling = POINTER_SWIZZLER::usesPointerSwizzling
staticprotected

Pointer swizzling used in the buffer pool.

Set if the BufferPool uses pointer swizzling for page references.

§ _evictionBatchSize

zero::buffer_pool::PageEvictioner::_evictionBatchSize
protected

Target value of free buffer frames.

Once page evictioning is started, it runs till there are this many free buffer frames in the BufferPool.

§ _flushDirty

zero::buffer_pool::PageEvictioner::_flushDirty
protected

Flush dirty pages.

Set if dirty pages should be flushed when they get evicted from the buffer pool.

§ _logEvictions

zero::buffer_pool::PageEvictioner::_logEvictions
protected

Log page evictions.

Set if a log record should be created for each eviction of a page.

§ _maintainEMLSN

zero::buffer_pool::PageEvictioner::_maintainEMLSN
protected

Maintain the page's EMLSNs on eviction.

Set if the EMLSNs of the pages should be maintained.

§ _maxAttempts

zero::buffer_pool::PageEvictioner::_maxAttempts
protected

Maximum number of unsuccessful picks of eviction victims.

Maximum number of picks of pages in a row that cannot be evicted before an error ("Eviction got stuck!") is thrown.

§ _wakeupCleanerAttempts

zero::buffer_pool::PageEvictioner::_wakeupCleanerAttempts = 42
protected

Number of unsuccessful picks of eviction victims before waking up the page cleaner.

Number of picks of pages in a row that cannot be evicted before the page cleaner of the BufferPool gets woken up (BufferPool::wakeupPageCleaner()).

Remarks
Dirty pages that need to get cleaned are a typical reason for stuck page evictions.

The documentation for this class was generated from the following files: