MySQL 9.1.0
Source Code Documentation
|
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... | |
Slot * | 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. More... | |
ulint | pending_io_count () const |
Count the number of free slots. More... | |
const Slot * | at (ulint i) const |
Returns a pointer to the nth slot in the aio array. More... | |
Slot * | at (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 AIO * | create (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 AIO * | select_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< Slot > | Slots |
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 AIO * | s_ibuf |
The aio arrays for non-ibuf i/o and ibuf i/o. More... | |
static AIO * | s_reads |
Reads. More... | |
static AIO * | s_writes |
Writes. More... | |
The asynchronous i/o array structure.
|
private |
AIO::AIO | ( | latch_id_t | id, |
ulint | n, | ||
ulint | segments | ||
) |
Constructor.
[in] | id | The latch ID |
[in] | n | Number of AIO slots |
[in] | segments | Number of segments |
AIO::~AIO | ( | ) |
Destructor.
AIO destructor.
|
inline |
Acquire the mutex.
Returns a pointer to the nth slot in the aio array.
[in] | i | Index of the slot in the array |
|
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.
[in] | id | Latch ID |
[in] | n | maximum number of pending AIO operations allowed; n must be divisible by m_n_segments |
[in] | n_segments | number of segments in the AIO array |
Calculates local segment number and aio array from global segment number.
[out] | array | AIO wait array |
[in] | segment | global segment number |
|
inline |
Calculates segment number for a slot.
[in] | array | AIO wait array |
[in] | slot | slot in this array |
dberr_t AIO::init | ( | void | ) |
Initialize the instance.
Initialise the array.
|
private |
Initialise the slots.
|
inline |
|
inlinestatic |
Check if it is a read request.
[in] | aio | The AIO instance to check |
|
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.
ulint AIO::pending_io_count | ( | ) | const |
Count the number of free slots.
void AIO::print | ( | FILE * | file | ) |
Prints info about the aio array.
[in,out] | file | Where to print |
|
static |
Print all the AIO segments.
[in,out] | file | Where to print |
|
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.
[in,out] | file | File where to print |
[in] | segments | Pending IO array |
|
static |
Print to file.
Print pending IOs for all arrays.
[in] | file | File to write to |
|
inline |
Release the mutex.
void AIO::release | ( | Slot * | slot | ) |
Frees a slot in the aio array.
Assumes caller owns the mutex.
[in,out] | slot | Slot to release |
void AIO::release_with_mutex | ( | Slot * | slot | ) |
Frees a slot in the AIO array.
Assumes caller doesn't own the mutex.
[in,out] | slot | Slot to release |
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.
[in,out] | type | IO context |
[in,out] | m1 | message to be passed along with AIO operation |
[in,out] | m2 | message to be passed along with AIO operation |
[in] | file | file handle |
[in] | name | name of the file or path as a null-terminated string |
[in,out] | buf | buffer where to read or from which to write |
[in] | offset | file offset, where to read from or start writing |
[in] | len | length of the block to read or write |
[in] | e_block | Encrypted block or nullptr. |
Select the IO slot array.
[in,out] | type | Type of IO, READ or WRITE |
[in] | read_only | true if running in read-only mode |
[in] | aio_mode | IO mode |
|
static |
Free the AIO arrays.
|
inline |
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().
[in] | n_per_seg | maximum number of pending aio operations allowed per segment |
[in] | n_readers | number of reader threads |
[in] | n_writers | number of writer threads |
|
static |
Starts a thread for each segment.
void AIO::to_file | ( | FILE * | file | ) | const |
Prints all pending IO for the array.
[in,out] | file | file where to print |
|
static |
Check for pending IO.
Get the total number of pending IOs.
Gets the count and also validates the data structures.
|
inlinestatic |
Wait on an event until no pending writes.
|
static |
Wakes up a simulated AIO I/O handler thread if it has something to do.
[in] | global_segment | The number of the segment in the AIO arrays |
Wakes up a simulated AIO I/O-handler thread if it has something to do for a local segment in the AIO array.
[in] | global_segment | The number of the segment in the AIO arrays |
[in] | segment | The local segment in the AIO array |
|
private |
The event which is set to the signaled state when there are no pending i/os in this array.
|
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.
|
mutableprivate |
the mutex protecting the aio array
|
private |
Number of reserved slots in the AIO array outside the ibuf segment.
|
private |
Number of segments in the aio array of pending aio requests.
A thread can wait separately for any one of the segments.
|
private |
The event which is set to the signaled state when there is space in the aio outside the ibuf segment.
|
private |
Pointer to the slots in the array.
Number of elements must be divisible by n_threads.
|
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
|
staticprivate |
Reads.
Static declarations.
|
staticprivate |
Writes.