MySQL 8.0.39
Source Code Documentation
semisync_source_ack_receiver.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 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 SEMISYNC_SOURCE_ACK_RECEIVER_DEFINED
25#define SEMISYNC_SOURCE_ACK_RECEIVER_DEFINED
26
27#include <sys/types.h>
28#include <vector>
29
30#include "my_inttypes.h"
31#include "my_io.h"
32#include "my_thread.h"
35#include "sql/sql_class.h"
36
37struct Slave {
38 enum class EnumStatus { up, leaving, down };
39 uint32_t thread_id;
44
45 my_socket sock_fd() const { return vio->mysql_socket.fd; }
46};
47
48typedef std::vector<Slave> Slave_vector;
49typedef Slave_vector::iterator Slave_vector_it;
50
51/**
52 Ack_receiver is responsible to control ack receive thread and maintain
53 slave information used by ack receive thread.
54
55 There are mainly four operations on ack receive thread:
56 start: start ack receive thread
57 stop: stop ack receive thread
58 add_slave: maintain a new semisync slave's information
59 remove_slave: remove a semisync slave's information
60 */
62 public:
65
66 /**
67 Notify ack receiver to receive acks on the dump session.
68
69 It adds the given dump thread into the slave list and wakes
70 up ack thread if it is waiting for any slave coming.
71
72 @param[in] thd THD of a dump thread.
73
74 @return it return false if succeeds, otherwise true is returned.
75 */
76 bool add_slave(THD *thd);
77
78 /**
79 Notify ack receiver not to receive ack on the dump session.
80
81 it removes the given dump thread from slave list.
82
83 @param[in] thd THD of a dump thread.
84 */
85 void remove_slave(THD *thd);
86
87 /**
88 Start ack receive thread
89
90 @return it return false if succeeds, otherwise true is returned.
91 */
92 bool start();
93
94 /**
95 Stop ack receive thread
96 */
97 void stop();
98
99 /**
100 The core of ack receive thread.
101
102 It monitors all slaves' sockets and receives acks when they come.
103 */
104 void run();
105
106 void setTraceLevel(unsigned long trace_level) { trace_level_ = trace_level; }
107
108 bool init() {
111 return false;
112 }
113
114 private:
117 /*
118 Protect m_status, m_slaves_changed and m_slaves. ack thread and other
119 session may access the variables at the same time.
120 */
123 /* If slave list is updated(add or remove). */
127
128 /* Declare them private, so no one can copy the object. */
131
132 void set_stage_info(const PSI_stage_info &stage);
134};
135
137#endif
Ack_receiver is responsible to control ack receive thread and maintain slave information used by ack ...
Definition: semisync_source_ack_receiver.h:61
void setTraceLevel(unsigned long trace_level)
Definition: semisync_source_ack_receiver.h:106
Ack_receiver()
Definition: semisync_source_ack_receiver.cc:63
void wait_for_slave_connection()
Definition: semisync_source_ack_receiver.cc:229
my_thread_handle m_pid
Definition: semisync_source_ack_receiver.h:126
Slave_vector m_slaves
Definition: semisync_source_ack_receiver.h:125
bool start()
Start ack receive thread.
Definition: semisync_source_ack_receiver.cc:86
void stop()
Stop ack receive thread.
Definition: semisync_source_ack_receiver.cc:113
bool init()
Definition: semisync_source_ack_receiver.h:108
uint8 m_status
Definition: semisync_source_ack_receiver.h:116
mysql_cond_t m_cond
Definition: semisync_source_ack_receiver.h:122
bool add_slave(THD *thd)
Notify ack receiver to receive acks on the dump session.
Definition: semisync_source_ack_receiver.cc:137
mysql_mutex_t m_mutex
Definition: semisync_source_ack_receiver.h:121
void remove_slave(THD *thd)
Notify ack receiver not to receive ack on the dump session.
Definition: semisync_source_ack_receiver.cc:175
Ack_receiver & operator=(const Ack_receiver &ack_receiver)
status
Definition: semisync_source_ack_receiver.h:115
@ ST_STOPPING
Definition: semisync_source_ack_receiver.h:115
@ ST_UP
Definition: semisync_source_ack_receiver.h:115
@ ST_DOWN
Definition: semisync_source_ack_receiver.h:115
void set_stage_info(const PSI_stage_info &stage)
Definition: semisync_source_ack_receiver.cc:222
void run()
The core of ack receive thread.
Definition: semisync_source_ack_receiver.cc:243
bool m_slaves_changed
Definition: semisync_source_ack_receiver.h:124
~Ack_receiver()
Definition: semisync_source_ack_receiver.cc:75
Ack_receiver(const Ack_receiver &ack_receiver)
Base class for semi-sync master and slave classes.
Definition: semisync.h:83
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
unsigned long trace_level_
Definition: semisync.h:50
Some integer typedefs for easier portability.
uint8_t uint8
Definition: my_inttypes.h:63
Common #defines and includes for file and socket I/O.
Defines to make different thread packages compatible.
int my_socket
Definition: mysql.h:65
unsigned long rpl_semi_sync_source_trace_level
Definition: semisync_source.cc:47
bool rpl_semi_sync_source_enabled
Definition: semisync_source.cc:45
Slave_vector::iterator Slave_vector_it
Definition: semisync_source_ack_receiver.h:49
Ack_receiver * ack_receiver
Definition: semisync_source_plugin.cc:63
std::vector< Slave > Slave_vector
Definition: semisync_source_ack_receiver.h:48
my_socket fd
The real socket descriptor.
Definition: mysql_socket_bits.h:37
Stage instrument information.
Definition: psi_stage_bits.h:74
Definition: semisync_source_ack_receiver.h:37
uint32_t thread_id
Definition: semisync_source_ack_receiver.h:39
EnumStatus
Definition: semisync_source_ack_receiver.h:38
Vio * vio
Definition: semisync_source_ack_receiver.h:40
my_socket sock_fd() const
Definition: semisync_source_ack_receiver.h:45
uint server_id
Definition: semisync_source_ack_receiver.h:41
mysql_compress_context compress_ctx
Definition: semisync_source_ack_receiver.h:42
EnumStatus m_status
Definition: semisync_source_ack_receiver.h:43
Definition: violite.h:318
MYSQL_SOCKET mysql_socket
Definition: violite.h:319
Definition: my_thread_bits.h:52
Compression context information.
Definition: my_compress.h:74
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
unsigned int uint
Definition: uca9-dump.cc:75