1 /* Copyright (c) 2006, 2021, Oracle and/or its affiliates.
2    Use is subject to license terms.
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
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 
25 #ifndef SEMISYNC_SLAVE_H
26 #define SEMISYNC_SLAVE_H
27 
28 #include "semisync.h"
29 
30 /**
31    The extension class for the slave of semi-synchronous replication
32 */
33 class ReplSemiSyncSlave
34   :public ReplSemiSyncBase {
35 public:
ReplSemiSyncSlave()36  ReplSemiSyncSlave()
37    :slave_enabled_(false)
38   {}
~ReplSemiSyncSlave()39   ~ReplSemiSyncSlave() {}
40 
setTraceLevel(unsigned long trace_level)41   void setTraceLevel(unsigned long trace_level) {
42     trace_level_ = trace_level;
43   }
44 
45   /* Initialize this class after MySQL parameters are initialized. this
46    * function should be called once at bootstrap time.
47    */
48   int initObject();
49 
getSlaveEnabled()50   bool getSlaveEnabled() {
51     return slave_enabled_;
52   }
setSlaveEnabled(bool enabled)53   void setSlaveEnabled(bool enabled) {
54     slave_enabled_ = enabled;
55   }
56 
57   /* A slave reads the semi-sync packet header and separate the metadata
58    * from the payload data.
59    *
60    * Input:
61    *  header      - (IN)  packet header pointer
62    *  total_len   - (IN)  total packet length: metadata + payload
63    *  need_reply  - (IN)  whether the master is waiting for the reply
64    *  payload     - (IN)  payload: the replication event
65    *  payload_len - (IN)  payload length
66    *
67    * Return:
68    *  0: success;  non-zero: error
69    */
70   int slaveReadSyncHeader(const char *header, unsigned long total_len, bool *need_reply,
71                           const char **payload, unsigned long *payload_len);
72 
73   /* A slave replies to the master indicating its replication process.  It
74    * indicates that the slave has received all events before the specified
75    * binlog position.
76    *
77    * Input:
78    *  mysql            - (IN)  the mysql network connection
79    *  binlog_filename  - (IN)  the reply point's binlog file name
80    *  binlog_filepos   - (IN)  the reply point's binlog file offset
81    *
82    * Return:
83    *  0: success;  non-zero: error
84    */
85   int slaveReply(MYSQL *mysql, const char *binlog_filename,
86                  my_off_t binlog_filepos);
87 
88   int slaveStart(Binlog_relay_IO_param *param);
89   int slaveStop(Binlog_relay_IO_param *param);
90 
91 private:
92   /* True when initObject has been called */
93   bool init_done_;
94   bool slave_enabled_;        /* semi-sycn is enabled on the slave */
95   MYSQL *mysql_reply;         /* connection to send reply */
96 };
97 
98 
99 /* System and status variables for the slave component */
100 extern char rpl_semi_sync_slave_enabled;
101 extern unsigned long rpl_semi_sync_slave_trace_level;
102 extern char rpl_semi_sync_slave_status;
103 
104 #endif /* SEMISYNC_SLAVE_H */
105