-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathrpl_async_conn_failover.h
141 lines (114 loc) · 5.1 KB
/
rpl_async_conn_failover.h
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
/* Copyright (c) 2020, 2024, 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 RPL_ASYNC_CONN_FAILOVER_H
#define RPL_ASYNC_CONN_FAILOVER_H
#include "mysql.h"
#include "sql/rpl_async_conn_failover_table_operations.h"
#include "sql/rpl_mi.h"
/*
The class is used to connect to new source in case the
current replica IO connection gets interrupted.
*/
class Async_conn_failover_manager {
public:
enum class DoAutoConnFailoverError {
/* Success. */
no_error = 0,
/* Failed to set/reset network configuration details. */
retriable_error,
/* Failed to find alternative source to connect. */
no_sources_error
};
enum class SourceQuorumStatus {
/* Success. */
no_error = 0,
/* Failed to detect if the source belongs to the group majority. */
fatal_error,
/* Transient network error connecting to source. */
transient_network_error,
/* No Quorum. Source does not belong to the group majority. */
no_quorum_error
};
Async_conn_failover_manager() = delete;
Async_conn_failover_manager(const Async_conn_failover_manager &) = delete;
Async_conn_failover_manager(Async_conn_failover_manager &&) = delete;
Async_conn_failover_manager &operator=(const Async_conn_failover_manager &) =
delete;
Async_conn_failover_manager &operator=(Async_conn_failover_manager &&) =
delete;
/**
Re-establishes connection to next available source.
@param[in] mi the mi of the failed connection which
needs to be reconnected to the new source.
@param[in] force_highest_weight When true, sender with highest weight is
chosen, otherwise the next sender from the current one is chosen.
@retval Please see DoAutoConnFailoverError.
*/
static DoAutoConnFailoverError do_auto_conn_failover(
Master_info *mi, bool force_highest_weight);
/*
Get source quorum status in case source has Group Replication enabled.
@param mysql MYSQL to request uuid from source.
@param mi Master_info to set master_uuid
@retval Please see SourceQuorumStatus.
*/
static SourceQuorumStatus get_source_quorum_status(MYSQL *mysql,
Master_info *mi);
private:
/**
Sets source network configuration details <host, port, network_namespace>
for the provided Master_info object. The function is used by async conn
failure to set configuration details of new source.
@param[in] mi the channel of the failed connection which
needs to be reconnected to the new source.
@param[in] host the source hostname to be set for Master_info object
@param[in] port the source port to be set for Master_info object
@param[in] network_namespace the source network_namespace to be set for
Master_info object
@retval true Error
@retval false Success
*/
static bool set_channel_conn_details(Master_info *mi, const std::string host,
const uint port,
const std::string network_namespace);
public:
/**
Logs error for failure while executing queries.
It logs error for following server error codes:
ER_RPL_ASYNC_CHECK_CONNECTION_ERROR
ER_RPL_ASYNC_MONITOR_IO_THD_FETCH_GROUP_MAJORITY_ERROR
ER_RPL_ASYNC_REPLICA_IO_THD_FETCH_GROUP_MAJORITY_ERROR
ER_RPL_ASYNC_GET_GROUP_MEMBERSHIP_DETAILS_ERROR
@param sql_errno Server error code.
@param mysql MYSQL to request uuid from source.
@param mi Master_info to set master_uuid.
*/
static inline void log_error_for_async_executing_query_failure(
const longlong sql_errno, MYSQL *mysql, Master_info *mi) {
if (mysql && mi) {
const char *error = mysql_error(mysql);
if (!error || strlen(error) == 0) {
error = "Unknown MySQL error";
}
LogErr(WARNING_LEVEL, sql_errno, error, mi->host, mi->port, "",
mi->get_channel());
}
}
};
#endif /* RPL_ASYNC_CONN_FAILOVER_H */