MySQL 9.1.0
Source Code Documentation
rpl_source.h
Go to the documentation of this file.
1#ifndef RPL_SOURCE_H_INCLUDED
2#define RPL_SOURCE_H_INCLUDED
3
4/* Copyright (c) 2010, 2024, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is designed to work with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License, version 2.0, for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
26
27#include <stddef.h>
28#include <string> // std::string
29
30#include "my_hostname.h" // HOSTNAME_LENGTH
31#include "my_inttypes.h"
32#include "my_thread_local.h" // my_thread_id
33#include "mysql/gtid/uuid.h" // UUID
34#include "mysql_com.h" // USERNAME_LENGTH
35#include "sql/resource_blocker.h" // resource_blocker::User and Resource
36#include "sql/sql_const.h" // MAX_PASSWORD_LENGTH
37
38class Gtid_set;
39class String;
40class THD;
41
42extern bool server_id_supplied;
43extern int max_binlog_dump_events;
46
47// Returns the rpl_resource
49
60};
61
62int register_replica(THD *thd, uchar *packet, size_t packet_length);
63void unregister_replica(THD *thd, bool only_mine, bool need_lock_slave_list);
64bool show_replicas(THD *thd);
65String *get_replica_uuid(THD *thd, String *value);
67bool show_binlogs(THD *thd);
69
70/**
71 Process a COM_BINLOG_DUMP_GTID packet.
72
73 This function parses the packet and then calls mysql_binlog_send.
74
75 @param thd The dump thread.
76 @param packet The COM_BINLOG_DUMP_GTID packet.
77 @param packet_length The length of the packet in bytes.
78 @retval true Error
79 @retval false Success
80*/
81bool com_binlog_dump_gtid(THD *thd, char *packet, size_t packet_length);
82
83/**
84 Process a COM_BINLOG_DUMP packet.
85
86 This function parses the packet and then calls mysql_binlog_send.
87
88 @param thd The dump thread.
89 @param packet The COM_BINLOG_DUMP packet.
90 @param packet_length The length of the packet in bytes.
91 @retval true Error
92 @retval false Success
93*/
94bool com_binlog_dump(THD *thd, char *packet, size_t packet_length);
95
96/**
97 Low-level function where the dump thread iterates over the binary
98 log and sends events to the slave. This function is common for both
99 COM_BINLOG_DUMP and COM_BINLOG_DUMP_GTID.
100
101 @param thd The dump thread.
102
103 @param log_ident The filename of the binary log, as given in the
104 COM_BINLOG_DUMP[_GTID] packet. If this is is an empty string (first
105 character is '\0'), we start with the oldest binary log.
106
107 @param pos The offset in the binary log, as given in the
108 COM_BINLOG_DUMP[_GTID] packet. This must be at least 4 and at most
109 the size of the binary log file.
110
111 @param gtid_set The gtid_set that the slave sent, or NULL if the
112 protocol is COM_BINLOG_DUMP.
113
114 @param flags flags in COM_BINLOG_DUMP[_GTID] packets.
115
116 @note This function will start reading at the given (filename,
117 offset), or from the oldest log if filename[0]==0. It will send all
118 events from that position; but if gtid_set!=NULL, it will skip all
119 events in that set.
120*/
121void mysql_binlog_send(THD *thd, char *log_ident, my_off_t pos,
122 Gtid_set *gtid_set, uint32 flags);
123
124bool reset_binary_logs_and_gtids(THD *thd, bool unlock_read_lock);
125
126class user_var_entry;
127/**
128 Read a user variable that may exist under two different names.
129
130 @param thd The session to read from.
131
132 @param alt1 The first variable name alternative.
133
134 @param alt2 The second variable name alternative.
135
136 @retval If there exists a user variable in the current session with
137 the first name, return that. Otherwise, if the second one exists,
138 return that. Otherwise, return NULL.
139*/
141 const std::string alt1,
142 const std::string alt2);
143
144#endif /* RPL_SOURCE_H_INCLUDED */
Represents a set of GTIDs.
Definition: rpl_gtid.h:1557
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Represents a "Resource" which can be either "used" by a number of threads, or "blocked" by a number o...
Definition: resource_blocker.h:70
Definition: item_func.h:3095
bool server_id_supplied
Definition: mysqld.cc:1212
static int flags[50]
Definition: hp_test1.cc:40
Common definition used by mysys, performance schema and server & client.
static constexpr int HOSTNAME_LENGTH
Definition: my_hostname.h:43
Some integer typedefs for easier portability.
ulonglong my_off_t
Definition: my_inttypes.h:72
unsigned char uchar
Definition: my_inttypes.h:52
uint16_t uint16
Definition: my_inttypes.h:65
uint32_t uint32
Definition: my_inttypes.h:67
uint32 my_thread_id
Definition: my_thread_local.h:34
Common definition between mysql server & client.
#define USERNAME_LENGTH
Definition: mysql_com.h:69
void mysql_binlog_send(THD *thd, char *log_ident, my_off_t pos, Gtid_set *gtid_set, uint32 flags)
Low-level function where the dump thread iterates over the binary log and sends events to the slave.
Definition: rpl_source.cc:1043
const user_var_entry * get_user_var_from_alternatives(const THD *thd, const std::string alt1, const std::string alt2)
Read a user variable that may exist under two different names.
Definition: rpl_source.cc:1050
resource_blocker::Resource & get_dump_thread_resource()
Definition: rpl_source.cc:87
bool com_binlog_dump(THD *thd, char *packet, size_t packet_length)
Process a COM_BINLOG_DUMP packet.
Definition: rpl_source.cc:921
int max_binlog_dump_events
Definition: rpl_source.cc:81
bool show_binlogs(THD *thd)
Execute a SHOW BINARY LOGS statement.
Definition: rpl_source.cc:1320
void unregister_replica(THD *thd, bool only_mine, bool need_lock_slave_list)
Definition: rpl_source.cc:206
void kill_zombie_dump_threads(THD *thd)
Definition: rpl_source.cc:1145
int register_replica(THD *thd, uchar *packet, size_t packet_length)
Register slave in 'slave_list' hash table.
Definition: rpl_source.cc:142
bool show_binary_log_status(THD *thd)
Execute a SHOW BINARY LOG STATUS statement.
Definition: rpl_source.cc:1259
bool com_binlog_dump_gtid(THD *thd, char *packet, size_t packet_length)
Process a COM_BINLOG_DUMP_GTID packet.
Definition: rpl_source.cc:973
bool opt_show_replica_auth_info
Definition: mysqld.cc:1256
String * get_replica_uuid(THD *thd, String *value)
An auxiliary function extracts slave UUID.
Definition: rpl_source.cc:1069
bool opt_sporadic_binlog_dump_fail
Definition: rpl_source.cc:82
bool show_replicas(THD *thd)
Execute a SHOW REPLICAS statement.
Definition: rpl_source.cc:231
bool reset_binary_logs_and_gtids(THD *thd, bool unlock_read_lock)
Execute a RESET BINARY LOGS AND GTIDS statement.
Definition: rpl_source.cc:1187
File containing constants that can be used throughout the server.
Definition: rpl_source.h:50
char host[HOSTNAME_LENGTH+1]
Definition: rpl_source.h:53
my_thread_id thd_id
Definition: rpl_source.h:57
uint16 port
Definition: rpl_source.h:56
mysql::gtid::Uuid replica_uuid
Definition: rpl_source.h:58
char user[USERNAME_LENGTH+1]
Definition: rpl_source.h:54
uint32 master_id
Definition: rpl_source.h:52
uint32 rpl_recovery_rank
Definition: rpl_source.h:52
char password[MAX_PASSWORD_LENGTH+1]
Definition: rpl_source.h:55
bool valid_replica_uuid
Definition: rpl_source.h:59
uint32 server_id
Definition: rpl_source.h:51
Uuid is a trivial and of standard layout The structure contains the following components.
Definition: uuid.h:64
#define MAX_PASSWORD_LENGTH
Definition: validate_password.cc:66