![]() |
MySQL 26.7.0
Source Code Documentation
|
The Event Reader / Controller class. More...
#include <event_reader_controller.h>
Public Member Functions | |
| Event_reader_controller (Relay_log_info *rli, Log_prefetcher_sptr prefetcher) | |
| bool | open () |
| Opens the first relay log. More... | |
| void | close () |
| Closes readers, stops prefetcher, clears internal state including error state. More... | |
| std::optional< Event_file_metadata > | read_next (unsigned int return_timeout_ms, Reader_controller_read_type read_type) |
| Fetches next: event data, event metadata, event metadata plus raw payload, depending on read type. More... | |
| bool | concurrent_purge (const std::string &log_filename) override |
| Register log_filename as a log ready to be purged. More... | |
| const std::string & | get_file_name () const |
| Obtain currently processed file. More... | |
| bool | is_error () const |
| Check if reader has an error. More... | |
| void | stop () |
| Stop the reader. More... | |
| bool | is_stopped () const |
| Check if reader is stopped. More... | |
Public Member Functions inherited from mysql::csa::Log_purge_controller | |
| virtual | ~Log_purge_controller () |
Private Member Functions | |
| bool | move_to_log (bool next_log=true, my_off_t offset=0) |
| When next_log is true, opens the next file. More... | |
| bool | move_to_next_log () |
| Moves to the next log file. More... | |
| bool | purge_applied_logs (const char *to_log) |
| Purge relay log files up to to_log. More... | |
| bool | wait_for_new_event (unsigned int return_timeout_ms) |
| In case we read from active file, we use this function to passively wait for new event. More... | |
| bool | check_cache_truncated () |
| If cache is truncated, reopen the reader to avoid reading trash data. More... | |
| bool | set_error (const char *msg) |
| Sets internal error to msg. More... | |
| bool | is_data_available () |
| Checks whether there is data in the current file. More... | |
| bool | wait_data_ready (unsigned int return_timeout_ms) |
| Waits until data is available, stopped or return_timeout_ms is reached. More... | |
| void | choose_reader (bool next_log, const std::string &prev_file) |
| Implements internal logic to choose between active and inactive file reading. More... | |
Private Attributes | |
| bool | m_is_error {false} |
| Flag which is true in case any error occurred. More... | |
| std::string | m_error_msg {""} |
| Error message if any. More... | |
| Relay_log_info * | m_rli {nullptr} |
| non-owning RLI object pointer More... | |
| Log_prefetcher_sptr | m_prefetcher |
| Relay log prefetcher. More... | |
| Relaylog_file_reader | m_active_reader |
| Reader for active files. More... | |
| Prefetched_relaylog_reader | m_inactive_reader |
| Reader for inactive files. More... | |
| IBasic_binlog_file_reader * | m_current_reader {nullptr} |
| Non-owning pointer to currently used reader (m_inactive_reader or m_active_reader) More... | |
| std::string | m_file_name |
| Stores the current file as obtaining from stream. More... | |
| std::unordered_set< std::string > | m_logs_to_purge |
| Here we keep the list of logs to be purged (in case later logs are applied before), protected with m_rli->data_lock. More... | |
| bool | m_using_prefetcher {false} |
| Flag indicating whether currently opened log file is active. More... | |
| bool | m_active_file_reading {false} |
| This flag is true in case we are using active file reader and reading from the active relay log file. More... | |
| bool | m_enable_prefetcher {tune::prefetcher_enable} |
| Variable to decide on whether we want to run prefetcher. More... | |
| std::atomic< bool > | m_is_stopped {false} |
| Stop flag. More... | |
The Event Reader / Controller class.
This class uses the low level reader to read consecutive events from the relay log. Also, it exposed functions to remove consumed relay log files. Class provides methods to:
register consumed relay log for purge and purge registered consecutive logs (concurrent_purge), which implements the Log_purge_controller interface
This class may be seen as 'Rpl_applier_reader' created for the CSA. Relay_log_decoder works with prefetched relay log files or stream build on top of the IO_CACHE. The first one is used when reading from inactive files. When reading from active files, Event_reader_controller utilizes the IO_CACHE implementation, since it allows the applier to fetch data from cache instead of fetching data from disk. Data will be consumed from cache provided that the applier keeps up with Receiver thread and cache is 'large' enough to keep the recent data. When reading from inactive files, the 'Event_reader_controller' utilizes the prefetcher class utility to fetch data. When reading from active files, the Event Reader / Controller needs to rely on the 'MYSQL_BIN_LOG' synchronization primitives and supply the implementation of passive waiting for data (is_data_available, wait_data_ready). Following the legacy design, streams implemented on top of prefetcher are allowed to move to the next file upon the caller request. Therefore, the 'Event_reader_controller' is responsible for checking file boundaries and reopening the streams on top of new files when needed.
| mysql::csa::Event_reader_controller::Event_reader_controller | ( | Relay_log_info * | rli, |
| Log_prefetcher_sptr | prefetcher | ||
| ) |
|
private |
If cache is truncated, reopen the reader to avoid reading trash data.
Hack function that solves problem of relay log IO_CACHE truncation on active relay log files
|
private |
Implements internal logic to choose between active and inactive file reading.
| next_log | True if open was called on the next log |
| prev_file | Previous relay log file processed |
| void mysql::csa::Event_reader_controller::close | ( | ) |
Closes readers, stops prefetcher, clears internal state including error state.
|
overridevirtual |
Register log_filename as a log ready to be purged.
This function will purge registered logs if they are in order according to the index file content.
| [in] | log_filename | Registeres this log as a log ready to be purged. If registered logs for purging are in order, purges up to log_filename, included. |
Implements mysql::csa::Log_purge_controller.
|
inline |
Obtain currently processed file.
|
private |
Checks whether there is data in the current file.
| true | Data is available |
| false | No data |
For prefetcher, we don't wait for data here, because passive waiting for data is implemented in the prefetcher itself. For active relay log file reading, we need implement passive waiting within the Event_reader_controller and using the MYSQL_BIN_LOG synchronization primitives.
|
inline |
Check if reader has an error.
| bool mysql::csa::Event_reader_controller::is_stopped | ( | ) | const |
Check if reader is stopped.
|
private |
When next_log is true, opens the next file.
Otherwise, opens the current file
| next_log | When true, moves to next log after the current |
| offset | Requested file offset |
| false | Success |
| true | failure |
|
private |
Moves to the next log file.
| false | Success |
| true | failure |
| bool mysql::csa::Event_reader_controller::open | ( | ) |
Opens the first relay log.
| false | Success |
| true | failure |
|
private |
Purge relay log files up to to_log.
| to_log | Purge logs up to this log, exclusively |
| false | Success |
| true | Error |
| std::optional< Event_file_metadata > mysql::csa::Event_reader_controller::read_next | ( | unsigned int | return_timeout_ms, |
| Reader_controller_read_type | read_type | ||
| ) |
Fetches next: event data, event metadata, event metadata plus raw payload, depending on read type.
| return_timeout_ms | If specified, will wait up to return_timeout_ms miliseconds. If timeout is reached, returns true. |
| read_type | Type of read: full event, event metadata or event metadata and raw payload |
|
private |
Sets internal error to msg.
| msg | Error message |
| void mysql::csa::Event_reader_controller::stop | ( | ) |
Stop the reader.
|
private |
Waits until data is available, stopped or return_timeout_ms is reached.
| return_timeout_ms | Timeout after which we will exit from waiting |
| true | Data is available |
| false | Data is not ready / stopped / error |
|
private |
In case we read from active file, we use this function to passively wait for new event.
| return_timeout_ms | Timeout after which we will exit from waiting |
| false | New event is available |
| true | Timeout occurred |
|
private |
This flag is true in case we are using active file reader and reading from the active relay log file.
|
private |
Reader for active files.
|
private |
Non-owning pointer to currently used reader (m_inactive_reader or m_active_reader)
|
private |
Variable to decide on whether we want to run prefetcher.
|
private |
Error message if any.
|
private |
Stores the current file as obtaining from stream.
|
private |
Reader for inactive files.
|
private |
Flag which is true in case any error occurred.
Otherwise, it is set to false.
|
private |
Stop flag.
|
private |
Here we keep the list of logs to be purged (in case later logs are applied before), protected with m_rli->data_lock.
|
private |
Relay log prefetcher.
|
private |
non-owning RLI object pointer
|
private |
Flag indicating whether currently opened log file is active.