MySQL 9.0.0
Source Code Documentation
Parallel_reader_adapter Class Reference

Traverse an index in the leaf page block list order and send records to adapter. More...

#include <row0pread-adapter.h>

Classes

struct  MySQL_row
 MySQL row meta data. More...
 
struct  Thread_ctx
 Callback thread context for each of the spawned threads. More...
 

Public Types

using Load_fn = handler::Load_cbk
 
using End_fn = handler::Load_end_cbk
 
using Init_fn = handler::Load_init_cbk
 

Public Member Functions

 Parallel_reader_adapter (size_t max_threads, ulint rowlen)
 Constructor. More...
 
 ~Parallel_reader_adapter ()=default
 Destructor. More...
 
dberr_t add_scan (trx_t *trx, const Parallel_reader::Config &config, Parallel_reader::F &&f)
 Add scan context. More...
 
dberr_t run (void **thread_contexts, Init_fn init_fn, Load_fn load_fn, End_fn end_fn)
 Run the parallel scan. More...
 
dberr_t process_rows (const Parallel_reader::Ctx *reader_ctx)
 Convert the record in InnoDB format to MySQL format and send them. More...
 
void set (row_prebuilt_t *prebuilt)
 Set up the query processing state cache. More...
 

Private Member Functions

dberr_t init (Parallel_reader::Thread_ctx *reader_thread_ctx, row_prebuilt_t *prebuilt)
 Each parallel reader thread's init function. More...
 
dberr_t end (Parallel_reader::Thread_ctx *reader_thread_ctx)
 Each parallel reader thread's end function. More...
 
dberr_t send_batch (Parallel_reader::Thread_ctx *reader_thread_ctx, size_t partition_id, uint64_t n_recs)
 Send a batch of records. More...
 
size_t pending (Thread_ctx *ctx) const
 Get the number of rows buffered but not sent. More...
 
bool is_buffer_full (Thread_ctx *ctx) const
 Check if the buffer is full. More...
 

Private Attributes

void ** m_thread_ctxs {}
 Adapter context for each of the spawned threads. More...
 
Init_fn m_init_fn {}
 Callback called by each parallel load thread at the beginning of the parallel load for the scan. More...
 
Load_fn m_load_fn {}
 Callback called by each parallel load thread when processing of rows is required for the scan. More...
 
End_fn m_end_fn {}
 Callback called by each parallel load thread when processing of rows has ended for the scan. More...
 
uint64_t m_batch_size {}
 Number of records to be sent across to the caller in a batch. More...
 
MySQL_row m_mysql_row {}
 Row meta data per scan context. More...
 
row_prebuilt_tm_prebuilt {}
 Prebuilt to use for conversion to MySQL row format. More...
 
Parallel_reader m_parallel_reader
 Parallel reader to use. More...
 

Static Private Attributes

static constexpr size_t ADAPTER_SEND_BUFFER_SIZE = 2 * 1024 * 1024
 Size of the buffer used to store InnoDB records and sent to the adapter. More...
 

Detailed Description

Traverse an index in the leaf page block list order and send records to adapter.

Member Typedef Documentation

◆ End_fn

◆ Init_fn

◆ Load_fn

Constructor & Destructor Documentation

◆ Parallel_reader_adapter()

Parallel_reader_adapter::Parallel_reader_adapter ( size_t  max_threads,
ulint  rowlen 
)

Constructor.

Parameters
[in]max_threadsMaximum threads to use for all scan contexts.
[in]rowlenRow length.

◆ ~Parallel_reader_adapter()

Parallel_reader_adapter::~Parallel_reader_adapter ( )
default

Destructor.

Member Function Documentation

◆ add_scan()

dberr_t Parallel_reader_adapter::add_scan ( trx_t trx,
const Parallel_reader::Config config,
Parallel_reader::F &&  f 
)

Add scan context.

Parameters
[in]trxTransaction used for parallel read.
[in]config(Cluster) Index scan configuration.
[in]fCallback function.
Returns
error.

◆ end()

dberr_t Parallel_reader_adapter::end ( Parallel_reader::Thread_ctx reader_thread_ctx)
private

Each parallel reader thread's end function.

Parameters
[in]reader_thread_ctxcontext info related to the current thread
Returns
DB_SUCCESS or error code.

◆ init()

dberr_t Parallel_reader_adapter::init ( Parallel_reader::Thread_ctx reader_thread_ctx,
row_prebuilt_t prebuilt 
)
private

Each parallel reader thread's init function.

Parameters
[in]reader_thread_ctxcontext info related to the current thread
[in]prebuiltprebuilt cache
Returns
DB_SUCCESS or error code.

There are data members in row_prebuilt_t that cannot be accessed in multi-threaded mode e.g., blob_heap.

row_prebuilt_t is designed for single threaded access and to share it among threads is not recommended unless "you know what you are doing". This is very fragile code as it stands.

To solve the blob heap issue in prebuilt we request parallel reader thread to use blob heap per thread and we pass this blob heap to the InnoDB to MySQL row format conversion function.

◆ is_buffer_full()

bool Parallel_reader_adapter::is_buffer_full ( Thread_ctx ctx) const
inlineprivate

Check if the buffer is full.

Parameters
[in]ctxadapter related thread context information.
Returns
true if the buffer is full.

◆ pending()

size_t Parallel_reader_adapter::pending ( Thread_ctx ctx) const
inlineprivate

Get the number of rows buffered but not sent.

Parameters
[in]ctxadapter related thread context information.
Returns
number of buffered items.

◆ process_rows()

dberr_t Parallel_reader_adapter::process_rows ( const Parallel_reader::Ctx reader_ctx)

Convert the record in InnoDB format to MySQL format and send them.

Parameters
[in]reader_ctxParallel read context.
Returns
error code

◆ run()

dberr_t Parallel_reader_adapter::run ( void **  thread_contexts,
Init_fn  init_fn,
Load_fn  load_fn,
End_fn  end_fn 
)

Run the parallel scan.

Parameters
[in]thread_contextsContext for each of the spawned threads
[in]init_fnCallback called by each parallel load thread at the beginning of the parallel load.
[in]load_fnCallback called by each parallel load thread when processing of rows is required.
[in]end_fnCallback called by each parallel load thread when processing of rows has ended.
Returns
DB_SUCCESS or error code.

◆ send_batch()

dberr_t Parallel_reader_adapter::send_batch ( Parallel_reader::Thread_ctx reader_thread_ctx,
size_t  partition_id,
uint64_t  n_recs 
)
private

Send a batch of records.

Parameters
[in]reader_thread_ctxreader threads related thread context info
[in]partition_idpartition ID of the index the record belongs to
[in]n_recsNumber of records to send.
Returns
DB_SUCCESS or error code.

◆ set()

void Parallel_reader_adapter::set ( row_prebuilt_t prebuilt)

Set up the query processing state cache.

Parameters
[in]prebuiltThe prebuilt cache for the query.

Member Data Documentation

◆ ADAPTER_SEND_BUFFER_SIZE

constexpr size_t Parallel_reader_adapter::ADAPTER_SEND_BUFFER_SIZE = 2 * 1024 * 1024
staticconstexprprivate

Size of the buffer used to store InnoDB records and sent to the adapter.

◆ m_batch_size

uint64_t Parallel_reader_adapter::m_batch_size {}
private

Number of records to be sent across to the caller in a batch.

◆ m_end_fn

End_fn Parallel_reader_adapter::m_end_fn {}
private

Callback called by each parallel load thread when processing of rows has ended for the scan.

◆ m_init_fn

Init_fn Parallel_reader_adapter::m_init_fn {}
private

Callback called by each parallel load thread at the beginning of the parallel load for the scan.

◆ m_load_fn

Load_fn Parallel_reader_adapter::m_load_fn {}
private

Callback called by each parallel load thread when processing of rows is required for the scan.

◆ m_mysql_row

MySQL_row Parallel_reader_adapter::m_mysql_row {}
private

Row meta data per scan context.

◆ m_parallel_reader

Parallel_reader Parallel_reader_adapter::m_parallel_reader
private

Parallel reader to use.

◆ m_prebuilt

row_prebuilt_t* Parallel_reader_adapter::m_prebuilt {}
private

Prebuilt to use for conversion to MySQL row format.

NOTE: We are sharing this because we don't convert BLOBs yet. There are data members in row_prebuilt_t that cannot be accessed in multi-threaded mode e.g., blob_heap.

row_prebuilt_t is designed for single threaded access and to share it among threads is not recommended unless "you know what you are doing". This is very fragile code as it stands.

To solve the blob heap issue in prebuilt we use per thread m_blob_heaps. Pass the blob heap to the InnoDB to MySQL row format conversion function.

◆ m_thread_ctxs

void** Parallel_reader_adapter::m_thread_ctxs {}
private

Adapter context for each of the spawned threads.

We don't know the type of the context it's passed to us as a void *.


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