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