MySQL 8.0.40
Source Code Documentation
AIO Class Reference

The asynchronous i/o array structure. More...

Public Member Functions

 AIO (latch_id_t id, ulint n, ulint segments)
 Constructor. More...
 
 ~AIO ()
 Destructor. More...
 
dberr_t init ()
 Initialize the instance. More...
 
Slotreserve_slot (IORequest &type, fil_node_t *m1, void *m2, pfs_os_file_t file, const char *name, void *buf, os_offset_t offset, ulint len, const file::Block *e_block)
 Requests for a slot in the aio array. More...
 
ulint pending_io_count () const
 Count the number of free slots. More...
 
const Slotat (ulint i) const
 Returns a pointer to the nth slot in the aio array. More...
 
Slotat (ulint i)
 Non const version. More...
 
void release (Slot *slot)
 Frees a slot in the aio array. More...
 
void release_with_mutex (Slot *slot)
 Frees a slot in the AIO array. More...
 
void print (FILE *file)
 Prints info about the aio array. More...
 
ulint slots_per_segment () const
 
ulint get_n_segments () const
 
bool is_mutex_owned () const
 
void acquire () const
 Acquire the mutex. More...
 
void release () const
 Release the mutex. More...
 
void to_file (FILE *file) const
 Prints all pending IO for the array. More...
 

Static Public Member Functions

static AIOcreate (latch_id_t id, ulint n, ulint n_segments)
 Creates an aio wait array. More...
 
static bool start (ulint n_per_seg, ulint n_readers, ulint n_writers)
 Initializes the asynchronous io system. More...
 
static void start_threads ()
 Starts a thread for each segment. More...
 
static void shutdown ()
 Free the AIO arrays. More...
 
static void print_all (FILE *file)
 Print all the AIO segments. More...
 
static ulint get_array_and_local_segment (AIO *&array, ulint segment)
 Calculates local segment number and aio array from global segment number. More...
 
static AIOselect_slot_array (IORequest &type, bool read_only, AIO_mode aio_mode)
 Select the IO slot array. More...
 
static ulint get_segment_no_from_slot (const AIO *array, const Slot *slot)
 Calculates segment number for a slot. More...
 
static void wake_simulated_handler_thread (ulint global_segment)
 Wakes up a simulated AIO I/O handler thread if it has something to do. More...
 
static bool is_read (const AIO *aio)
 Check if it is a read request. More...
 
static void wait_until_no_pending_writes ()
 Wait on an event until no pending writes. More...
 
static void print_to_file (FILE *file)
 Print to file. More...
 
static ulint total_pending_io_count ()
 Check for pending IO. More...
 

Private Types

typedef std::vector< SlotSlots
 

Private Member Functions

dberr_t init_slots ()
 Initialise the slots. More...
 
void wake_simulated_handler_thread (ulint global_segment, ulint segment)
 Wakes up a simulated AIO I/O-handler thread if it has something to do for a local segment in the AIO array. More...
 
void print_segment_info (FILE *file, const ulint *segments)
 Prints pending IO requests per segment of an aio array. More...
 

Static Private Member Functions

static size_t number_of_extra_threads ()
 Returns the number of arrays other than n_readers and n_writers that start() will create. More...
 

Private Attributes

SysMutex m_mutex
 the mutex protecting the aio array More...
 
Slots m_slots
 Pointer to the slots in the array. More...
 
ulint m_n_segments
 Number of segments in the aio array of pending aio requests. More...
 
os_event_t m_not_full
 The event which is set to the signaled state when there is space in the aio outside the ibuf segment. More...
 
os_event_t m_is_empty
 The event which is set to the signaled state when there are no pending i/os in this array. More...
 
ulint m_n_reserved
 Number of reserved slots in the AIO array outside the ibuf segment. More...
 
std::atomic_size_t m_last_slot_used
 The index of last slot used to reserve. More...
 

Static Private Attributes

static AIOs_ibuf
 The aio arrays for non-ibuf i/o and ibuf i/o. More...
 
static AIOs_reads
 Reads. More...
 
static AIOs_writes
 Writes. More...
 

Detailed Description

The asynchronous i/o array structure.

Member Typedef Documentation

◆ Slots

typedef std::vector<Slot> AIO::Slots
private

Constructor & Destructor Documentation

◆ AIO()

AIO::AIO ( latch_id_t  id,
ulint  n,
ulint  segments 
)

Constructor.

Parameters
[in]idThe latch ID
[in]nNumber of AIO slots
[in]segmentsNumber of segments

◆ ~AIO()

AIO::~AIO ( )

Destructor.

AIO destructor.

Member Function Documentation

◆ acquire()

void AIO::acquire ( ) const
inline

Acquire the mutex.

◆ at() [1/2]

Slot * AIO::at ( ulint  i)
inline

Non const version.

◆ at() [2/2]

const Slot * AIO::at ( ulint  i) const
inline

Returns a pointer to the nth slot in the aio array.

Parameters
[in]iIndex of the slot in the array
Returns
pointer to slot

◆ create()

AIO * AIO::create ( latch_id_t  id,
ulint  n,
ulint  n_segments 
)
static

Creates an aio wait array.

Note that we return NULL in case of failure. We don't care about freeing memory here because we assume that a failure will result in server refusing to start up.

Parameters
[in]idLatch ID
[in]nmaximum number of pending AIO operations allowed; n must be divisible by m_n_segments
[in]n_segmentsnumber of segments in the AIO array
Returns
own: AIO array, NULL on failure

◆ get_array_and_local_segment()

ulint AIO::get_array_and_local_segment ( AIO *&  array,
ulint  segment 
)
static

Calculates local segment number and aio array from global segment number.

Parameters
[out]arrayAIO wait array
[in]segmentglobal segment number
Returns
local segment number within the aio array

◆ get_n_segments()

ulint AIO::get_n_segments ( ) const
inline
Returns
accessor for n_segments

◆ get_segment_no_from_slot()

ulint AIO::get_segment_no_from_slot ( const AIO array,
const Slot slot 
)
static

Calculates segment number for a slot.

Parameters
[in]arrayAIO wait array
[in]slotslot in this array
Returns
segment number (which is the number used by, for example, I/O handler threads)

◆ init()

dberr_t AIO::init ( void  )

Initialize the instance.

Initialise the array.

Returns
DB_SUCCESS or error code

◆ init_slots()

dberr_t AIO::init_slots ( )
private

Initialise the slots.

Returns
DB_SUCCESS or error code

◆ is_mutex_owned()

bool AIO::is_mutex_owned ( ) const
inline
Returns
true if the thread owns the mutex

◆ is_read()

static bool AIO::is_read ( const AIO aio)
inlinestatic

Check if it is a read request.

Parameters
[in]aioThe AIO instance to check
Returns
true if the AIO instance is for reading.

◆ number_of_extra_threads()

size_t AIO::number_of_extra_threads ( )
staticprivate

Returns the number of arrays other than n_readers and n_writers that start() will create.

In srv_read_only_mode this is 0. Otherwise this is just one for ibuf i/o.

◆ pending_io_count()

ulint AIO::pending_io_count ( ) const

Count the number of free slots.

Returns
number of reserved slots

◆ print()

void AIO::print ( FILE *  file)

Prints info about the aio array.

Parameters
[in,out]fileWhere to print

◆ print_all()

void AIO::print_all ( FILE *  file)
static

Print all the AIO segments.

Parameters
[in,out]fileWhere to print

◆ print_segment_info()

void AIO::print_segment_info ( FILE *  file,
const ulint segments 
)
private

Prints pending IO requests per segment of an aio array.

We probably don't need per segment statistics but they can help us during development phase to see if the IO requests are being distributed as expected.

Parameters
[in,out]fileFile where to print
[in]segmentsPending IO array

◆ print_to_file()

void AIO::print_to_file ( FILE *  file)
static

Print to file.

Print pending IOs for all arrays.

Parameters
[in]fileFile to write to

◆ release() [1/2]

void AIO::release ( ) const
inline

Release the mutex.

◆ release() [2/2]

void AIO::release ( Slot slot)

Frees a slot in the aio array.

Assumes caller owns the mutex.

Parameters
[in,out]slotSlot to release

◆ release_with_mutex()

void AIO::release_with_mutex ( Slot slot)

Frees a slot in the AIO array.

Assumes caller doesn't own the mutex.

Parameters
[in,out]slotSlot to release

◆ reserve_slot()

Slot * AIO::reserve_slot ( IORequest type,
fil_node_t m1,
void *  m2,
pfs_os_file_t  file,
const char *  name,
void *  buf,
os_offset_t  offset,
ulint  len,
const file::Block e_block 
)

Requests for a slot in the aio array.

If no slot is available, waits until not_full-event becomes signaled.

Parameters
[in,out]typeIO context
[in,out]m1message to be passed along with AIO operation
[in,out]m2message to be passed along with AIO operation
[in]filefile handle
[in]namename of the file or path as a null-terminated string
[in,out]bufbuffer where to read or from which to write
[in]offsetfile offset, where to read from or start writing
[in]lenlength of the block to read or write
[in]e_blockEncrypted block or nullptr.
Returns
pointer to slot

◆ select_slot_array()

AIO * AIO::select_slot_array ( IORequest type,
bool  read_only,
AIO_mode  aio_mode 
)
static

Select the IO slot array.

Parameters
[in,out]typeType of IO, READ or WRITE
[in]read_onlytrue if running in read-only mode
[in]aio_modeIO mode
Returns
slot array or NULL if invalid mode specified

◆ shutdown()

void AIO::shutdown ( )
static

Free the AIO arrays.

◆ slots_per_segment()

ulint AIO::slots_per_segment ( ) const
inline
Returns
the number of slots per segment

◆ start()

bool AIO::start ( ulint  n_per_seg,
ulint  n_readers,
ulint  n_writers 
)
static

Initializes the asynchronous io system.

Creates one array for ibuf I/O. Also creates one array each for read and write where each array is divided logically into n_readers and n_writers respectively. The caller must create an i/o handler thread for each segment in these arrays by calling start_threads().

Parameters
[in]n_per_segmaximum number of pending aio operations allowed per segment
[in]n_readersnumber of reader threads
[in]n_writersnumber of writer threads
Returns
true if AIO sub-system was started successfully

◆ start_threads()

void AIO::start_threads ( )
static

Starts a thread for each segment.

◆ to_file()

void AIO::to_file ( FILE *  file) const

Prints all pending IO for the array.

Parameters
[in,out]filefile where to print

◆ total_pending_io_count()

ulint AIO::total_pending_io_count ( )
static

Check for pending IO.

Get the total number of pending IOs.

Gets the count and also validates the data structures.

Returns
count of pending IO requests
the total number of pending IOs

◆ wait_until_no_pending_writes()

static void AIO::wait_until_no_pending_writes ( )
inlinestatic

Wait on an event until no pending writes.

◆ wake_simulated_handler_thread() [1/2]

void AIO::wake_simulated_handler_thread ( ulint  global_segment)
static

Wakes up a simulated AIO I/O handler thread if it has something to do.

Parameters
[in]global_segmentThe number of the segment in the AIO arrays

◆ wake_simulated_handler_thread() [2/2]

void AIO::wake_simulated_handler_thread ( ulint  global_segment,
ulint  segment 
)
private

Wakes up a simulated AIO I/O-handler thread if it has something to do for a local segment in the AIO array.

Parameters
[in]global_segmentThe number of the segment in the AIO arrays
[in]segmentThe local segment in the AIO array

Member Data Documentation

◆ m_is_empty

os_event_t AIO::m_is_empty
private

The event which is set to the signaled state when there are no pending i/os in this array.

◆ m_last_slot_used

std::atomic_size_t AIO::m_last_slot_used
private

The index of last slot used to reserve.

This is used to balance the incoming requests more evenly throughout the segments. This field is not guarded by any lock. This is only used as a heuristic and any value read or written to it is OK. It is atomic as it is accesses without any latches from multiple threads.

◆ m_mutex

SysMutex AIO::m_mutex
mutableprivate

the mutex protecting the aio array

◆ m_n_reserved

ulint AIO::m_n_reserved
private

Number of reserved slots in the AIO array outside the ibuf segment.

◆ m_n_segments

ulint AIO::m_n_segments
private

Number of segments in the aio array of pending aio requests.

A thread can wait separately for any one of the segments.

◆ m_not_full

os_event_t AIO::m_not_full
private

The event which is set to the signaled state when there is space in the aio outside the ibuf segment.

◆ m_slots

Slots AIO::m_slots
private

Pointer to the slots in the array.

Number of elements must be divisible by n_threads.

◆ s_ibuf

AIO * AIO::s_ibuf
staticprivate

The aio arrays for non-ibuf i/o and ibuf i/o.

These are NULL when the module has not yet been initialized. Insert buffer

◆ s_reads

AIO * AIO::s_reads
staticprivate

Reads.

Static declarations.

◆ s_writes

AIO * AIO::s_writes
staticprivate

Writes.


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