18 #include "semisync_slave.h"
20 char rpl_semi_sync_slave_enabled;
21 char rpl_semi_sync_slave_status= 0;
22 unsigned long rpl_semi_sync_slave_trace_level;
24 int ReplSemiSyncSlave::initObject()
27 const char *kWho =
"ReplSemiSyncSlave::initObject";
31 fprintf(stderr,
"%s called twice\n", kWho);
37 setSlaveEnabled(rpl_semi_sync_slave_enabled);
38 setTraceLevel(rpl_semi_sync_slave_trace_level);
43 int ReplSemiSyncSlave::slaveReadSyncHeader(
const char *header,
44 unsigned long total_len,
47 unsigned long *payload_len)
49 const char *kWho =
"ReplSemiSyncSlave::slaveReadSyncHeader";
53 if ((
unsigned char)(header[0]) == kPacketMagicNum)
55 *need_reply = (header[1] & kPacketFlagSync);
56 *payload_len = total_len - 2;
57 *payload = header + 2;
59 if (trace_level_ & kTraceDetail)
60 sql_print_information(
"%s: reply - %d", kWho, *need_reply);
64 sql_print_error(
"Missing magic number for semi-sync packet, packet "
65 "len: %lu", total_len);
69 return function_exit(kWho, read_res);
74 bool semi_sync= getSlaveEnabled();
76 sql_print_information(
"Slave I/O thread: Start %s replication to\
77 master '%s@%s:%d' in log '%s' at position %lu",
78 semi_sync ?
"semi-sync" :
"asynchronous",
79 param->user, param->host, param->port,
80 param->master_log_name[0] ? param->master_log_name :
"FIRST",
81 (
unsigned long)param->master_log_pos);
83 if (semi_sync && !rpl_semi_sync_slave_status)
84 rpl_semi_sync_slave_status= 1;
90 if (rpl_semi_sync_slave_status)
91 rpl_semi_sync_slave_status= 0;
93 mysql_close(mysql_reply);
98 int ReplSemiSyncSlave::slaveReply(
MYSQL *mysql,
99 const char *binlog_filename,
100 my_off_t binlog_filepos)
102 const char *kWho =
"ReplSemiSyncSlave::slaveReply";
103 NET *net= &mysql->net;
104 uchar reply_buffer[REPLY_MAGIC_NUM_LEN
105 + REPLY_BINLOG_POS_LEN
106 + REPLY_BINLOG_NAME_LEN];
107 int reply_res, name_len = strlen(binlog_filename);
109 function_enter(kWho);
112 reply_buffer[REPLY_MAGIC_NUM_OFFSET] = kPacketMagicNum;
113 int8store(reply_buffer + REPLY_BINLOG_POS_OFFSET, binlog_filepos);
114 memcpy(reply_buffer + REPLY_BINLOG_NAME_OFFSET,
118 if (trace_level_ & kTraceDetail)
119 sql_print_information(
"%s: reply (%s, %lu)", kWho,
120 binlog_filename, (ulong)binlog_filepos);
125 name_len + REPLY_BINLOG_NAME_OFFSET);
130 sql_print_error(
"Semi-sync slave net_flush() reply failed");
134 sql_print_error(
"Semi-sync slave send reply failed: %s (%d)",
138 return function_exit(kWho, reply_res);