24#ifndef MYSQL_CSA_LOG_PREFETCHER_H
25#define MYSQL_CSA_LOG_PREFETCHER_H
79 Cv_key cv_key_file_move = 0,
Th_key key_th_prefetcher = 0,
104 template <
typename P>
105 std::optional<Elem_type>
dequeue(
P &&wait_predicate);
129 const std::string &next_file);
MySQL wrapper for a condition variable, using mysql_cond_t as implementation of a condition variable ...
Definition: condition_variable_wrapper.h:37
MySQL wrapper for a mutex, template which may be specialized with a specific implementation of a mute...
Definition: mutex_wrapper.h:38
Bounded concurrent queue supporting multiple producers and consumers.
Definition: sync_bounded_queue.h:84
Wrapper to mysql thread, which matches interface of std::thread.
Definition: thread_srv.h:46
Represents a cached chunk of data that comes from the specific relay log file (events / headers may c...
Definition: data_source.h:45
This class starts an asynchronous thread that prefetches consecutive logs recorded in the index file.
Definition: log_prefetcher.h:60
void set_error(const char *msg)
Sets internal error (under lock) and internal error message.
Definition: log_prefetcher.cpp:204
Memory_allocator m_allocator
Memory_resource to handle all allocations.
Definition: log_prefetcher.h:244
std::string m_error_message
Error message if any. Protected by m_mt_prefetcher.
Definition: log_prefetcher.h:225
std::atomic< bool > m_end
Notification atomic for end of execution.
Definition: log_prefetcher.h:199
Log_prefetcher & operator=(const Log_prefetcher &)=delete
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)
Definition: log_prefetcher.cpp:37
bool is_error() const
Returns true if error occurred.
Definition: log_prefetcher.cpp:180
std::string m_move_file
Is set to a value if prefetcher initiated file move procedure Watcher may wait until prefetcher moves...
Definition: log_prefetcher.h:211
mysql::concurrency::Cv_key Cv_key
Definition: log_prefetcher.h:63
Log_prefetcher & operator=(Log_prefetcher &&)=delete
bool open(const char *file_name)
Tries to open a new, gifen file.
Definition: log_prefetcher.cpp:98
bool is_stopped() const
Checks whether prefetcher is stopped.
Definition: log_prefetcher.cpp:212
std::conditional< tune::csa_prefetcher_simple_queue, Locking_queue_type, Sync_bounded_queue >::type Queue_type
Definition: log_prefetcher.h:171
bool open_file(bool next_file)
Opens new or next file for reading.
Definition: log_prefetcher.cpp:57
std::atomic< bool > m_stopped
Internal stop flag set to true when stop of the thread is requested.
Definition: log_prefetcher.h:148
std::atomic< std::size_t > m_bytes_fetched
This way we track the actual number of bytes that are cached in the m_cache.
Definition: log_prefetcher.h:215
std::size_t m_batch_size
Default batch size ~16MB.
Definition: log_prefetcher.h:217
std::ifstream m_istream
Stream to read from.
Definition: log_prefetcher.h:222
virtual ~Log_prefetcher()
Definition: log_prefetcher.cpp:50
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 ensur...
Definition: log_prefetcher.h:205
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 chec...
Definition: log_prefetcher.cpp:193
static constexpr std::size_t max_bytes_fetched
The maximum number of bytes we can prefetch.
Definition: log_prefetcher.h:219
std::string get_current_file() const
Obtains the current file under the lock.
Definition: log_prefetcher.cpp:182
Th_key m_key_th_prefetcher
Key for prefetcher thread.
Definition: log_prefetcher.h:241
std::atomic< bool > m_is_error
Becomes true in case error has been encountered.
Definition: log_prefetcher.h:228
std::optional< Elem_type > dequeue(P &&wait_predicate)
Consumes the next batch of data.
Definition: log_prefetcher_impl.hpp:34
Data_source_sptr Elem_type
Definition: log_prefetcher.h:89
mysql::concurrency::Thread_key Th_key
Definition: log_prefetcher.h:64
mysql::concurrency::Locking_queue< Elem_type > Locking_queue_type
Definition: log_prefetcher.h:165
void ensure_file_done(const std::string &file_name)
If currently rotated file is file_name, waits until rotate is done.
Definition: log_prefetcher.cpp:172
Thread_type m_prefetcher
Thread that runs prefetching.
Definition: log_prefetcher.h:181
mysql::concurrency::Mutex_key Mt_key
Definition: log_prefetcher.h:62
void update_current_file(const char *file_name, bool active)
Updates the current file and its activity under the lock.
Definition: log_prefetcher.cpp:187
MYSQL_BIN_LOG * m_log
The MYSQL_BIN_LOG object we use to know from where we need to read data.
Definition: log_prefetcher.h:174
Log_prefetcher(Log_prefetcher &&)=delete
std::string m_current_log_name
Currently processed log file Protected by m_mt_prefetcher.
Definition: log_prefetcher.h:232
PSI_memory_key Mem_key
Definition: log_prefetcher.h:65
std::size_t m_current_file_length
Length of the currently opened file.
Definition: log_prefetcher.h:235
Log_prefetcher(const Log_prefetcher &)=delete
std::size_t m_current_offset
Current file offset.
Definition: log_prefetcher.h:238
mysql::concurrency::Mutex m_mt_prefetcher
Mutex protecting access to m_tasks.
Definition: log_prefetcher.h:193
void stop()
Gracefully stops the prefetcher.
Definition: log_prefetcher.cpp:164
bool m_log_active
True in case reading from the active relay log file (used currently by the receiver thread),...
Definition: log_prefetcher.h:187
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 a...
Definition: log_prefetcher.h:196
Queue_type m_cache
Queue into which prefetcher puts data batches read from a raw binary file.
Definition: log_prefetcher.h:178
void start_prefetcher()
Starts asynchronous thread prefetching data.
Definition: log_prefetcher.cpp:52
void run_prefetch_thread()
Runs a thread that prefetch data from the relay log.
Definition: log_prefetcher.cpp:107
mysql::concurrency::Mutex m_mt_move_file
Mutex protecting access to m_move_file.
Definition: log_prefetcher.h:202
#define P
Definition: dtoa.cc:620
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:49
Allocator class that uses a polymorphic Memory_resource to allocate memory.
Class that wraps resources in a polymorphic manner.
std::string file_name(Log_file_id file_id)
Provides name of the log file with the given file id, e.g.
Definition: log0pre_8_0_30.cc:45
PSI_cond_key Cv_key
Definition: condition_variable_srv.h:39
PSI_mutex_key Mutex_key
Definition: mutex_srv.h:41
std::thread Thread
Definition: thread_stl.h:42
PSI_thread_key Thread_key
Definition: thread_srv.h:43
constexpr std::size_t prefetcher_batch_size
Definition: tune.h:44
constexpr bool csa_prefetcher_simple_queue
Definition: tune.h:42
constexpr std::size_t prefetcher_queue_max_size
Definition: tune.h:43
Definition: channel.cpp:28
std::shared_ptr< Log_prefetcher > Log_prefetcher_sptr
Definition: log_prefetcher.h:48
std::shared_ptr< Data_source > Data_source_sptr
Definition: data_source.h:39
required string type
Definition: replication_group_member_actions.proto:34