MySQL 8.3.0
Source Code Documentation
rpl_async_conn_failover.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 2023, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef RPL_ASYNC_CONN_FAILOVER_H
24#define RPL_ASYNC_CONN_FAILOVER_H
25
26#include "mysql.h"
28#include "sql/rpl_mi.h"
29
30/*
31 The class is used to connect to new source in case the
32 current replica IO connection gets interrupted.
33*/
35 public:
37 /* Success. */
38 no_error = 0,
39
40 /* Failed to set/reset network configuration details. */
42
43 /* Failed to find alternative source to connect. */
45 };
46
47 enum class SourceQuorumStatus {
48 /* Success. */
49 no_error = 0,
50
51 /* Failed to detect if the source belongs to the group majority. */
53
54 /* Transient network error connecting to source. */
56
57 /* No Quorum. Source does not belong to the group majority. */
59 };
60
62
66 delete;
68 delete;
69
70 /**
71 Re-establishes connection to next available source.
72
73 @param[in] mi the mi of the failed connection which
74 needs to be reconnected to the new source.
75 @param[in] force_highest_weight When true, sender with highest weight is
76 chosen, otherwise the next sender from the current one is chosen.
77
78 @retval Please see DoAutoConnFailoverError.
79 */
81 Master_info *mi, bool force_highest_weight);
82
83 /*
84 Get source quorum status in case source has Group Replication enabled.
85
86 @param mysql MYSQL to request uuid from source.
87 @param mi Master_info to set master_uuid
88
89 @retval Please see SourceQuorumStatus.
90 */
92 Master_info *mi);
93
94 private:
95 /**
96 Sets source network configuration details <host, port, network_namespace>
97 for the provided Master_info object. The function is used by async conn
98 failure to set configuration details of new source.
99
100 @param[in] mi the channel of the failed connection which
101 needs to be reconnected to the new source.
102 @param[in] host the source hostname to be set for Master_info object
103 @param[in] port the source port to be set for Master_info object
104 @param[in] network_namespace the source network_namespace to be set for
105 Master_info object
106
107 @retval true Error
108 @retval false Success
109 */
110 static bool set_channel_conn_details(Master_info *mi, const std::string host,
111 const uint port,
112 const std::string network_namespace);
113
114 public:
115 /**
116 Logs error for failure while executing queries.
117 It logs error for following server error codes:
118 ER_RPL_ASYNC_CHECK_CONNECTION_ERROR
119 ER_RPL_ASYNC_MONITOR_IO_THD_FETCH_GROUP_MAJORITY_ERROR
120 ER_RPL_ASYNC_REPLICA_IO_THD_FETCH_GROUP_MAJORITY_ERROR
121 ER_RPL_ASYNC_GET_GROUP_MEMBERSHIP_DETAILS_ERROR
122
123 @param sql_errno Server error code.
124 @param mysql MYSQL to request uuid from source.
125 @param mi Master_info to set master_uuid.
126 */
128 const longlong sql_errno, MYSQL *mysql, Master_info *mi) {
129 if (mysql && mi) {
130 const char *error = mysql_error(mysql);
131 if (!error || strlen(error) == 0) {
132 error = "Unknown MySQL error";
133 }
134
135 LogErr(WARNING_LEVEL, sql_errno, error, mi->host, mi->port, "",
136 mi->get_channel());
137 }
138 }
139};
140#endif /* RPL_ASYNC_CONN_FAILOVER_H */
Definition: rpl_async_conn_failover.h:34
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:54
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:127
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:202
static SourceQuorumStatus get_source_quorum_status(MYSQL *mysql, Master_info *mi)
Definition: rpl_async_conn_failover.cc:271
DoAutoConnFailoverError
Definition: rpl_async_conn_failover.h:36
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:47
Definition: rpl_mi.h:86
char host[HOSTNAME_LENGTH+1]
Host name or ip address stored in the master.info.
Definition: rpl_mi.h:93
uint port
Definition: rpl_mi.h:299
char * get_channel() const
Definition: rpl_info.h:124
#define LogErr(severity, ecode,...)
Definition: log_builtins.h:842
long long int longlong
Definition: my_inttypes.h:54
@ WARNING_LEVEL
Definition: my_loglevel.h:43
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:9112
const char * host
Definition: mysqladmin.cc:63
Definition: instrumented_condition_variable.h:31
required string network_namespace
Definition: replication_asynchronous_connection_failover.proto:33
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:32
Definition: mysql.h:297