MySQL 8.4.2
Source Code Documentation
rpl_async_conn_failover.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef RPL_ASYNC_CONN_FAILOVER_H
25#define RPL_ASYNC_CONN_FAILOVER_H
26
27#include "mysql.h"
29#include "sql/rpl_mi.h"
30
31/*
32 The class is used to connect to new source in case the
33 current replica IO connection gets interrupted.
34*/
36 public:
38 /* Success. */
39 no_error = 0,
40
41 /* Failed to set/reset network configuration details. */
43
44 /* Failed to find alternative source to connect. */
46 };
47
48 enum class SourceQuorumStatus {
49 /* Success. */
50 no_error = 0,
51
52 /* Failed to detect if the source belongs to the group majority. */
54
55 /* Transient network error connecting to source. */
57
58 /* No Quorum. Source does not belong to the group majority. */
60 };
61
63
67 delete;
69 delete;
70
71 /**
72 Re-establishes connection to next available source.
73
74 @param[in] mi the mi of the failed connection which
75 needs to be reconnected to the new source.
76 @param[in] force_highest_weight When true, sender with highest weight is
77 chosen, otherwise the next sender from the current one is chosen.
78
79 @retval Please see DoAutoConnFailoverError.
80 */
82 Master_info *mi, bool force_highest_weight);
83
84 /*
85 Get source quorum status in case source has Group Replication enabled.
86
87 @param mysql MYSQL to request uuid from source.
88 @param mi Master_info to set master_uuid
89
90 @retval Please see SourceQuorumStatus.
91 */
93 Master_info *mi);
94
95 private:
96 /**
97 Sets source network configuration details <host, port, network_namespace>
98 for the provided Master_info object. The function is used by async conn
99 failure to set configuration details of new source.
100
101 @param[in] mi the channel of the failed connection which
102 needs to be reconnected to the new source.
103 @param[in] host the source hostname to be set for Master_info object
104 @param[in] port the source port to be set for Master_info object
105 @param[in] network_namespace the source network_namespace to be set for
106 Master_info object
107
108 @retval true Error
109 @retval false Success
110 */
111 static bool set_channel_conn_details(Master_info *mi, const std::string host,
112 const uint port,
113 const std::string network_namespace);
114
115 public:
116 /**
117 Logs error for failure while executing queries.
118 It logs error for following server error codes:
119 ER_RPL_ASYNC_CHECK_CONNECTION_ERROR
120 ER_RPL_ASYNC_MONITOR_IO_THD_FETCH_GROUP_MAJORITY_ERROR
121 ER_RPL_ASYNC_REPLICA_IO_THD_FETCH_GROUP_MAJORITY_ERROR
122 ER_RPL_ASYNC_GET_GROUP_MEMBERSHIP_DETAILS_ERROR
123
124 @param sql_errno Server error code.
125 @param mysql MYSQL to request uuid from source.
126 @param mi Master_info to set master_uuid.
127 */
129 const longlong sql_errno, MYSQL *mysql, Master_info *mi) {
130 if (mysql && mi) {
131 const char *error = mysql_error(mysql);
132 if (!error || strlen(error) == 0) {
133 error = "Unknown MySQL error";
134 }
135
136 LogErr(WARNING_LEVEL, sql_errno, error, mi->host, mi->port, "",
137 mi->get_channel());
138 }
139 }
140};
141#endif /* RPL_ASYNC_CONN_FAILOVER_H */
Definition: rpl_async_conn_failover.h:35
Async_conn_failover_manager(Async_conn_failover_manager &&)=delete
static DoAutoConnFailoverError do_auto_conn_failover(Master_info *mi, bool force_highest_weight)
Re-establishes connection to next available source.
Definition: rpl_async_conn_failover.cc:55
static void log_error_for_async_executing_query_failure(const longlong sql_errno, MYSQL *mysql, Master_info *mi)
Logs error for failure while executing queries.
Definition: rpl_async_conn_failover.h:128
static bool set_channel_conn_details(Master_info *mi, const std::string host, const uint port, const std::string network_namespace)
Sets source network configuration details <host, port, network_namespace> for the provided Master_inf...
Definition: rpl_async_conn_failover.cc:203
static SourceQuorumStatus get_source_quorum_status(MYSQL *mysql, Master_info *mi)
Definition: rpl_async_conn_failover.cc:273
DoAutoConnFailoverError
Definition: rpl_async_conn_failover.h:37
Async_conn_failover_manager(const Async_conn_failover_manager &)=delete
Async_conn_failover_manager & operator=(Async_conn_failover_manager &&)=delete
Async_conn_failover_manager & operator=(const Async_conn_failover_manager &)=delete
SourceQuorumStatus
Definition: rpl_async_conn_failover.h:48
Definition: rpl_mi.h:87
char host[HOSTNAME_LENGTH+1]
Host name or ip address stored in the master.info.
Definition: rpl_mi.h:99
uint port
Definition: rpl_mi.h:305
char * get_channel() const
Definition: rpl_info.h:125
#define LogErr(severity, ecode,...)
Definition: log_builtins.h:843
long long int longlong
Definition: my_inttypes.h:55
@ WARNING_LEVEL
Definition: my_loglevel.h:44
This file defines the client API to MySQL and also the ABI of the dynamically linked libmysqlclient.
const char *STDCALL mysql_error(MYSQL *mysql)
Definition: client.cc:9177
const char * host
Definition: mysqladmin.cc:65
Definition: instrumented_condition_variable.h:32
required string network_namespace
Definition: replication_asynchronous_connection_failover.proto:34
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:33
Definition: mysql.h:300