19 #ifndef SEMISYNC_MASTER_H
20 #define SEMISYNC_MASTER_H
24 #ifdef HAVE_PSI_INTERFACE
25 extern PSI_mutex_key key_ss_mutex_LOCK_binlog_;
26 extern PSI_cond_key key_ss_cond_COND_binlog_send_;
32 char log_name_[FN_REFLEN];
71 #define BLOCK_TRANX_NODES 16
83 reserved_blocks(reserved_nodes/BLOCK_TRANX_NODES +
84 (reserved_nodes%BLOCK_TRANX_NODES > 1 ? 2 : 1)),
85 first_block(NULL), last_block(NULL),
86 current_block(NULL), last_node(-1), block_num(0) {}
90 Block *
block= first_block;
93 Block *next= block->next;
110 Block *block= current_block;
112 if (last_node == BLOCK_TRANX_NODES-1)
114 current_block= current_block->next;
118 if (current_block == NULL && allocate_block())
120 current_block=
block;
122 last_node= BLOCK_TRANX_NODES-1;
126 trx_node= &(current_block->nodes[++last_node]);
127 trx_node->log_name_[0] =
'\0';
128 trx_node->log_pos_= 0;
130 trx_node->hash_next_= 0;
141 current_block= first_block;
158 Block *prev_block= NULL;
161 while (block != current_block->next)
164 if (&(block->nodes[0]) <= node && &(block->nodes[BLOCK_TRANX_NODES]) >= node)
167 if (first_block != block)
169 last_block->next= first_block;
171 last_block= prev_block;
172 last_block->next= NULL;
187 uint reserved_blocks;
216 Block *current_block;
234 Block *block= (Block *)my_malloc(
sizeof(Block), MYF(0));
239 if (first_block == NULL)
242 last_block->next=
block;
247 current_block=
block;
258 void free_block(Block *block)
274 if (current_block == NULL || current_block->next == NULL)
278 Block *block= current_block->next->next;
279 while (block_num > reserved_blocks && block != NULL)
281 Block *next= block->next;
285 current_block->next->next=
block;
287 last_block= current_block->next;
312 inline void assert_lock_owner();
314 inline unsigned int calc_hash(
const unsigned char *key,
unsigned int length);
315 unsigned int get_hash_value(
const char *log_file_name, my_off_t log_file_pos);
317 int compare(
const char *log_file_name1, my_off_t log_file_pos1,
319 return compare(log_file_name1, log_file_pos1,
320 node2->log_name_, node2->log_pos_);
323 const char *log_file_name2, my_off_t log_file_pos2) {
324 return compare(node1->log_name_, node1->log_pos_,
325 log_file_name2, log_file_pos2);
328 return compare(node1->log_name_, node1->log_pos_,
329 node2->log_name_, node2->log_pos_);
341 int insert_tranx_node(
const char *log_file_name, my_off_t log_file_pos);
351 int clear_active_tranx_nodes(
const char *log_file_name,
352 my_off_t log_file_pos);
357 bool is_tranx_end_pos(
const char *log_file_name, my_off_t log_file_pos);
362 static int compare(
const char *log_file_name1, my_off_t log_file_pos1,
363 const char *log_file_name2, my_off_t log_file_pos2);
392 bool reply_file_name_inited_;
395 char reply_file_name_[FN_REFLEN];
398 my_off_t reply_file_pos_;
401 bool wait_file_name_inited_;
406 char wait_file_name_[FN_REFLEN];
412 my_off_t wait_file_pos_;
421 bool commit_file_name_inited_;
424 char commit_file_name_[FN_REFLEN];
427 my_off_t commit_file_pos_;
430 volatile bool master_enabled_;
431 unsigned long wait_timeout_;
437 void cond_broadcast();
438 int cond_timewait(
struct timespec *wait_time);
445 void set_master_enabled(
bool enabled) {
446 master_enabled_ = enabled;
453 int try_switch_on(
int server_id,
454 const char *log_file_name, my_off_t log_file_pos);
460 bool getMasterEnabled() {
461 return master_enabled_;
463 void setTraceLevel(
unsigned long trace_level) {
464 trace_level_ = trace_level;
466 active_tranxs_->trace_level_ = trace_level;
470 void setWaitTimeout(
unsigned long wait_timeout) {
471 wait_timeout_ = wait_timeout;
492 bool is_semi_sync_slave();
508 int reportReplyBinlog(uint32 server_id,
509 const char* log_file_name,
511 bool skipped_event=
false);
528 int commitTrx(
const char* trx_wait_binlog_name,
529 my_off_t trx_wait_binlog_pos);
542 int reserveSyncHeader(
unsigned char *header,
unsigned long size);
557 int updateSyncHeader(
unsigned char *packet,
558 const char *log_file_name,
559 my_off_t log_file_pos,
574 int writeTranxInBinlog(
const char* log_file_name, my_off_t log_file_pos);
587 int readSlaveReply(
NET *net, uint32 server_id,
const char *event_buf);
602 int skipSlaveReply(
const char *event_buf, uint32 server_id,
603 const char* log_file_name, my_off_t log_file_pos);
606 void setExportStats();
615 extern char rpl_semi_sync_master_enabled;
616 extern char rpl_semi_sync_master_status;
617 extern unsigned long rpl_semi_sync_master_clients;
618 extern unsigned long rpl_semi_sync_master_timeout;
619 extern unsigned long rpl_semi_sync_master_trace_level;
620 extern unsigned long rpl_semi_sync_master_yes_transactions;
621 extern unsigned long rpl_semi_sync_master_no_transactions;
622 extern unsigned long rpl_semi_sync_master_off_times;
623 extern unsigned long rpl_semi_sync_master_wait_timeouts;
624 extern unsigned long rpl_semi_sync_master_timefunc_fails;
625 extern unsigned long rpl_semi_sync_master_num_timeouts;
626 extern unsigned long rpl_semi_sync_master_wait_sessions;
627 extern unsigned long rpl_semi_sync_master_wait_pos_backtraverse;
628 extern unsigned long rpl_semi_sync_master_avg_trx_wait_time;
629 extern unsigned long rpl_semi_sync_master_avg_net_wait_time;
630 extern unsigned long long rpl_semi_sync_master_net_wait_num;
631 extern unsigned long long rpl_semi_sync_master_trx_wait_num;
632 extern unsigned long long rpl_semi_sync_master_net_wait_time;
633 extern unsigned long long rpl_semi_sync_master_trx_wait_time;
641 extern char rpl_semi_sync_master_wait_no_slave;