![]() |
MySQL 26.7.0
Source Code Documentation
|
This class starts an asynchronous thread that prefetches consecutive logs recorded in the index file. More...
#include <log_prefetcher.h>
Public Types | |
| using | Mt_key = mysql::concurrency::Mutex_key |
| using | Cv_key = mysql::concurrency::Cv_key |
| using | Th_key = mysql::concurrency::Thread_key |
| using | Mem_key = PSI_memory_key |
| using | Memory_allocator = mysql::allocators::Allocator< uint8_t > |
| using | Data_type = Data_source |
| using | Elem_type = Data_source_sptr |
Public Member Functions | |
| Log_prefetcher (MYSQL_BIN_LOG *log_ptr, Mt_key mt_key_wait=0, Cv_key cv_key_wait=0, Mt_key mt_key_file_move=0, Cv_key cv_key_file_move=0, Th_key key_th_prefetcher=0, Mem_key key_memory=0) | |
| virtual | ~Log_prefetcher () |
| Log_prefetcher (const Log_prefetcher &)=delete | |
| Log_prefetcher & | operator= (const Log_prefetcher &)=delete |
| Log_prefetcher (Log_prefetcher &&)=delete | |
| Log_prefetcher & | operator= (Log_prefetcher &&)=delete |
| void | start_prefetcher () |
| Starts asynchronous thread prefetching data. More... | |
| bool | open (const char *file_name) |
| Tries to open a new, gifen file. More... | |
| template<typename P > | |
| std::optional< Elem_type > | dequeue (P &&wait_predicate) |
| Consumes the next batch of data. More... | |
| bool | is_stopped () const |
| Checks whether prefetcher is stopped. More... | |
| void | stop () |
| Gracefully stops the prefetcher. More... | |
| bool | is_error () const |
| Returns true if error occurred. More... | |
| bool | is_waiting_for_next_file (const std::string &prev_file, const std::string &next_file) |
| Checks whether we reached inactive file after the prev_file This function takes previous file to check if prefetcher finished rotation on this file and consecutive file to check if prefetcher opened it and stopped working until file becomes inactive. More... | |
Private Types | |
| using | Thread_type = mysql::concurrency::Thread |
| Thread type. More... | |
| using | Locking_queue_type = mysql::concurrency::Locking_queue< Elem_type > |
| using | Sync_bounded_queue = mysql::concurrency::Sync_bounded_queue< Elem_type, tune::prefetcher_queue_max_size > |
| using | Queue_type = std::conditional< tune::csa_prefetcher_simple_queue, Locking_queue_type, Sync_bounded_queue >::type |
Private Member Functions | |
| bool | open_file (bool next_file) |
| Opens new or next file for reading. More... | |
| void | ensure_file_done (const std::string &file_name) |
| If currently rotated file is file_name, waits until rotate is done. More... | |
| void | set_error (const char *msg) |
| Sets internal error (under lock) and internal error message. More... | |
| std::string | get_current_file () const |
| Obtains the current file under the lock. More... | |
| void | update_current_file (const char *file_name, bool active) |
| Updates the current file and its activity under the lock. More... | |
| void | run_prefetch_thread () |
| Runs a thread that prefetch data from the relay log. More... | |
Private Attributes | |
| std::atomic< bool > | m_stopped {false} |
| Internal stop flag set to true when stop of the thread is requested. More... | |
| MYSQL_BIN_LOG * | m_log |
| The MYSQL_BIN_LOG object we use to know from where we need to read data. More... | |
| Queue_type | m_cache |
| Queue into which prefetcher puts data batches read from a raw binary file. More... | |
| Thread_type | m_prefetcher |
| Thread that runs prefetching. More... | |
| bool | m_log_active {true} |
| True in case reading from the active relay log file (used currently by the receiver thread), protected with m_mt_prefetcher. More... | |
| mysql::concurrency::Mutex | m_mt_prefetcher |
| Mutex protecting access to m_tasks. More... | |
| mysql::concurrency::Condition_variable | m_cv_prefetcher |
| Cv used by the scheduler main thread to wait on, when no task is available or tasks in m_task queue are not read to execute. More... | |
| std::atomic< bool > | m_end {false} |
| Notification atomic for end of execution. More... | |
| mysql::concurrency::Mutex | m_mt_move_file |
| Mutex protecting access to m_move_file. More... | |
| mysql::concurrency::Condition_variable | m_cv_move_file |
| CV to notify the watcher that prefetcher finished moving from m_move_file to the next file (see ensure_file_done) More... | |
| std::string | m_move_file {""} |
| Is set to a value if prefetcher initiated file move procedure Watcher may wait until prefetcher moves to the next file by using the m_cv_move_file notification cv and associated m_mt_move_file. More... | |
| std::atomic< std::size_t > | m_bytes_fetched {0} |
| This way we track the actual number of bytes that are cached in the m_cache. More... | |
| std::size_t | m_batch_size {tune::prefetcher_batch_size} |
| Default batch size ~16MB. More... | |
| std::ifstream | m_istream |
| Stream to read from. More... | |
| std::string | m_error_message {""} |
| Error message if any. Protected by m_mt_prefetcher. More... | |
| std::atomic< bool > | m_is_error {false} |
| Becomes true in case error has been encountered. More... | |
| std::string | m_current_log_name {""} |
| Currently processed log file Protected by m_mt_prefetcher. More... | |
| std::size_t | m_current_file_length {0} |
| Length of the currently opened file. More... | |
| std::size_t | m_current_offset {0} |
| Current file offset. More... | |
| Th_key | m_key_th_prefetcher {0} |
| Key for prefetcher thread. More... | |
| Memory_allocator | m_allocator |
| Memory_resource to handle all allocations. More... | |
Static Private Attributes | |
| static constexpr std::size_t | max_bytes_fetched {1073741824} |
| The maximum number of bytes we can prefetch. More... | |
This class starts an asynchronous thread that prefetches consecutive logs recorded in the index file.
It contains the following main functions:
|
private |
| using mysql::csa::Log_prefetcher::Memory_allocator = mysql::allocators::Allocator<uint8_t> |
|
private |
|
private |
|
private |
Thread type.
| mysql::csa::Log_prefetcher::Log_prefetcher | ( | MYSQL_BIN_LOG * | log_ptr, |
| Mt_key | mt_key_wait = 0, |
||
| Cv_key | cv_key_wait = 0, |
||
| Mt_key | mt_key_file_move = 0, |
||
| Cv_key | cv_key_file_move = 0, |
||
| Th_key | key_th_prefetcher = 0, |
||
| Mem_key | key_memory = 0 |
||
| ) |
| log_ptr | The MYSQL_BIN_LOG object we use to know from where we need to read data |
| mt_key_wait | Instrumentation key for internal mutex (wait for work) |
| cv_key_wait | Instrumentation key for internal cv (wait for work) |
| mt_key_file_move | Instrumentation key for internal mutex (wait for file rotation) |
| cv_key_file_move | Instrumentation key for internal cv (wait for file rotation) |
| key_th_prefetcher | Instrumentation key for prefetcher thread |
| key_memory | Instrumentation key for allocated memory |
|
virtual |
|
delete |
|
delete |
| std::optional< Log_prefetcher::Elem_type > mysql::csa::Log_prefetcher::dequeue | ( | P && | wait_predicate | ) |
Consumes the next batch of data.
|
private |
If currently rotated file is file_name, waits until rotate is done.
If prefetcher moves a different file, function returns immediately.
| file_name | File expected to be moved from. |
|
private |
Obtains the current file under the lock.
| bool mysql::csa::Log_prefetcher::is_error | ( | ) | const |
Returns true if error occurred.
| bool mysql::csa::Log_prefetcher::is_stopped | ( | ) | const |
Checks whether prefetcher is stopped.
True if stop was requested, false otherwise
| bool mysql::csa::Log_prefetcher::is_waiting_for_next_file | ( | const std::string & | prev_file, |
| const std::string & | next_file | ||
| ) |
Checks whether we reached inactive file after the prev_file This function takes previous file to check if prefetcher finished rotation on this file and consecutive file to check if prefetcher opened it and stopped working until file becomes inactive.
| prev_file | File we know we read all data from (got eof in the last consumed batch) to check if prefetcher finished rotation on this file |
| next_file | Consecutive file we want to open the stream on. |
| true | Prefetcher waits for file_name to become inactive |
| false | Prefetcher does not wait for 'file_name' |
| bool mysql::csa::Log_prefetcher::open | ( | const char * | file_name | ) |
Tries to open a new, gifen file.
Prefetcher must stop on cv before calling this function (see is_waiting_for_next_file).
| file_name | Starts reading from this file path |
|
private |
Opens new or next file for reading.
| next_file | True if reading file after the current one |
|
delete |
|
delete |
|
private |
Runs a thread that prefetch data from the relay log.
get file name after wait (updated by open)
|
private |
Sets internal error (under lock) and internal error message.
Later on, stops the prefetcher. This function will report any error to error log
| msg | Error message |
| void mysql::csa::Log_prefetcher::start_prefetcher | ( | ) |
Starts asynchronous thread prefetching data.
| void mysql::csa::Log_prefetcher::stop | ( | ) |
Gracefully stops the prefetcher.
Blocks waiting for notification that prefetcher thread is done
|
private |
Updates the current file and its activity under the lock.
| file_name | Update the current file name to this file |
| active | True if file_name is an active log |
|
private |
Memory_resource to handle all allocations.
|
private |
Default batch size ~16MB.
|
private |
This way we track the actual number of bytes that are cached in the m_cache.
|
private |
Queue into which prefetcher puts data batches read from a raw binary file.
|
private |
Length of the currently opened file.
|
private |
Currently processed log file Protected by m_mt_prefetcher.
|
private |
Current file offset.
|
private |
CV to notify the watcher that prefetcher finished moving from m_move_file to the next file (see ensure_file_done)
|
private |
Cv used by the scheduler main thread to wait on, when no task is available or tasks in m_task queue are not read to execute.
|
private |
Notification atomic for end of execution.
|
private |
Error message if any. Protected by m_mt_prefetcher.
|
private |
Becomes true in case error has been encountered.
|
private |
Stream to read from.
|
private |
Key for prefetcher thread.
|
private |
The MYSQL_BIN_LOG object we use to know from where we need to read data.
|
private |
True in case reading from the active relay log file (used currently by the receiver thread), protected with m_mt_prefetcher.
Prefetcher can read only from inactive files Protected by m_mt_prefetcher
|
private |
Is set to a value if prefetcher initiated file move procedure Watcher may wait until prefetcher moves to the next file by using the m_cv_move_file notification cv and associated m_mt_move_file.
|
mutableprivate |
Mutex protecting access to m_move_file.
|
mutableprivate |
Mutex protecting access to m_tasks.
|
private |
Thread that runs prefetching.
|
private |
Internal stop flag set to true when stop of the thread is requested.
|
staticconstexprprivate |
The maximum number of bytes we can prefetch.