1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
|
/* Copyright (c) 2014, 2025, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#ifndef REPLICATION_THREADS_API_INCLUDE
#define REPLICATION_THREADS_API_INCLUDE
#include <mysql/group_replication_priv.h>
#include <stddef.h>
#include <string>
#include "my_inttypes.h"
#define DEFAULT_THREAD_PRIORITY 0
// Applier thread InnoDB priority
#define GROUP_REPLICATION_APPLIER_THREAD_PRIORITY 1
class Replication_thread_api {
public:
Replication_thread_api(const char *channel_interface);
Replication_thread_api();
~Replication_thread_api() = default;
/**
Set the channel name to be used on the interface method invocation.
@param channel_name the name to be used.
*/
void set_channel_name(const char *channel_name) {
interface_channel = channel_name;
}
/**
Initializes a channel connection in a similar way to a change master
command.
@param hostname The channel hostname
@param port The channel port
@param user The user used in the receiver connection
@param password The password used in the receiver connection
@param use_ssl Force the use of SSL on recovery connections
@param ssl_ca SSL trusted certificate authorities file
@param ssl_capath A directory with trusted CA files
@param ssl_cert The certificate file for secure connections
@param ssl_cipher The list of ciphers to use
@param ssl_key The SSL key file
@param ssl_crl SSL revocation list file
@param ssl_crlpath Path with revocation list files
@param ssl_verify_server_cert verify the hostname against the certificate
@param priority The channel priority on event application
@param retry_count The number of retries when connecting
@param preserve_logs If logs should be always preserved
@param public_key_path The file with public key path information
@param get_public_key Preference to get public key if unavailable.
@param compression_algorithm The compression algorithm
@param zstd_compression_level The compression level
@param tls_version TLS versions
@param tls_ciphersuites Permissible ciphersuites for TLS 1.3.
@param ignore_ws_mem_limit Shall ignore write set mem limits
@param allow_drop_write_set Shall not require write set to be preserved
@return the operation status
@retval 0 OK
@retval !=0 Error on channel creation
*/
int initialize_channel(char *hostname, uint port, char *user, char *password,
bool use_ssl, char *ssl_ca, char *ssl_capath,
char *ssl_cert, char *ssl_cipher, char *ssl_key,
char *ssl_crl, char *ssl_crlpath,
bool ssl_verify_server_cert, int priority,
int retry_count, bool preserve_logs,
char *public_key_path, bool get_public_key,
char *compression_algorithm,
uint zstd_compression_level, char *tls_version,
char *tls_ciphersuites, bool ignore_ws_mem_limit,
bool allow_drop_write_set);
/**
Start the Applier/Receiver threads according to the given options.
If the receiver thread is to be started, connection credential must be
supported.
@param start_receiver Is the receiver thread to be started
@param start_applier Is the applier thread to be started
@param view_id The view id, that can be used to activate the
until view id clause.
@param wait_for_connection If when starting the receiver, the method should
wait for the connection to succeed
@return the operation status
@retval 0 OK
@retval REPLICATION_THREAD_START_ERROR
Error when launching on of the threads
@retval REPLICATION_THREAD_START_IO_NOT_CONNECTED
Error when the threads start, but the IO thread cannot connect
*/
int start_threads(bool start_receiver, bool start_applier,
std::string *view_id, bool wait_for_connection);
/**
Stops the channel threads according to the given options.
@param stop_receiver if the receiver thread should be stopped
@param stop_applier if the applier thread should be stopped
@return the operation status
@retval 0 OK
@retval !=0 Error stopping channel thread
*/
int stop_threads(bool stop_receiver, bool stop_applier);
/**
Purges the relay logs.
@param reset_all If true, the method will purge logs and remove the channel
If false, the channel logs will be deleted and recreated
but the channel info will be preserved.
@return the operation status
@retval 0 OK
@retval !=0 Error purging channel logs
*/
int purge_logs(bool reset_all);
/**
Checks if the receiver thread is running.
@return the thread status
@retval true the thread is running
@retval false the thread is stopped
*/
bool is_receiver_thread_running();
/**
Checks if the receiver thread is stopping.
@return the thread status
@retval true the thread is stopping
@retval false the thread is not stopping
*/
bool is_receiver_thread_stopping();
/**
Checks if the applier thread is running.
@return the thread status
@retval true the thread is running
@retval false the thread is stopped
*/
bool is_applier_thread_running();
/**
Checks if the applier thread is stopping.
@return the thread status
@retval true the thread is stopping
@retval false the thread is not stopping
*/
bool is_applier_thread_stopping();
/**
Queues a event packet into the current active channel relay log.
@param buf the event buffer
@param event_len the event buffer length
@return the operation status
@retval 0 OK
@retval != 0 Error on queue
*/
int queue_packet(const char *buf, ulong event_len);
/**
Checks if the applier, and its workers when parallel applier is
enabled, has already consumed all relay log, that is, applier is
waiting for transactions to be queued.
@return the applier status
@retval true the applier is waiting
@retval false otherwise
*/
bool is_applier_thread_waiting();
/**
Checks if all the queued transactions were executed.
@param timeout the time (seconds) after which the method returns if the
above condition was not satisfied
@return the operation status
@retval 0 All transactions were executed
@retval REPLICATION_THREAD_WAIT_TIMEOUT_ERROR A timeout occurred
@retval REPLICATION_THREAD_WAIT_NO_INFO_ERROR An error occurred
*/
int wait_for_gtid_execution(double timeout);
/**
Checks if all the set transactions were executed.
@param retrieved_set the set in string format of transaction to wait for
@param timeout the time (seconds) after which the method returns if the
above condition was not satisfied
@param update_THD_status Shall the method update the THD stage
@return the operation status
@retval 0 All transactions were executed
@retval REPLICATION_THREAD_WAIT_TIMEOUT_ERROR A timeout occurred
@retval REPLICATION_THREAD_WAIT_NO_INFO_ERROR An error occurred
*/
int wait_for_gtid_execution(std::string &retrieved_set, double timeout,
bool update_THD_status = true);
/**
Method to get applier ids from the configured channel
@param[out] thread_ids The retrieved thread ids.
@return the number of appliers
@retval <= 0 Some error occurred or the applier is not present
@retval > 0 Number of appliers
*/
int get_applier_thread_ids(unsigned long **thread_ids);
/**
Checks if the given id matches any of the event applying threads for
the configured channel.
@param id the thread id
@param channel_name the channel name which needs to be checked. It is
an optional parameter.
@return if it belongs to a thread
@retval true the id matches a SQL or worker thread
@retval false the id doesn't match any thread
*/
bool is_own_event_applier(my_thread_id id,
const char *channel_name = nullptr);
/**
Checks if the given id matches the receiver thread for
the configured channel.
@param id the thread id
@return if it belongs to a thread
@retval true the id matches an IO thread
@retval false the id doesn't match any thread
*/
bool is_own_event_receiver(my_thread_id id);
/**
Returns last GNO from the applier for a given UUID.
@param sidno the SIDNO of the group UUID, so that we get the
last GNO of group's already certified transactions
on relay log.
@retval GNO value
*/
rpl_gno get_last_delivered_gno(rpl_sidno sidno);
/**
Sets the threads shutdown timeout.
@param[in] timeout the timeout
*/
void set_stop_wait_timeout(ulong timeout) { stop_wait_timeout = timeout; }
/**
Returns the retrieved gtid set from the receiver thread.
@param[out] retrieved_set the set in string format.
@param channel_name the name of the channel to get the information.
@retval true there was an error.
@retval false the operation has succeeded.
*/
bool get_retrieved_gtid_set(std::string &retrieved_set,
const char *channel_name = nullptr);
/**
Checks if the channel's relay log contains partial transaction.
@retval true If relaylog contains partial transaction.
@retval false If relaylog does not contain partial transaction.
*/
bool is_partial_transaction_on_relay_log();
/**
Interface to Channel Service Interface channel_stop_all method.
Stops all the running channel threads according to the given options.
@param threads_to_stop The types of threads to be stopped
@param timeout The max time in which the thread should stop
@return the operation status
@retval 0 OK
@retval !=0 Error
*/
static int rpl_channel_stop_all(int threads_to_stop, long timeout);
/**
Interface to kill binlog dump thread.
Kills binlog dump thread thus killing all slave connections.
@note binlog dump GTID thread is not killed as of now.
@return the operation status
@retval 0 OK
*/
static int rpl_binlog_dump_thread_kill();
/**
Interface to remove stored credentials from thread api.
Removes credentials for the channel from thread api.
@param channel_name Credential associated channel name
@return the operation status
@retval 0 OK
@retval !=0 Error
*/
static int delete_credential(const char *channel_name);
/**
Method to get the credentials configured for a channel
@param[out] username The user to extract
@param[out] password The password to extract
@param[in] channel_name The name of the channel to get the information.
@return the operation status
@retval false OK
@retval true Error, channel not found
*/
bool get_channel_credentials(std::string &username, std::string &password,
const char *channel_name = nullptr);
/**
Method to get the network namespace configured for a channel
@param[out] net_ns The network namespace to extract
@param[in] channel_name The name of the channel to get the information.
@return the operation status
@retval false OK
@retval true Error, channel not found
*/
bool get_channel_network_namespace(std::string &net_ns,
const char *channel_name = nullptr);
/**
Checks if any channel uses the same UUID for
assign_gtids_to_anonymous_transactions as the given uuid
@param[in] uuid_param the group name
@retval true at least one channel has the same uuid
@retval false none of the the channels have the same
uuid
*/
bool is_any_channel_using_uuid_for_assign_gtids_to_anonymous_transaction(
const char *uuid_param);
private:
ulong stop_wait_timeout;
const char *interface_channel;
};
#endif /* REPLICATION_THREADS_API_INCLUDE */
|