MySQL 9.0.0
Source Code Documentation
Parallel_reader::Scan_ctx Class Reference

Parallel reader context. More...

#include <row0pread.h>

Classes

struct  Iter
 Boundary of the range to scan. More...
 

Public Member Functions

 Scan_ctx (Parallel_reader *reader, size_t id, trx_t *trx, const Parallel_reader::Config &config, F &&f)
 Constructor. More...
 
 ~Scan_ctx ()=default
 Destructor. More...
 

Private Types

using Savepoint = std::pair< ulint, buf_block_t * >
 mtr_t savepoint. More...
 
using Savepoints = std::vector< Savepoint, ut::allocator< Savepoint > >
 For releasing the S latches after processing the blocks. More...
 
using Range = std::pair< std::shared_ptr< Iter >, std::shared_ptr< Iter > >
 The first cursor should read up to the second cursor [f, s). More...
 
using Ranges = std::vector< Range, ut::allocator< Range > >
 
using Config = Parallel_reader::Config
 

Private Member Functions

size_t id () const
 
void set_error_state (dberr_t err)
 Set the error state. More...
 
bool is_error_set () const
 
buf_block_tblock_get_s_latched (const page_id_t &page_id, mtr_t *mtr, size_t line) const
 Fetch a block from the buffer pool and acquire an S latch on it. More...
 
dberr_t partition (const Scan_range &scan_range, Ranges &ranges, size_t split_level)
 Partition the B+Tree for parallel read. More...
 
page_no_t search (const buf_block_t *block, const dtuple_t *key) const
 Find the page number of the node that contains the search key. More...
 
page_cur_t start_range (page_no_t page_no, mtr_t *mtr, const dtuple_t *key, Savepoints &savepoints) const
 Traverse from given sub-tree page number to start of the scan range from the given page number. More...
 
void create_range (Ranges &ranges, page_cur_t &leaf_page_cursor, mtr_t *mtr) const
 Create and add the range to the scan ranges. More...
 
dberr_t create_ranges (const Scan_range &scan_range, page_no_t page_no, size_t depth, const size_t split_level, Ranges &ranges, mtr_t *mtr)
 Find the subtrees to scan in a block. More...
 
void copy_row (const rec_t *rec, Iter *iter) const
 Build a dtuple_t from rec_t. More...
 
std::shared_ptr< Itercreate_persistent_cursor (const page_cur_t &page_cursor, mtr_t *mtr) const
 Create the persistent cursor that will be used to traverse the partition and position on the the start row. More...
 
bool check_visibility (const rec_t *&rec, ulint *&offsets, mem_heap_t *&heap, mtr_t *mtr)
 Build an old version of the row if required. More...
 
dberr_t create_context (const Range &range, bool split)
 Create an execution context for a range and add it to the Parallel_reader's run queue. More...
 
dberr_t create_contexts (const Ranges &ranges)
 Create the execution contexts based on the ranges. More...
 
size_t max_threads () const
 
void release_threads (size_t unused_threads)
 Release unused threads back to the pool. More...
 
void index_s_lock ()
 S lock the index. More...
 
void index_s_unlock ()
 S unlock the index. More...
 
bool index_s_own () const
 
 Scan_ctx (Scan_ctx &&)=delete
 
 Scan_ctx (const Scan_ctx &)=delete
 
Scan_ctxoperator= (Scan_ctx &&)=delete
 
Scan_ctxoperator= (const Scan_ctx &)=delete
 

Private Attributes

size_t m_id {std::numeric_limits<size_t>::max()}
 Context ID. More...
 
Config m_config
 Parallel scan configuration. More...
 
const trx_tm_trx {}
 Covering transaction. More...
 
F m_f
 Callback function. More...
 
size_t m_depth {}
 Depth of the Btree. More...
 
Parallel_readerm_reader {}
 The parallel reader. More...
 
std::atomic< dberr_tm_err {DB_SUCCESS}
 Error during parallel read. More...
 
std::atomic_size_t m_s_locks {}
 Number of threads that have S locked the index. More...
 

Friends

class Parallel_reader
 

Detailed Description

Parallel reader context.

Member Typedef Documentation

◆ Config

◆ Range

using Parallel_reader::Scan_ctx::Range = std::pair<std::shared_ptr<Iter>, std::shared_ptr<Iter> >
private

The first cursor should read up to the second cursor [f, s).

◆ Ranges

◆ Savepoint

mtr_t savepoint.

◆ Savepoints

For releasing the S latches after processing the blocks.

Constructor & Destructor Documentation

◆ Scan_ctx() [1/3]

Parallel_reader::Scan_ctx::Scan_ctx ( Parallel_reader reader,
size_t  id,
trx_t trx,
const Parallel_reader::Config config,
F &&  f 
)

Constructor.

Parameters
[in]readerParallel reader that owns this context.
[in]idID of this scan context.
[in]trxTransaction covering the scan.
[in]configRange scan config.
[in]fCallback function.

◆ ~Scan_ctx()

Parallel_reader::Scan_ctx::~Scan_ctx ( )
default

Destructor.

◆ Scan_ctx() [2/3]

Parallel_reader::Scan_ctx::Scan_ctx ( Scan_ctx &&  )
privatedelete

◆ Scan_ctx() [3/3]

Parallel_reader::Scan_ctx::Scan_ctx ( const Scan_ctx )
privatedelete

Member Function Documentation

◆ block_get_s_latched()

buf_block_t * Parallel_reader::Scan_ctx::block_get_s_latched ( const page_id_t page_id,
mtr_t mtr,
size_t  line 
) const
private

Fetch a block from the buffer pool and acquire an S latch on it.

Parameters
[in]page_idPage ID.
[in,out]mtrMini-transaction covering the fetch.
[in]lineLine from where called.
Returns
the block fetched from the buffer pool.

◆ check_visibility()

bool Parallel_reader::Scan_ctx::check_visibility ( const rec_t *&  rec,
ulint *&  offsets,
mem_heap_t *&  heap,
mtr_t mtr 
)
private

Build an old version of the row if required.

Parameters
[in,out]recCurrent row read from the index. This can be modified by this method if an older version needs to be built.
[in,out]offsetsSame as above but pertains to the rec offsets
[in,out]heapHeap to use if a previous version needs to be built from the undo log.
[in,out]mtrMini-transaction covering the read.
Returns
true if row is visible to the transaction.

◆ copy_row()

void Parallel_reader::Scan_ctx::copy_row ( const rec_t rec,
Iter iter 
) const
private

Build a dtuple_t from rec_t.

Parameters
[in]recBuild the dtuple from this record.
[in,out]iterBuild in this iterator.

◆ create_context()

dberr_t Parallel_reader::Scan_ctx::create_context ( const Range range,
bool  split 
)
private

Create an execution context for a range and add it to the Parallel_reader's run queue.

Parameters
[in]rangeRange for which to create the context.
[in]splittrue if the sub-tree should be split further.
Returns
DB_SUCCESS or error code.

◆ create_contexts()

dberr_t Parallel_reader::Scan_ctx::create_contexts ( const Ranges ranges)
private

Create the execution contexts based on the ranges.

Parameters
[in]rangesRanges for which to create the contexts.
Returns
DB_SUCCESS or error code.

◆ create_persistent_cursor()

std::shared_ptr< Parallel_reader::Scan_ctx::Iter > Parallel_reader::Scan_ctx::create_persistent_cursor ( const page_cur_t page_cursor,
mtr_t mtr 
) const
private

Create the persistent cursor that will be used to traverse the partition and position on the the start row.

Parameters
[in]page_cursorCurrent page cursor
[in]mtrMini-transaction covering the read.
Returns
Start iterator.

◆ create_range()

void Parallel_reader::Scan_ctx::create_range ( Ranges ranges,
page_cur_t leaf_page_cursor,
mtr_t mtr 
) const
private

Create and add the range to the scan ranges.

Parameters
[in,out]rangesRanges to scan.
[in,out]leaf_page_cursorLeaf page cursor on which to create the persistent cursor.
[in,out]mtrMini-transaction

◆ create_ranges()

dberr_t Parallel_reader::Scan_ctx::create_ranges ( const Scan_range scan_range,
page_no_t  page_no,
size_t  depth,
const size_t  split_level,
Ranges ranges,
mtr_t mtr 
)
private

Find the subtrees to scan in a block.

Parameters
[in]scan_rangePartition based on this scan range.
[in]page_noPage to partition at if at required level.
[in]depthSub-range current level.
[in]split_levelSub-range starting level (0 == root).
[in,out]rangesRanges to scan.
[in,out]mtrMini-transaction

◆ id()

size_t Parallel_reader::Scan_ctx::id ( ) const
inlineprivate
Returns
the scan context ID.

◆ index_s_lock()

void Parallel_reader::Scan_ctx::index_s_lock ( )
private

S lock the index.

◆ index_s_own()

bool Parallel_reader::Scan_ctx::index_s_own ( ) const
inlineprivate
Returns
true if at least one thread owns the S latch on the index.

◆ index_s_unlock()

void Parallel_reader::Scan_ctx::index_s_unlock ( )
private

S unlock the index.

◆ is_error_set()

bool Parallel_reader::Scan_ctx::is_error_set ( ) const
inlineprivate
Returns
true if in error state.

◆ max_threads()

size_t Parallel_reader::Scan_ctx::max_threads ( ) const
inlineprivate
Returns
the maximum number of threads configured.

◆ operator=() [1/2]

Scan_ctx & Parallel_reader::Scan_ctx::operator= ( const Scan_ctx )
privatedelete

◆ operator=() [2/2]

Scan_ctx & Parallel_reader::Scan_ctx::operator= ( Scan_ctx &&  )
privatedelete

◆ partition()

dberr_t Parallel_reader::Scan_ctx::partition ( const Scan_range scan_range,
Ranges ranges,
size_t  split_level 
)
private

Partition the B+Tree for parallel read.

Parameters
[in]scan_rangeRange for partitioning.
[in,out]rangesRanges to scan.
[in]split_levelSub-range required level (0 == root).
Returns
the partition scan ranges.

◆ release_threads()

void Parallel_reader::Scan_ctx::release_threads ( size_t  unused_threads)
inlineprivate

Release unused threads back to the pool.

Parameters
[in]unused_threadsNumber of threads to "release".

◆ search()

page_no_t Parallel_reader::Scan_ctx::search ( const buf_block_t block,
const dtuple_t key 
) const
private

Find the page number of the node that contains the search key.

If the key is null then we assume -infinity.

Parameters
[in]blockPage to look in.
[in]keyKey of the first record in the range.
Returns
the left child page number.

◆ set_error_state()

void Parallel_reader::Scan_ctx::set_error_state ( dberr_t  err)
inlineprivate

Set the error state.

Parameters
[in]errError state to set to.

◆ start_range()

page_cur_t Parallel_reader::Scan_ctx::start_range ( page_no_t  page_no,
mtr_t mtr,
const dtuple_t key,
Savepoints savepoints 
) const
private

Traverse from given sub-tree page number to start of the scan range from the given page number.

Parameters
[in]page_noPage number of sub-tree.
[in,out]mtrMini-transaction.
[in]keyKey of the first record in the range.
[in,out]savepointsBlocks S latched and accessed.
Returns
the leaf node page cursor.

Friends And Related Function Documentation

◆ Parallel_reader

friend class Parallel_reader
friend

Member Data Documentation

◆ m_config

Config Parallel_reader::Scan_ctx::m_config
private

Parallel scan configuration.

◆ m_depth

size_t Parallel_reader::Scan_ctx::m_depth {}
private

Depth of the Btree.

◆ m_err

std::atomic<dberr_t> Parallel_reader::Scan_ctx::m_err {DB_SUCCESS}
mutableprivate

Error during parallel read.

◆ m_f

F Parallel_reader::Scan_ctx::m_f
private

Callback function.

◆ m_id

size_t Parallel_reader::Scan_ctx::m_id {std::numeric_limits<size_t>::max()}
private

Context ID.

◆ m_reader

Parallel_reader* Parallel_reader::Scan_ctx::m_reader {}
private

The parallel reader.

◆ m_s_locks

std::atomic_size_t Parallel_reader::Scan_ctx::m_s_locks {}
private

Number of threads that have S locked the index.

◆ m_trx

const trx_t* Parallel_reader::Scan_ctx::m_trx {}
private

Covering transaction.


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