MySQL 8.0.40
Source Code Documentation
|
The major logic of dump thread is implemented in this class. More...
#include <rpl_binlog_sender.h>
Classes | |
class | Event_allocator |
Binlog_sender reads events one by one. More... | |
Public Member Functions | |
Binlog_sender (THD *thd, const char *start_file, my_off_t start_pos, Gtid_set *exclude_gtids, uint32 flag) | |
~Binlog_sender ()=default | |
void | run () |
It checks the dump request and sends events to the client until it finish all events(for mysqlbinlog) or encounters an error. More... | |
void | set_prev_event_type (binary_log::Log_event_type type) |
Sets the value of the previously processed event. More... | |
Private Types | |
typedef Basic_binlog_file_reader< Binlog_ifile, Binlog_event_data_istream, Binlog_event_object_istream, Event_allocator > | File_reader |
Private Member Functions | |
bool | stop_waiting_for_update (my_off_t log_pos) const |
Checks whether thread should continue awaiting new events. More... | |
void | init () |
void | cleanup () |
void | init_heartbeat_period () |
void | init_checksum_alg () |
int | check_start_file () |
Check if the requested binlog file and position are valid. More... | |
const char * | log_read_error_msg (Binlog_read_error::Error_type error) |
Transform read error numbers to error messages. More... | |
int | send_binlog (File_reader &reader, my_off_t start_pos) |
It dumps a binlog file. More... | |
int | send_events (File_reader &reader, my_off_t end_pos) |
It sends some events in a binlog file to the client. More... | |
std::pair< my_off_t, int > | get_binlog_end_pos (File_reader &reader) |
It gets the end position of the binlog file. More... | |
int | has_previous_gtid_log_event (File_reader &reader, bool *found) |
It checks if a binlog file has Previous_gtid_log_event. More... | |
int | fake_rotate_event (const char *next_log_file, my_off_t log_pos) |
It sends a faked rotate event which does not exist physically in any binlog to the slave. More... | |
int | send_format_description_event (File_reader &reader, my_off_t start_pos) |
When starting to dump a binlog file, Format_description_log_event is read and sent first. More... | |
int | send_heartbeat_event_v1 (my_off_t log_pos) |
It sends a heartbeat to the client. More... | |
int | send_heartbeat_event_v2 (my_off_t log_pos) |
It sends a heartbeat to the client, for the cases when the flag USE_HEARTBEAT_EVENT_V2 is set. More... | |
int | send_heartbeat_event (my_off_t log_pos) |
Checks if the heartbeat_version flag is set or not, and call the correct send_heartbeat_method accordingly. More... | |
int | read_event (File_reader &reader, uchar **event_ptr, uint32 *event_len) |
It reads an event from binlog file. More... | |
bool | check_event_type (binary_log::Log_event_type type, const char *log_file, my_off_t log_pos) |
Check if it is allowed to send this event type. More... | |
bool | skip_event (const uchar *event_ptr, bool in_exclude_group) |
It checks if the event is in m_exclude_gtid. More... | |
void | calc_event_checksum (uchar *event_ptr, size_t event_len) |
int | flush_net () |
int | send_packet () |
int | send_packet_and_flush () |
int | before_send_hook (const char *log_file, my_off_t log_pos) |
int | after_send_hook (const char *log_file, my_off_t log_pos) |
int | reset_transmit_packet (ushort flags, size_t event_len=0) |
int | wait_new_events (my_off_t log_pos) |
It waits until receiving an update_cond signal. More... | |
int | wait_with_heartbeat (my_off_t log_pos) |
int | wait_without_heartbeat (my_off_t log_pos) |
int | check_event_count () |
bool | has_error () |
void | set_error (int errorno, const char *errmsg) |
void | set_unknown_error (const char *errmsg) |
void | set_fatal_error (const char *errmsg) |
bool | is_fatal_error () |
bool | event_checksum_on () |
void | set_last_pos (my_off_t log_pos) |
void | set_last_file (const char *log_file) |
bool | grow_packet (size_t extra_size) |
This function SHALL grow the buffer of the packet if needed. More... | |
bool | shrink_packet () |
This function SHALL shrink the size of the buffer used. More... | |
size_t | calc_grow_buffer_size (size_t current_size, size_t min_size) |
Helper function to recalculate a new size for the growing buffer. More... | |
void | calc_shrink_buffer_size (size_t current_size) |
Helper function to recalculate the new size for the m_new_shrink_size. More... | |
Private Attributes | |
THD * | m_thd |
String & | m_packet |
const char * | m_start_file |
my_off_t | m_start_pos |
Gtid_set * | m_exclude_gtid |
bool | m_using_gtid_protocol |
bool | m_check_previous_gtid_event |
bool | m_gtid_clear_fd_created_flag |
LOG_INFO | m_linfo |
binary_log::enum_binlog_checksum_alg | m_event_checksum_alg |
binary_log::enum_binlog_checksum_alg | m_slave_checksum_alg |
std::chrono::nanoseconds | m_heartbeat_period |
std::chrono::nanoseconds | m_last_event_sent_ts |
bool | m_wait_new_events |
Diagnostics_area | m_diag_area |
char | m_errmsg_buf [MYSQL_ERRMSG_SIZE] |
const char * | m_errmsg |
int | m_errno |
char | m_last_file_buf [FN_REFLEN] |
const char * | m_last_file |
my_off_t | m_last_pos |
ushort | m_half_buffer_size_req_counter |
size_t | m_new_shrink_size |
uint32 | m_flag |
bool | m_observe_transmission |
bool | m_transmit_started |
binary_log::Log_event_type | m_prev_event_type |
Type of the previously processed event. More... | |
int | m_event_count |
Static Private Attributes | |
static const uint32 | PACKET_MAX_SIZE = UINT_MAX32 |
static const ushort | PACKET_SHRINK_COUNTER_THRESHOLD = 100 |
static const uint32 | PACKET_MIN_SIZE = 4096 |
The minimum size of the buffer. More... | |
static const float | PACKET_GROW_FACTOR = 2.0 |
How much to grow the buffer each time we need to accommodate more bytes than it currently can hold. More... | |
static const float | PACKET_SHRINK_FACTOR = 0.5 |
The dual of PACKET_GROW_FACTOR. More... | |
The major logic of dump thread is implemented in this class.
It sends required binlog events to clients according to their requests.
|
private |
Binlog_sender::Binlog_sender | ( | THD * | thd, |
const char * | start_file, | ||
my_off_t | start_pos, | ||
Gtid_set * | exclude_gtids, | ||
uint32 | flag | ||
) |
|
default |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
Helper function to recalculate a new size for the growing buffer.
current_size | The baseline (for instance, the current buffer size). |
min_size | The resulting buffer size, needs to be at least as large as this parameter states. |
|
private |
Helper function to recalculate the new size for the m_new_shrink_size.
current_size | The baseline (for instance, the current buffer size). |
|
inlineprivate |
|
private |
Check if it is allowed to send this event type.
The following are disallowed:
type | The event type. |
log_file | The binary log file (used in error messages). |
log_pos | The binary log position (used in error messages). |
true | The event is not allowed. In this case, this function calls set_fatal_error(). |
false | The event is allowed. |
|
private |
Check if the requested binlog file and position are valid.
|
private |
|
inlineprivate |
|
private |
It sends a faked rotate event which does not exist physically in any binlog to the slave.
It contains the name of the binlog we are going to send to the slave.
Faked rotate event is required in a few cases, so slave can know which binlog the following events are from.
[in] | next_log_file | The name of the binlog file will be sent after the rotate event. |
[in] | log_pos | The start position of the binlog file. |
|
inlineprivate |
|
private |
It gets the end position of the binlog file.
[in] | reader | File_reader of binlog will be checked |
|
inlineprivate |
This function SHALL grow the buffer of the packet if needed.
If the buffer used for the packet is large enough to accommodate the requested extra bytes, then this function does not do anything.
On the other hand, if the requested size is bigger than the available free bytes in the buffer, the buffer is extended by a constant factor (PACKET_GROW_FACTOR
).
extra_size | The size in bytes that the caller wants to add to the buffer. |
|
inlineprivate |
|
private |
It checks if a binlog file has Previous_gtid_log_event.
[in] | reader | File_reader of binlog will be checked |
[out] | found | Found Previous_gtid_log_event or not |
|
private |
|
private |
|
private |
|
inlineprivate |
|
private |
Transform read error numbers to error messages.
|
inlineprivate |
It reads an event from binlog file.
this function can set event_ptr either a valid buffer pointer or nullptr. nullptr means it arrives at the end of the binlog file if no error happens.
[in] | reader | File_reader of the binlog file. |
[out] | event_ptr | The buffer used to store the event. |
[out] | event_len | Length of the event. |
0 | Succeed |
1 | Fail |
|
inlineprivate |
void Binlog_sender::run | ( | ) |
It checks the dump request and sends events to the client until it finish all events(for mysqlbinlog) or encounters an error.
|
private |
It dumps a binlog file.
Events are read and sent one by one. If it need to wait for new events, it will wait after already reading all events in the active log file.
[in] | reader | File_reader of binlog will be sent |
[in] | start_pos | Position requested by the slave's IO thread. Only the events after the position are sent. |
|
private |
It sends some events in a binlog file to the client.
[in] | reader | File_reader of binlog will be sent |
[in] | end_pos | Only the events before end_pos are sent |
|
private |
When starting to dump a binlog file, Format_description_log_event is read and sent first.
If the requested position is after Format_description_log_event, log_pos field in the first Format_description_log_event has to be set to 0. So the slave will not increment its master's binlog position.
[in] | reader | File_reader of the binlog will be dumpped |
[in] | start_pos | Position requested by the slave's IO thread. Only the events after the position are sent. |
|
private |
Checks if the heartbeat_version flag is set or not, and call the correct send_heartbeat_method accordingly.
[in] | log_pos | The log position that events before it are sent. |
|
private |
It sends a heartbeat to the client.
[in] | log_pos | The log position that events before it are sent. |
|
private |
It sends a heartbeat to the client, for the cases when the flag USE_HEARTBEAT_EVENT_V2 is set.
[in] | log_pos | The log position that events before it are sent. |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inline |
Sets the value of the previously processed event.
type | The last processed event type. |
|
inlineprivate |
|
inlineprivate |
This function SHALL shrink the size of the buffer used.
If less than half of the buffer was used in the last N (PACKET_SHRINK_COUNTER_THRESHOLD
) consecutive times this function was called, then the buffer gets shrunk by a constant factor (PACKET_SHRINK_FACTOR
).
The buffer is never shrunk less than a minimum size (PACKET_MIN_SIZE
).
|
inlineprivate |
It checks if the event is in m_exclude_gtid.
Clients may request to exclude some GTIDs. The events include in the GTID groups will be skipped. We call below events sequence as a goup, Gtid_log_event BEGIN ... COMMIT or ROLLBACK
or Gtid_log_event DDL statement
[in] | event_ptr | Buffer of the event |
[in] | in_exclude_group | If it is in a exclude group |
|
private |
Checks whether thread should continue awaiting new events.
log_pos | Last processed (sent) event id |
|
private |
It waits until receiving an update_cond signal.
It will send heartbeat periodically if m_heartbeat_period is set.
[in] | log_pos | The end position of the last event it already sent. It is required by heartbeat events. |
|
inlineprivate |
|
inlineprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Type of the previously processed event.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticprivate |
How much to grow the buffer each time we need to accommodate more bytes than it currently can hold.
|
staticprivate |
|
staticprivate |
The minimum size of the buffer.
|
staticprivate |
|
staticprivate |
The dual of PACKET_GROW_FACTOR.
How much to shrink the buffer each time it is deemed to being underused.