MySQL 9.5.0
Source Code Documentation
semisync_source_ack_receiver.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 2025, 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 Replica {
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<Replica> Replica_vector;
49typedef Replica_vector::iterator Replica_vector_it;
50
51/**
52 Ack_receiver is responsible to control ack receive thread and maintain
53 replica 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_replica: maintain a new semisync replica's information
59 remove_replica: remove a semisync replica'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 replica list and wakes
70 up ack thread if it is waiting for any replica 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_replica(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 replica list.
82
83 @param[in] thd THD of a dump thread.
84 */
85 void remove_replica(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 replicas' 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_replicas_changed and m_replicas. ack thread and other
119 session may access the variables at the same time.
120 */
123 /* If replica 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 replica information used by ac...
Definition: semisync_source_ack_receiver.h:61
void setTraceLevel(unsigned long trace_level)
Definition: semisync_source_ack_receiver.h:106
void wait_for_replica_connection()
Definition: semisync_source_ack_receiver.cc:231
Ack_receiver()
Definition: semisync_source_ack_receiver.cc:63
my_thread_handle m_pid
Definition: semisync_source_ack_receiver.h:126
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
mysql_mutex_t m_mutex
Definition: semisync_source_ack_receiver.h:121
void remove_replica(THD *thd)
Notify ack receiver not to receive ack on the dump session.
Definition: semisync_source_ack_receiver.cc:176
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:224
Replica_vector m_replicas
Definition: semisync_source_ack_receiver.h:125
void run()
The core of ack receive thread.
Definition: semisync_source_ack_receiver.cc:245
bool add_replica(THD *thd)
Notify ack receiver to receive acks on the dump session.
Definition: semisync_source_ack_receiver.cc:137
~Ack_receiver()
Definition: semisync_source_ack_receiver.cc:75
bool m_replicas_changed
Definition: semisync_source_ack_receiver.h:124
Ack_receiver(const Ack_receiver &ack_receiver)
Base class for semi-sync source and replica 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:36
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
Replica_vector::iterator Replica_vector_it
Definition: semisync_source_ack_receiver.h:49
Ack_receiver * ack_receiver
Definition: semisync_source_plugin.cc:45
std::vector< Replica > Replica_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
EnumStatus m_status
Definition: semisync_source_ack_receiver.h:43
Vio * vio
Definition: semisync_source_ack_receiver.h:40
EnumStatus
Definition: semisync_source_ack_receiver.h:38
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
uint32_t thread_id
Definition: semisync_source_ack_receiver.h:39
Definition: violite.h:320
MYSQL_SOCKET mysql_socket
Definition: violite.h:321
Definition: my_thread_bits.h:58
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