Zero  0.1.0
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
zero::buffer_pool::BufferPool Class Reference

A buffer manager that exploits the tree structure of indexes. More...

#include <buffer_pool.hpp>

Public Member Functions

 BufferPool ()
 Default constructor for a buffer pool. More...
 
void postInitialize ()
 Completes the initialization of this buffer pool. More...
 
void shutdown ()
 Shuts down this buffer pool. More...
 
 ~BufferPool ()
 Default destructor for a buffer pool. More...
 
bf_idx getBlockCount () const noexcept
 Number of buffer frames of this buffer pool. More...
 
bool isNoDBMode () const noexcept
 Whether this buffer pool is in NoDB mode. More...
 
bool usesWriteElision () const noexcept
 Whether this buffer pool uses write elision. More...
 
bool isWarmupDone () const noexcept
 Return whether this buffer pool is already "warmed up". More...
 
const std::shared_ptr< zero::buffer_pool::HashtablegetHashtable () const noexcept
 Returns the hashtable of this buffer pool. More...
 
const std::shared_ptr< zero::buffer_pool::FreeListLowContentiongetFreeList () const noexcept
 Returns the free list of this buffer pool. More...
 
const std::shared_ptr< page_cleaner_basegetPageCleaner () const noexcept
 Returns the page cleaner of this buffer pool. More...
 
void wakeupPageCleaner () const
 
const std::shared_ptr< PAGE_EVICTIONER > getPageEvictioner () const noexcept
 Returns the page evictioner of this buffer pool. More...
 
bool hasDirtyFrames ()
 Whether this buffer pool has dirty buffer frames. More...
 
void fixRoot (generic_page *&targetPage, StoreID store, latch_mode_t latchMode, bool conditional, bool virgin)
 Fixes a root B-Tree page in this buffer pool. More...
 
w_rc_t fixRootOldStyleExceptions (generic_page *&targetPage, StoreID store, latch_mode_t latchMode, bool conditional, bool virgin)
 
bool fixNonRoot (generic_page *&targetPage, generic_page *parentPage, PageID pid, latch_mode_t latchMode, bool conditional=false, bool virgin=false, bool onlyIfHit=false, bool doRecovery=true, lsn_t emlsn=lsn_t::null)
 Fixes a non-root B-Tree page in this buffer pool. More...
 
w_rc_t fixNonRootOldStyleExceptions (generic_page *&targetPage, generic_page *parentPage, PageID pid, latch_mode_t latchMode, bool conditional=false, bool virgin=false, bool onlyIfHit=false, bool doRecovery=true, lsn_t emlsn=lsn_t::null)
 
bf_idx pinForRefix (const generic_page *pinPage)
 Pin a page for a cheaper re-fix. More...
 
void refixDirect (generic_page *&targetPage, bf_idx refixIndex, latch_mode_t latchMode, bool conditional)
 Re-fix a pinned page. More...
 
w_rc_t refixDirectOldSytleExceptions (generic_page *&targetPage, bf_idx refixIndex, latch_mode_t latchMode, bool conditional)
 
void unpinForRefix (bf_idx unpinIndex)
 Unpin a page for re-fix. More...
 
void unfix (const generic_page *unfixPage, bool evict=false)
 Unfixes a page in this buffer pool. More...
 
bf_tree_cb_tgetControlBlock (bf_idx index) noexcept
 Returns the control block corresponding to a buffer pool index. More...
 
const bf_tree_cb_tgetControlBlock (bf_idx index) const noexcept
 Returns the control block corresponding to a buffer pool index. noexcept More...
 
bf_tree_cb_tgetControlBlock (const generic_page *page) noexcept
 Returns the control block corresponding to a buffered page. More...
 
bf_idx getIndex (const bf_tree_cb_t &controlBlock) const noexcept
 The buffer pool index of a control block. More...
 
bf_idx getIndex (const generic_page *page) const noexcept
 The buffer pool index of a buffered page. More...
 
bf_idx getRootIndex (StoreID store) const noexcept
 The buffer pool index of a buffered B-Tree root page. More...
 
generic_pagegetPage (const bf_idx &index) noexcept
 A buffered page at a buffer pool index. More...
 
const generic_pagegetPage (const bf_idx &index) const noexcept
 A buffered page at a buffer pool index. noexcept More...
 
bool isValidIndex (bf_idx index) const noexcept
 Checks the validity of a buffer pool index in this buffer pool. More...
 
bool isActiveIndex (bf_idx index) const noexcept
 Checks whether a buffer pool frame is used in this buffer pool. More...
 
bool upgradeLatchConditional (const generic_page *page) noexcept
 Upgrade the latch of a page. More...
 
void downgradeLatch (const generic_page *page) noexcept
 Downgrade the latch of a page. More...
 
bool unswizzlePagePointer (generic_page *parentPage, general_recordid_t childSlotInParentPage, PageID *childPageID=nullptr)
 Unswizzle a page pointer in a page's parent page. More...
 
PageID normalizePID (const PageID pid) const noexcept
 Normalize a page ID. More...
 
bool isEvictable (const bf_idx indexToCheck, const bool doFlushIfDirty) noexcept
 Check if a page can be evicted. More...
 
void batchPrefetch (PageID startPID, bf_idx numberOfPages) noexcept
 Prefetches a batch of pages into this buffer pool. More...
 
void recoverIfNeeded (bf_tree_cb_t &controlBlock, generic_page *page, bool onlyIfDirty=true) noexcept
 Recover buffered page if needed. More...
 
void fuzzyCheckpoint (chkpt_t &checkpoint) const noexcept
 Creates a fuzzy checkpoint for this buffer pool. More...
 
void sxUpdateChildEMLSN (btree_page_h &parentPage, general_recordid_t childSlotID, lsn_t childEMLSN) const
 Update the EMLSN of a B-Tree child inside its parent page. More...
 
void switchParent (PageID childPID, generic_page *newParentPage) noexcept
 Switch the parent page of a buffered B-Tree page in this buffer pool. More...
 
void setMediaFailure () noexcept
 MG TODO. More...
 
void unsetMediaFailure () noexcept
 MG TODO. More...
 
PageID getMediaFailurePID () const noexcept
 MG TODO. More...
 
bool isMediaFailure () const noexcept
 
bool isMediaFailure (PageID pid) const noexcept
 MG TODO. More...
 
void debugDump (std::ostream &o) const
 Dumps some meta data of this buffer pool to an output stream. More...
 
void debugDumpPagePointers (std::ostream &o, generic_page *page) const
 Dumps the pointers stored inside a page to an output stream. More...
 

Private Types

using RestoreCoord = RestoreCoordinator< std::function< decltype(SegmentRestorer::bf_restore)>>
 
using BgRestorer = BackgroundRestorer< RestoreCoord, std::function< void(void)>>
 

Private Member Functions

bool _fix (generic_page *parentPage, generic_page *&targetPage, PageID pid, latch_mode_t latchMode, bool conditional, bool virgin, bool onlyIfHit=false, bool doRecovery=true, lsn_t emlsn=lsn_t::null)
 Fixes a page in this buffer pool. More...
 
void _convertToDiskPage (generic_page *page) const noexcept
 Converts an image of a page with swizzled pointers to one without. More...
 
void _readPage (PageID pid, generic_page *targetPage, bool fromBackup=false)
 Reads a page from database or backup. More...
 
void _deletePage (bf_idx index) noexcept
 Deletes a page from this buffer pool. More...
 
void _checkWarmupDone () noexcept
 Decides if this buffer pool is "warmed up". More...
 
void _setWarmupDone () noexcept
 Sets this buffer pool to "warmed up". More...
 

Private Attributes

bf_idx _blockCount
 Maximum number of pages in this buffer pool. More...
 
std::array< bf_idx, stnode_page::max_rootPages
 Buffer indexes of root pages. More...
 
std::vector< bf_tree_cb_t, boost::alignment::aligned_allocator< bf_tree_cb_t, sizeof(bf_tree_cb_t)> > _controlBlocks
 Array of control blocks. More...
 
generic_page_buffer
 Array of buffered pages. More...
 
std::shared_ptr< Hashtable_hashtable
 Allows to locate pages by PageID. More...
 
std::shared_ptr< FreeListLowContention_freeList
 List of unused buffer frames. More...
 
std::shared_ptr< page_cleaner_base_cleaner
 Cleans dirty pages. More...
 
bool _cleanerDecoupled
 Use log-based "decoupled" cleaner. More...
 
std::shared_ptr< PAGE_EVICTIONER > _evictioner
 Evicts pages. More...
 
bool _asyncEviction
 Use a dedicated thread for eviction. More...
 
bool _maintainEMLSN
 Maintain EMLSN of B-Tree pages. More...
 
std::shared_ptr< RestoreCoord_restoreCoordinator
 MG TODO. More...
 
std::shared_ptr< BgRestorer_backgroundRestorer
 MG TODO. More...
 
bool _useWriteElision
 Use write elision. More...
 
std::atomic< PageID_mediaFailurePID
 MG TODO. More...
 
bool _instantRestore
 Use instant restore. More...
 
bool _noDBMode
 Use NoDB. More...
 
bool _logFetches
 Log page fetches. More...
 
size_t _batchSegmentSize
 MG TODO. More...
 
bool _batchWarmup
 MG TODO. More...
 
bool _warmupDone
 MG TODO. More...
 
double _warmupHitRatio
 Hit rate of a "warm" buffer pool. More...
 
unsigned _warmupMinFixes
 Minimum number of fixes of a "warm" buffer pool. More...
 

Static Private Attributes

static thread_local SprIterator _localSprIter
 Single-page-recovery iterator used for instant restart redo. More...
 
static thread_local unsigned _fixCount = 0
 MG TODO. More...
 
static thread_local unsigned _hitCount = 0
 MG TODO. More...
 

Friends

class ::test_bf_tree
 
class ::bf_tree_cleaner
 
class page_cleaner_decoupled
 
class ::GenericPageIterator
 
class FreeListLowContention
 
class FreeListHighContention
 
class PageEvictioner
 
template<class selector_class , class filter_class , bool filter_early>
class PageEvictionerSelectAndFilter
 

Detailed Description

A buffer manager that exploits the tree structure of indexes.

This buffer manager only deals with tree-structured stores such as B-trees.

Member Typedef Documentation

§ BgRestorer

using zero::buffer_pool::BufferPool::BgRestorer = BackgroundRestorer<RestoreCoord, std::function<void(void)>>
private

§ RestoreCoord

Constructor & Destructor Documentation

§ BufferPool()

zero::buffer_pool::BufferPool::BufferPool ( )

Default constructor for a buffer pool.

Constructs an almost completely initialized buffer pool according to the settings set in ss_m::get_options() .

Postcondition
The buffer pool is partially initialized.
Warning
The buffer pool is only fully initialized after calling postInitialize .

§ ~BufferPool()

zero::buffer_pool::BufferPool::~BufferPool ( )

Default destructor for a buffer pool.

Due to the usage of smart pointers, all this destructor does is implicit.

Warning
Due to forked threads, the buffer pool needs to be shut down before destruction using shutdown .

Member Function Documentation

§ _checkWarmupDone()

zero::buffer_pool::BufferPool::_checkWarmupDone ( )
privatenoexcept

Decides if this buffer pool is "warmed up".

Decides if this buffer pool is "warmed up" by looking at the hit ratio observed for the current thread and the total number of page fixes done by this thread. This is for cases where the dataset fits in main memory and the buffer pool never (or just takes really long to) fill up.

§ _convertToDiskPage()

zero::buffer_pool::BufferPool::_convertToDiskPage ( generic_page page) const
privatenoexcept

Converts an image of a page with swizzled pointers to one without.

Converts an image of a page (buffered in this buffer pool) with swizzled pointers to a disk page without swizzled pointers. This is mainly used to write out dirty pages.

Precondition
Hold the latch corresponding to the page in either latch_mode_t::LATCH_SH or latch_mode_t::LATCH_EX .
Parameters
pageThe page with swizzled pointers to convert to a disk page.

§ _deletePage()

zero::buffer_pool::BufferPool::_deletePage ( bf_idx  index)
privatenoexcept

Deletes a page from this buffer pool.

Makes the buffer frame which corresponds to the specified buffer index unoccupied.

Precondition
The buffer frame corresponding the buffer index is occupied, it is not fixed by any thread and if it contains a non-root B-Tree page, the corresponding pointer is not swizzled in its parent page (the page is not pinned).
Parameters
indexThe buffer index of the buffer pool frame to be freed.

§ _fix()

zero::buffer_pool::BufferPool::_fix ( generic_page parentPage,
generic_page *&  targetPage,
PageID  pid,
latch_mode_t  latchMode,
bool  conditional,
bool  virgin,
bool  onlyIfHit = false,
bool  doRecovery = true,
lsn_t  emlsn = lsn_t::null 
)
private

Fixes a page in this buffer pool.

If pointer swizzling is enabled, this receives the requested page's parent page and efficiently fixes the requested page if the pid is already swizzled by inside the parent page. If it is not already swizzled, it will be swizzled after the execution of this. The optimization is transparent for most of the code because the page ID stored in the parent page is automatically (and atomically) changed to a swizzled pointer by the buffer pool.
If pointer swizzling is disabled, this fixes the requested page in this buffer pool.

Precondition
The parentPage set and latched. Otherwise use fixable_page_h.fix_direct(PageID pid, latch_mode_t mode, bool conditional, bool virgin_page, bool only_if_hit, bool do_recovery) .
Postcondition
The targetPage pointer points to the page which should have been fixed and it is latched in the wanted mode.
Parameters
[in]parentPageThis is the parent of the page to be fixed. If the page is either represents a root of a B-Tree or is not a B-Tree page this see the prerequisites.
[out]targetPageThis page should contain the fixed page.
[in]pidPage ID of the requested page to be fixed (or buffer pool index with swizzledPIDBit set when swizzled).
[in]latchModeThe wanted latch mode for the page that should be fixed (only latch_mode_t::LATCH_SH and latch_mode_t::LATCH_EX are allowed here).
[in]conditionalWhether the fix is conditional (returns immediately even if failed).
[in]virginWhether the page is a new page thus does not have to be read from disk.
[in]onlyIfHitThe fix is only performed if the requested page is already buffered in this buffer pool (i.e., a page hit occurs)
[in]doRecoveryWhether recovery should be enabled for this page.
[in]emlsnThe EMLSN of the requested page.
Returns
If onlyIfHit is set and it is a page miss false , else true .

§ _readPage()

zero::buffer_pool::BufferPool::_readPage ( PageID  pid,
generic_page targetPage,
bool  fromBackup = false 
)
private

Reads a page from database or backup.

Reads a page from database or backup into a buffer frame of this buffer pool. The source of the page needs to be selected explicitly.

Precondition
Hold the latch corresponding to the targetPage in latch_mode_t::LATCH_EX .
Parameters
pidThe page ID of the page to read.
targetPageThe page should be read into this page image.
fromBackupWhether the page should be read from the backup or from the database.

§ _setWarmupDone()

zero::buffer_pool::BufferPool::_setWarmupDone ( )
privatenoexcept

Sets this buffer pool to "warmed up".

§ batchPrefetch()

zero::buffer_pool::BufferPool::batchPrefetch ( PageID  startPID,
bf_idx  numberOfPages 
)
noexcept

Prefetches a batch of pages into this buffer pool.

Prefetches a continuous batch of pages into this buffer pool using preadv . This allows a faster restore process without traversing the B-Tree.

Parameters
startPIDThe page ID of the first page in the continuous batch of pages to prefetch.
numberOfPagesThe number of pages to prefetch (page ID of the last prefetched page: startPID + numberOfPages - 1 ).
Warning
It is not guaranteed for a non-root B-Tree page that its parent page is also prefetched.
The parent page information of non-root B-Tree pages is not properly set in the hashtable.

§ debugDump()

zero::buffer_pool::BufferPool::debugDump ( std::ostream &  o) const

Dumps some meta data of this buffer pool to an output stream.

Dumps some general meta data of this buffer pool and of the first 1000 buffer pool frames to the specified output stream. See the implementation for more details! The data is multi-lined and cannot be manipulated using stream manipulators.

Parameters
oThe output stream to which the meta data are printed.
Warning
This function is only for debug purposes because it is slow and unsafe.

§ debugDumpPagePointers()

zero::buffer_pool::BufferPool::debugDumpPagePointers ( std::ostream &  o,
generic_page page 
) const

Dumps the pointers stored inside a page to an output stream.

Dumps the pointers (accounting for swizzling) of a given page to the specified output stream. See the implementation for more details! The data is single-lined and cannot be manipulated using stream manipulators.

Parameters
oThe output stream to which the pointers are printed.
pageThe page whose contained pointers are printed.
Warning
This function is only for debug purposes because it is slow and unsafe.

§ downgradeLatch()

zero::buffer_pool::BufferPool::downgradeLatch ( const generic_page page)
noexcept

Downgrade the latch of a page.

Downgrade this thread holding the latch of a page in latch_mode_t::LATCH_EX to one holding the latch in latch_mode_t::LATCH_SH .

Parameters
pageThe latch corresponding to this page should be downgraded.

§ fixNonRoot()

zero::buffer_pool::BufferPool::fixNonRoot ( generic_page *&  targetPage,
generic_page parentPage,
PageID  pid,
latch_mode_t  latchMode,
bool  conditional = false,
bool  virgin = false,
bool  onlyIfHit = false,
bool  doRecovery = true,
lsn_t  emlsn = lsn_t::null 
)

Fixes a non-root B-Tree page in this buffer pool.

If pointer swizzling is enabled, this receives the requested page's parent page and efficiently fixes the requested page if the pid is already swizzled by inside the parent page. If it is not already swizzled, it will be swizzled after the execution of this. The optimization is transparent for most of the code because the page ID stored in the parent page is automatically (and atomically) changed to a swizzled pointer by the buffer pool.
If pointer swizzling is disabled, this fixes the requested page in this buffer pool.

Precondition
The parentPage set and latched. Otherwise use fixable_page_h.fix_direct(PageID pid, latch_mode_t mode, bool conditional, bool virgin_page, bool only_if_hit, bool do_recovery) .
Postcondition
The targetPage pointer points to the page which should have been fixed and it is latched in the wanted mode.
Parameters
[out]targetPageThis page should contain the fixed page.
[in]parentPageThis is the parent of the page to be fixed. If the page is either represents a root of a B-Tree or is not a B-Tree page this see the prerequisites.
[in]pidPage ID of the requested page to be fixed (or buffer pool index with swizzledPIDBit set when swizzled).
[in]latchModeThe wanted latch mode for the page that should be fixed (only latch_mode_t::LATCH_SH and latch_mode_t::LATCH_EX are allowed here).
[in]conditionalWhether the fix is conditional (returns immediately even if failed).
[in]virginWhether the page is a new page thus does not have to be read from disk.
[in]onlyIfHitThe fix is only performed if the requested page is already buffered in this buffer pool (i.e., a page hit occurs)
[in]doRecoveryWhether recovery should be enabled for this page.
[in]emlsnThe EMLSN of the requested page.
Returns
If onlyIfHit is set and it is a page miss false , else true .

§ fixNonRootOldStyleExceptions()

w_rc_t BufferPool::fixNonRootOldStyleExceptions ( generic_page *&  targetPage,
generic_page parentPage,
PageID  pid,
latch_mode_t  latchMode,
bool  conditional = false,
bool  virgin = false,
bool  onlyIfHit = false,
bool  doRecovery = true,
lsn_t  emlsn = lsn_t::null 
)

§ fixRoot()

zero::buffer_pool::BufferPool::fixRoot ( generic_page *&  targetPage,
StoreID  store,
latch_mode_t  latchMode,
bool  conditional,
bool  virgin 
)

Fixes a root B-Tree page in this buffer pool.

Fixes an existing (not virgin) root B-Tree page of a given store in this buffer pool.

Postcondition
The targetPage pointer points to the page which should have been fixed and it is latched in the wanted mode.
Parameters
[out]targetPageThis page should contain the fixed page.
[in]storeStore ID of the store whose root B-Tree page is requested to be fixed.
[in]latchModeThe wanted latch mode for the page that should be fixed (only latch_mode_t::LATCH_SH and latch_mode_t::LATCH_EX are allowed here).
[in]conditionalWhether the fix is conditional (returns immediately even if failed).
[in]virginWhether the page is a new page thus does not have to be read from disk.

§ fixRootOldStyleExceptions()

w_rc_t BufferPool::fixRootOldStyleExceptions ( generic_page *&  targetPage,
StoreID  store,
latch_mode_t  latchMode,
bool  conditional,
bool  virgin 
)

§ fuzzyCheckpoint()

zero::buffer_pool::BufferPool::fuzzyCheckpoint ( chkpt_t checkpoint) const
noexcept

Creates a fuzzy checkpoint for this buffer pool.

Adds the information required for a fuzzy checkpoint of this buffer pool to the given checkpoint. A fuzzy checkpoint of this buffer pool contains all the page IDs of potentially dirty pages buffered in this buffer pool together with their LSNs.

Postcondition
The checkpoint contains a fuzzy checkpoint of this buffer pool.
Parameters
[in,out]checkpointA fuzzy checkpoint.

§ getBlockCount()

bf_idx zero::buffer_pool::BufferPool::getBlockCount ( ) const
inlinenoexcept

Number of buffer frames of this buffer pool.

Returns
The number of buffer pool frames (_blockCount) of this buffer pool.

§ getControlBlock() [1/3]

bf_tree_cb_t & zero::buffer_pool::BufferPool::getControlBlock ( bf_idx  index)
inlinenoexcept

Returns the control block corresponding to a buffer pool index.

Returns the control block which corresponds to the buffer frame at the given buffer pool index. Due to the allocation scheme used in _controlBlocks , it is not trivial (but possible in constant time) to find the requested control block.

Parameters
indexA buffer pool index corresponding to a buffer frame of this buffer pool.
Returns
The control block corresponding to the buffer frame of the given buffer pool index.

§ getControlBlock() [2/3]

const bf_tree_cb_t& zero::buffer_pool::BufferPool::getControlBlock ( bf_idx  index) const
inlinenoexcept

Returns the control block corresponding to a buffer pool index. noexcept

Returns the control block which corresponds to the buffer frame at the given buffer pool index. Due to the allocation scheme used in _controlBlocks , it is not trivial (but possible in constant time) to find the requested control block.

Parameters
indexA buffer pool index corresponding to a buffer frame of this buffer pool.
Returns
The control block corresponding to the buffer frame of the given buffer pool index. noexcept

§ getControlBlock() [3/3]

bf_tree_cb_t & zero::buffer_pool::BufferPool::getControlBlock ( const generic_page page)
inlinenoexcept

Returns the control block corresponding to a buffered page.

Returns the control block which corresponds to the buffer frame of a given buffered page. Due to the allocation scheme used in _controlBlocks , it is not trivial (but possible in constant time) to find the requested control block.

Parameters
pageA page buffered in this buffer pool.
Returns
The control block corresponding to the buffer frame of the given buffered page.
Warning
Unwanted behaviour if the given page is not buffered in this buffer pool!

§ getFreeList()

zero::buffer_pool::BufferPool::getFreeList ( ) const
inlinenoexcept

Returns the free list of this buffer pool.

Returns
The free list holding a queue of unoccupied buffer frames of this buffer pool.

§ getHashtable()

zero::buffer_pool::BufferPool::getHashtable ( ) const
inlinenoexcept

Returns the hashtable of this buffer pool.

Returns
The hashtable mapping page IDs of pages buffered in this buffer pool to the corresponding buffer indexes of them and their parent pages.

§ getIndex() [1/2]

zero::buffer_pool::BufferPool::getIndex ( const bf_tree_cb_t controlBlock) const
inlinenoexcept

The buffer pool index of a control block.

Returns the buffer pool index to which the given control block corresponds to.

Parameters
controlBlockA control block of this buffer pool.
Returns
The buffer pool index to which controlBlock corresponds to.

§ getIndex() [2/2]

zero::buffer_pool::BufferPool::getIndex ( const generic_page page) const
inlinenoexcept

The buffer pool index of a buffered page.

Returns the buffer pool index in which the given buffered page is buffered in.

Parameters
pageA page buffered in this buffer pool.
Returns
The buffer pool index in which page is buffered in.

§ getMediaFailurePID()

zero::buffer_pool::BufferPool::getMediaFailurePID ( ) const
inlinenoexcept

MG TODO.

MG TODO

Returns
MG TODO

§ getPage() [1/2]

generic_page * zero::buffer_pool::BufferPool::getPage ( const bf_idx index)
inlinenoexcept

A buffered page at a buffer pool index.

Returns the page which is buffered at a given buffer pool index in this buffer pool.

Parameters
indexA buffer index of this buffer pool.
Returns
The page which is buffered in the buffer frame with buffer index index .
Note
Mainly for debugging!

§ getPage() [2/2]

const generic_page* zero::buffer_pool::BufferPool::getPage ( const bf_idx index) const
inlinenoexcept

A buffered page at a buffer pool index. noexcept

Returns the page which is buffered at a given buffer pool index in this buffer pool.

Parameters
indexA buffer index of this buffer pool.
Returns
The page which is buffered in the buffer frame with buffer index index .
Note
Mainly for debugging! noexcept

§ getPageCleaner()

zero::buffer_pool::BufferPool::getPageCleaner ( ) const
inlinenoexcept

Returns the page cleaner of this buffer pool.

Returns
The page cleaner thread responsible to write-back dirty pages of this buffer pool.

§ getPageEvictioner()

zero::buffer_pool::BufferPool::getPageEvictioner ( ) const
noexcept

Returns the page evictioner of this buffer pool.

Returns
The page evictioner (thread) responsible evict pages from this buffer pool once its full.

§ getRootIndex()

zero::buffer_pool::BufferPool::getRootIndex ( StoreID  store) const
inlinenoexcept

The buffer pool index of a buffered B-Tree root page.

Returns the buffer pool index in which a B-Tree root page specified by its Store ID is buffered in.

Parameters
storeThe Store ID of the requested B-Tree root page.
Returns
The buffer pool index where the requested B-Tree root page is buffered in this buffer pool or 0 if it is currently not buffered in this buffer pool.

§ hasDirtyFrames()

zero::buffer_pool::BufferPool::hasDirtyFrames ( )

Whether this buffer pool has dirty buffer frames.

Checks each frame of the buffer pool whether it contains a page and whether this page is dirty inside the buffer pool frame. In NoDB mode, pages cannot be dirty.

Returns
true if this buffer pool contains dirty buffer frames, false else.

§ isActiveIndex()

zero::buffer_pool::BufferPool::isActiveIndex ( bf_idx  index) const
inlinenoexcept

Checks whether a buffer pool frame is used in this buffer pool.

Whether the given buffer pool index is in the range of valid buffer pool indexes of this buffer pool (0 is invalid and too large indexes are invalid, too) and whether it is occupied by a page.

Precondition
Hold the latch corresponding to the buffer pool index in latch_mode_t::LATCH_SH or latch_mode_t::LATCH_EX .
Parameters
indexThe buffer pool index to be checked.
Returns
Whether index is a valid buffer pool index in this buffer pool and whether a page is buffered in the corresponding buffer frame.

§ isEvictable()

zero::buffer_pool::BufferPool::isEvictable ( const bf_idx  indexToCheck,
const bool  doFlushIfDirty 
)
noexcept

Check if a page can be evicted.

The following conditions make a page unevictable:

Precondition
The buffer frame with index indexToCheck is latched in latch_mode_t::LATCH_SH or latch_mode_t::LATCH_EX mode by this thread.
Remarks
The example implementations for the conditions are given in the documentation because it is hard to figure out which pages cannot be evicted.
Parameters
indexToCheckThe index of the buffer frame that is supposed to be freed by evicting the contained page.
doFlushIfDirtytrue if the page gets flushed during the eviction, false else.
Returns
true if the page could be evicted, false else.

§ isMediaFailure() [1/2]

bool zero::buffer_pool::BufferPool::isMediaFailure ( ) const
inlinenoexcept

§ isMediaFailure() [2/2]

bool zero::buffer_pool::BufferPool::isMediaFailure ( PageID  pid) const
inlinenoexcept

MG TODO.

MG TODO

Parameters
pidMG TODO
Returns
MG TODO

§ isNoDBMode()

zero::buffer_pool::BufferPool::isNoDBMode ( ) const
inlinenoexcept

Whether this buffer pool is in NoDB mode.

Returns
true if this buffer pool is in NoDB mode (_noDBMode ), false else.

§ isValidIndex()

zero::buffer_pool::BufferPool::isValidIndex ( bf_idx  index) const
inlinenoexcept

Checks the validity of a buffer pool index in this buffer pool.

Whether the given buffer pool index is in the range of valid buffer pool indexes of this buffer pool (0 is invalid and too large indexes are invalid, too).

Parameters
indexThe buffer pool index to be checked.
Returns
Whether index is a valid buffer pool index in this buffer pool.

§ isWarmupDone()

bool zero::buffer_pool::BufferPool::isWarmupDone ( ) const
inlinenoexcept

Return whether this buffer pool is already "warmed up".

Returns whether this buffer pool is already "warmed up". Further details on the meaning of "warmed up" can be found at _checkWarmupDone() .

Returns
False, if the warmup of this buffer pool is ongoing, true else.

§ normalizePID()

zero::buffer_pool::BufferPool::normalizePID ( const PageID  pid) const
inlinenoexcept

Normalize a page ID.

Normalizes the given page ID to an actual page ID (for vol_t ). If the page ID is a buffer pool index (in case of swizzling) then it returns the page ID of the page on disk, otherwise it returns the page ID as it is.

Precondition
Hold the latch corresponding to the parent page in latch_mode_t::LATCH_SH or latch_mode_t::LATCH_EX ?
Parameters
pidThe page ID to normalize.
Returns
The corresponding page ID to a vol_t page.

§ pinForRefix()

zero::buffer_pool::BufferPool::pinForRefix ( const generic_page pinPage)

Pin a page for a cheaper re-fix.

Adds an additional pin count for the given pinPage . This is used to re-fix the page later without parent pointer. See refixDirect(generic_page*& targetPage, bf_idx refixIndex, latch_mode_t latchMode, bool conditional) why we need this feature.

Precondition
The buffer frame corresponding to pinPage is already latched by this thread.
Postcondition
The page cannot be evicted because it is pinned by this thread.
Parameters
[in]pinPageThe page that is currently latched and will be re-fixed later.
Returns
Buffer frame index of the pinPage in this buffer pool. Use this value for the subsequent calls to refixDirect(generic_page*& targetPage, bf_idx refixIndex, latch_mode_t latchMode, bool conditional) and unpinForRefix(bf_idx unpinIndex) .
Warning
Never forget to call a corresponding unpinForRefix(bf_idx unpinIndex) because otherwise the pinPage will be in this buffer pool forever.

§ postInitialize()

void zero::buffer_pool::BufferPool::postInitialize ( )

Completes the initialization of this buffer pool.

Completes the initialization of this buffer pool which was started during its construction.

Precondition
vol_t::_alloc_cache needs to be initialized before.
Postcondition
The buffer pool is fully initialized. All the required auxiliary threads are running.

§ recoverIfNeeded()

zero::buffer_pool::BufferPool::recoverIfNeeded ( bf_tree_cb_t controlBlock,
generic_page page,
bool  onlyIfDirty = true 
)
noexcept

Recover buffered page if needed.

Recovers a page—buffered in this buffer pool—if needed using the _localSprIter . It is not needed when recovery is disabled in general or when it is disabled for the particular page. It is possibly needed when it is explicitly requested (onlyIfTrue == false ) or when the page is dirty.

Precondition
Hold the latch corresponding to the control block in latch_mode_t::LATCH_EX .
Postcondition
If recovery is enabled, the page is not dirty and a log record of type fetch_page_log was created if _logFetches is true .
Parameters
controlBlockThe control block of the page to recover if needed.
pageThe buffered page to recover if needed.
onlyIfDirtyWhether the page should be recovered even though it is not dirty.

§ refixDirect()

zero::buffer_pool::BufferPool::refixDirect ( generic_page *&  targetPage,
bf_idx  refixIndex,
latch_mode_t  latchMode,
bool  conditional 
)

Re-fix a pinned page.

Re-fixes a page without the parent pointer which was pinned for refix (pinForRefix(const generic_page* pinPage) ) before.

Parameters
[out]targetPageThis page should contain the re-fixed page.
[in]refixIndexBuffer pool index of the requested page to be re-fixed.
[in]latchModeThe wanted latch mode for the page that should be re-fixed (only latch_mode_t::LATCH_SH and latch_mode_t::LATCH_EX are allowed here).
[in]conditionalWhether the re-fix is conditional (returns immediately even if failed).

§ refixDirectOldSytleExceptions()

w_rc_t BufferPool::refixDirectOldSytleExceptions ( generic_page *&  targetPage,
bf_idx  refixIndex,
latch_mode_t  latchMode,
bool  conditional 
)

§ setMediaFailure()

void zero::buffer_pool::BufferPool::setMediaFailure ( )
noexcept

MG TODO.

MG TODO

Precondition
MG TODO
Postcondition
MG TODO

§ shutdown()

void zero::buffer_pool::BufferPool::shutdown ( )

Shuts down this buffer pool.

Stops the threads forked by this buffer pool to allow destruction without leaving those threads running.

Postcondition
Threads forked by the buffer pool are stopped. The buffer pool is not able to work properly anymore.

§ switchParent()

zero::buffer_pool::BufferPool::switchParent ( PageID  childPID,
generic_page newParentPage 
)
noexcept

Switch the parent page of a buffered B-Tree page in this buffer pool.

For each buffered non-root B-Tree page, the buffer pool also stores the buffer pool index of the buffer frame where the corresponding parent page is buffered. Therefore, this information needs to be updated once the parent page of such a page is changed. That is what this function does.

Precondition
Hold the latch corresponding to the old and new parent page in either latch_mode_t::LATCH_SH or latch_mode_t::LATCH_EX .
Parameters
childPIDThe page ID of the B-Tree page whose parent is switched.
newParentPageThe new parent page.

§ sxUpdateChildEMLSN()

zero::buffer_pool::BufferPool::sxUpdateChildEMLSN ( btree_page_h parentPage,
general_recordid_t  childSlotID,
lsn_t  childEMLSN 
) const

Update the EMLSN of a B-Tree child inside its parent page.

Sets the EMLSN of a B-Tree child in the corresponding slot of its parent page. This uses a system transaction for the purpose.

Precondition
Hold the latch corresponding to the parent page in either latch_mode_t::LATCH_SH or latch_mode_t::LATCH_EX .
Postcondition
A log record of type update_emlsn_log was created.
Parameters
parentPageThe parent page buffered in this buffer pool.
childSlotIDThe corresponding slot ID of the child within parentPage .
childEMLSNThe new EMLSN of the child page requested to be written in the parent page.

§ unfix()

zero::buffer_pool::BufferPool::unfix ( const generic_page unfixPage,
bool  evict = false 
)

Unfixes a page in this buffer pool.

Unfixes the given page in this buffer pool by releasing its latch, and, if requested, evicting the page.

Parameters
[in]unfixPageThe page that should be unfixed.
[in]evictWhether the unfixed page should be explicitly evicted if possible.

§ unpinForRefix()

zero::buffer_pool::BufferPool::unpinForRefix ( bf_idx  unpinIndex)

Unpin a page for re-fix.

Removes the additional pin count added by the call to pinForRefix(const generic_page* pinPage) from the buffer frame corresponding to the given buffer frame index.

Precondition
The page cannot be evicted because it is pinned by this thread.
Postcondition
If no other thread pinned this page, it can be evicted.
Parameters
[in]unpinIndexBuffer pool index of the page to be unpin for refix.

§ unsetMediaFailure()

void zero::buffer_pool::BufferPool::unsetMediaFailure ( )
noexcept

MG TODO.

MG TODO

Precondition
MG TODO
Postcondition
MG TODO

MG TODO

Returns
MG TODO

§ unswizzlePagePointer()

zero::buffer_pool::BufferPool::unswizzlePagePointer ( generic_page parentPage,
general_recordid_t  childSlotInParentPage,
PageID childPageID = nullptr 
)

Unswizzle a page pointer in a page's parent page.

Tries to unswizzle the given child page (childSlotInParentPage ) from the parent page (parentPage ). If, for some reason, unswizzling was impossible or troublesome, gives up and returns false .

Precondition
The parent page is latched in any mode and the child page is latched in mode latch_mode_t::LATCH_EX.
Parameters
[in]parentPageThe parent page where to unswizzle the child page.
[in]childSlotInParentPageThe slot within the parent page where to find the swizzled pointer to the child page.
[in,out]childPageIDIf it wasn't set to the nullptr, the unswizzled PageID of the child page is returned.
Returns
false if the unswizzling was not successful, else true.

§ upgradeLatchConditional()

zero::buffer_pool::BufferPool::upgradeLatchConditional ( const generic_page page)
noexcept

Upgrade the latch of a page.

Upgrade this thread holding the latch of a page in latch_mode_t::LATCH_SH to one holding the latch in latch_mode_t::LATCH_EX without waiting.

Parameters
pageThe latch corresponding to this page should be upgraded.
Returns
If the latch is already held in latch_mode_t::LATCH_EX or if the latch could be upgraded immediately true, else false .

§ usesWriteElision()

zero::buffer_pool::BufferPool::usesWriteElision ( ) const
inlinenoexcept

Whether this buffer pool uses write elision.

Returns
true if this buffer pool uses write elision (_useWriteElision ), false else.

§ wakeupPageCleaner()

void zero::buffer_pool::BufferPool::wakeupPageCleaner ( ) const
inline

Friends And Related Function Documentation

§ ::bf_tree_cleaner

friend class ::bf_tree_cleaner
friend

§ ::GenericPageIterator

friend class ::GenericPageIterator
friend

§ ::test_bf_tree

friend class ::test_bf_tree
friend

§ FreeListHighContention

friend class FreeListHighContention
friend

§ FreeListLowContention

friend class FreeListLowContention
friend

§ page_cleaner_decoupled

friend class page_cleaner_decoupled
friend

§ PageEvictioner

friend class PageEvictioner
friend

§ PageEvictionerSelectAndFilter

template<class selector_class , class filter_class , bool filter_early>
friend class PageEvictionerSelectAndFilter
friend

Member Data Documentation

§ _asyncEviction

zero::buffer_pool::BufferPool::_asyncEviction
private

Use a dedicated thread for eviction.

Set if a dedicated thread should be used for page eviction. If a dedicated thread is used, threads encountering a full buffer pool wakeup this page eviction thread and wait until there is a buffer index of an unoccupied buffer frame available for them in the _freeList . If no dedicated thread is used, the first thread encountering a full buffer pool runs the eviction before it continues with its transaction.

Note
One run of the evictioner might evict many pages (batch eviction) therefore such a run might take a long time.

§ _backgroundRestorer

zero::buffer_pool::BufferPool::_backgroundRestorer
private

MG TODO.

MG TODO

§ _batchSegmentSize

zero::buffer_pool::BufferPool::_batchSegmentSize
private

MG TODO.

MG TODO

§ _batchWarmup

zero::buffer_pool::BufferPool::_batchWarmup
private

MG TODO.

MG TODO

§ _blockCount

zero::buffer_pool::BufferPool::_blockCount
private

Maximum number of pages in this buffer pool.

Number of buffer pool frames available to hold pages in this buffer pool.

§ _buffer

zero::buffer_pool::BufferPool::_buffer
private

Array of buffered pages.

A C-array containing up to _blockCount buffered pages, each in a buffer pool frame of this buffer pool. The array index represents the buffer frame index.

§ _cleaner

zero::buffer_pool::BufferPool::_cleaner
private

Cleans dirty pages.

This is responsible to clean dirty pages (write-back changed pages) buffered in this buffer pool.

§ _cleanerDecoupled

zero::buffer_pool::BufferPool::_cleanerDecoupled
private

Use log-based "decoupled" cleaner.

Set if the log-based "decoupled" cleaner should be used instead of one that is based on data from the buffer pool.

§ _controlBlocks

zero::buffer_pool::BufferPool::_controlBlocks
private

Array of control blocks.

A C-array containing _blockCount control blocks, one for each buffer pool frame of this buffer pool. The array index represents the buffer frame index.

§ _evictioner

zero::buffer_pool::BufferPool::_evictioner
private

Evicts pages.

This is responsible to evict buffered pages from this buffer pool once there are (almost) no more unoccupied buffer frames in this buffer pool while currently not buffered pages should be added to this buffer pool.

§ _fixCount

zero::buffer_pool::BufferPool::_fixCount = 0
staticprivate

MG TODO.

MG TODO

§ _freeList

zero::buffer_pool::BufferPool::_freeList
private

List of unused buffer frames.

A queue containing the indexes of currently unoccupied buffer frames of this buffer pool.

Note
It could be any synchronized data structure but a queue is required for some of the page eviction strategies like CLOCK.

§ _hashtable

zero::buffer_pool::BufferPool::_hashtable
private

Allows to locate pages by PageID.

A hashtable which maps the PageID of page buffered in this buffer pool to the buffer frame index where it is located in. For each buffered page, it also contains the buffer frame index of its parent page (if it's a non-root B-Tree page).

§ _hitCount

zero::buffer_pool::BufferPool::_hitCount = 0
staticprivate

MG TODO.

MG TODO

§ _instantRestore

zero::buffer_pool::BufferPool::_instantRestore
private

Use instant restore.

Set if instant restore should be used by this buffer pool. MG TODO

§ _localSprIter

zero::buffer_pool::BufferPool::_localSprIter
staticprivate

Single-page-recovery iterator used for instant restart redo.

MG TODO

See also
recoverIfNeeded

§ _logFetches

zero::buffer_pool::BufferPool::_logFetches
private

Log page fetches.

Set if page fetches from database or from the used recovery mechansim should be logged in the transactional log using log entries of type fetch_page_log .

§ _maintainEMLSN

zero::buffer_pool::BufferPool::_maintainEMLSN
private

Maintain EMLSN of B-Tree pages.

MG TODO

§ _mediaFailurePID

zero::buffer_pool::BufferPool::_mediaFailurePID
private

MG TODO.

MG TODO

§ _noDBMode

zero::buffer_pool::BufferPool::_noDBMode
private

Use NoDB.

Set if this buffer pool should be used for NoDB. MG TODO

§ _restoreCoordinator

zero::buffer_pool::BufferPool::_restoreCoordinator
private

MG TODO.

MG TODO

§ _rootPages

zero::buffer_pool::BufferPool::_rootPages
private

Buffer indexes of root pages.

This holds for each stnode_t the buffer index of its root page or 0 if it is currently not buffered in this buffer pool.

§ _useWriteElision

zero::buffer_pool::BufferPool::_useWriteElision
private

Use write elision.

Set if write elision should be used by this buffer pool. With write elision, a page can be evicted from the buffer pool even though it is dirty because once the page is read again, the changes are retrieved from the log.

§ _warmupDone

zero::buffer_pool::BufferPool::_warmupDone
private

MG TODO.

MG TODO

§ _warmupHitRatio

zero::buffer_pool::BufferPool::_warmupHitRatio
private

Hit rate of a "warm" buffer pool.

At least this hit rate needs to be achieved by this buffer pool to be considered warm.

§ _warmupMinFixes

zero::buffer_pool::BufferPool::_warmupMinFixes
private

Minimum number of fixes of a "warm" buffer pool.

At least this many page fixes need to be performed by this buffer pool to be considered warm.


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