1 /* Copyright (c) 2006 MySQL AB, 2009 Sun Microsystems, Inc. 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 as published by 6 the Free Software Foundation; version 2 of the License. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 16 17 18 #ifndef SEMISYNC_SLAVE_H 19 #define SEMISYNC_SLAVE_H 20 21 #include "semisync.h" 22 #include "my_global.h" 23 #include "sql_priv.h" 24 #include "rpl_mi.h" 25 #include "mysql.h" 26 27 class Master_info; 28 29 /** 30 The extension class for the slave of semi-synchronous replication 31 */ 32 class Repl_semi_sync_slave 33 :public Repl_semi_sync_base { 34 public: Repl_semi_sync_slave()35 Repl_semi_sync_slave() :m_slave_enabled(false) {} ~Repl_semi_sync_slave()36 ~Repl_semi_sync_slave() {} 37 set_trace_level(unsigned long trace_level)38 void set_trace_level(unsigned long trace_level) { 39 m_trace_level = trace_level; 40 } 41 42 /* Initialize this class after MySQL parameters are initialized. this 43 * function should be called once at bootstrap time. 44 */ 45 int init_object(); 46 get_slave_enabled()47 bool get_slave_enabled() { 48 return m_slave_enabled; 49 } 50 set_slave_enabled(bool enabled)51 void set_slave_enabled(bool enabled) { 52 m_slave_enabled = enabled; 53 } 54 is_delay_master()55 bool is_delay_master(){ 56 return m_delay_master; 57 } 58 set_delay_master(bool enabled)59 void set_delay_master(bool enabled) { 60 m_delay_master = enabled; 61 } 62 set_kill_conn_timeout(unsigned int timeout)63 void set_kill_conn_timeout(unsigned int timeout) { 64 m_kill_conn_timeout = timeout; 65 } 66 67 /* A slave reads the semi-sync packet header and separate the metadata 68 * from the payload data. 69 * 70 * Input: 71 * header - (IN) packet header pointer 72 * total_len - (IN) total packet length: metadata + payload 73 * semi_flags - (IN) store flags: SEMI_SYNC_SLAVE_DELAY_SYNC and 74 SEMI_SYNC_NEED_ACK 75 * payload - (IN) payload: the replication event 76 * payload_len - (IN) payload length 77 * 78 * Return: 79 * 0: success; non-zero: error 80 */ 81 int slave_read_sync_header(const char *header, unsigned long total_len, 82 int *semi_flags, 83 const char **payload, unsigned long *payload_len); 84 85 /* A slave replies to the master indicating its replication process. It 86 * indicates that the slave has received all events before the specified 87 * binlog position. 88 */ 89 int slave_reply(Master_info* mi); 90 int slave_start(Master_info *mi); 91 int slave_stop(Master_info *mi); 92 int request_transmit(Master_info*); 93 void kill_connection(MYSQL *mysql); 94 int reset_slave(Master_info *mi); 95 96 private: 97 /* True when init_object has been called */ 98 bool m_init_done; 99 bool m_slave_enabled; /* semi-sycn is enabled on the slave */ 100 bool m_delay_master; 101 unsigned int m_kill_conn_timeout; 102 }; 103 104 105 /* System and status variables for the slave component */ 106 extern my_bool rpl_semi_sync_slave_enabled; 107 extern my_bool rpl_semi_sync_slave_status; 108 extern ulong rpl_semi_sync_slave_trace_level; 109 extern Repl_semi_sync_slave repl_semisync_slave; 110 111 extern char rpl_semi_sync_slave_delay_master; 112 extern unsigned int rpl_semi_sync_slave_kill_conn_timeout; 113 extern unsigned long long rpl_semi_sync_slave_send_ack; 114 115 #endif /* SEMISYNC_SLAVE_H */ 116