16 #include <my_global.h>
26 #ifdef HAVE_REPLICATION
29 LINES_IN_MASTER_INFO_WITH_SSL= 14,
32 LINE_FOR_MASTER_SSL_VERIFY_SERVER_CERT= 15,
35 LINE_FOR_MASTER_HEARTBEAT_PERIOD= 16,
38 LINE_FOR_MASTER_BIND = 17,
41 LINE_FOR_REPLICATE_IGNORE_SERVER_IDS= 18,
44 LINE_FOR_MASTER_UUID= 19,
47 LINE_FOR_MASTER_RETRY_COUNT= 20,
53 LINE_FOR_SSL_CRLPATH= 22,
56 LINE_FOR_AUTO_POSITION= 23,
59 LINES_IN_MASTER_INFO= LINE_FOR_AUTO_POSITION
67 const char *info_mi_fields []=
83 "ssl_verify_server_cert",
94 Master_info::Master_info(
95 #ifdef HAVE_PSI_INTERFACE
96 PSI_mutex_key *param_key_info_run_lock,
97 PSI_mutex_key *param_key_info_data_lock,
98 PSI_mutex_key *param_key_info_sleep_lock,
99 PSI_mutex_key *param_key_info_data_cond,
100 PSI_mutex_key *param_key_info_start_cond,
101 PSI_mutex_key *param_key_info_stop_cond,
102 PSI_mutex_key *param_key_info_sleep_cond,
107 #ifdef HAVE_PSI_INTERFACE
108 ,param_key_info_run_lock, param_key_info_data_lock,
109 param_key_info_sleep_lock,
110 param_key_info_data_cond, param_key_info_start_cond,
111 param_key_info_stop_cond, param_key_info_sleep_cond
115 start_user_configured(false),
116 ssl(0), ssl_verify_server_cert(0),
117 port(MYSQL_PORT), connect_retry(DEFAULT_CONNECT_RETRY),
118 clock_diff_with_master(0), heartbeat_period(0),
119 received_heartbeats(0), last_heartbeat(0), master_id(0),
120 checksum_alg_before_fd(BINLOG_CHECKSUM_ALG_UNDEF),
121 retry_count(master_retry_count), master_gtid_mode(0),
122 mi_description_event(NULL),
125 host[0] = 0; user[0] = 0; bind_addr[0] = 0;
126 password[0]= 0; start_password[0]= 0;
127 ssl_ca[0]= 0; ssl_capath[0]= 0; ssl_cert[0]= 0;
128 ssl_cipher[0]= 0; ssl_key[0]= 0;
129 ssl_crl[0]= 0; ssl_crlpath[0]= 0;
131 start_plugin_auth[0]= 0; start_plugin_dir[0]= 0;
133 ignore_server_ids=
new Server_ids(
sizeof(::server_id));
136 Master_info::~Master_info()
138 delete ignore_server_ids;
139 delete mi_description_event;
149 int change_master_server_id_cmp(ulong *id1, ulong *id2)
151 return *id1 < *id2? -1 : (*id1 > *id2? 1 : 0);
167 bool Master_info::shall_ignore_server_id(ulong s_id)
169 if (likely(ignore_server_ids->dynamic_ids.elements == 1))
171 dynamic_array_ptr(&(ignore_server_ids->dynamic_ids), 0)) == s_id;
173 return bsearch((
const ulong *) &s_id,
174 ignore_server_ids->dynamic_ids.buffer,
175 ignore_server_ids->dynamic_ids.elements,
sizeof(ulong),
176 (int (*) (
const void*,
const void*)) change_master_server_id_cmp)
180 void Master_info::clear_in_memory_info(
bool all)
182 init_master_log_pos();
186 host[0] = 0; user[0] = 0; password[0] = 0;
190 void Master_info::init_master_log_pos()
192 DBUG_ENTER(
"Master_info::init_master_log_pos");
194 master_log_name[0]= 0;
195 master_log_pos= BIN_LOG_HEADER_SIZE;
198 ssl_verify_server_cert= 0;
206 (slave_net_timeout/2.0));
207 DBUG_ASSERT(heartbeat_period > (
float) 0.001
208 || heartbeat_period == 0);
213 void Master_info::end_info()
215 DBUG_ENTER(
"Master_info::end_info");
256 int Master_info::flush_info(
bool force)
258 DBUG_ENTER(
"Master_info::flush_info");
259 DBUG_PRINT(
"enter",(
"master_pos: %lu", (ulong) master_log_pos));
270 handler->set_sync_period(sync_masterinfo_period);
275 if (
handler->flush_info(force))
281 sql_print_error(
"Error writing master configuration.");
295 int Master_info::mi_init_info()
297 DBUG_ENTER(
"Master_info::mi_init_info");
298 enum_return_check check_return= ERROR_CHECKING_REPOSITORY;
303 mysql= 0; file_id= 1;
304 if ((check_return= check_info()) == ERROR_CHECKING_REPOSITORY)
310 if (check_return == REPOSITORY_DOES_NOT_EXIST)
312 init_master_log_pos();
321 if (flush_info(TRUE))
329 sql_print_error(
"Error reading master configuration.");
333 size_t Master_info::get_number_info_mi_fields()
335 return sizeof(info_mi_fields)/
sizeof(info_mi_fields[0]);
338 bool Master_info::read_info(Rpl_info_handler *from)
341 char *first_non_digit= NULL;
342 ulong temp_master_log_pos= 0;
344 int temp_ssl_verify_server_cert= 0;
345 int temp_auto_position= 0;
347 DBUG_ENTER(
"Master_info::read_info");
368 if (from->prepare_info_for_read() ||
369 from->get_info(master_log_name, (
size_t)
sizeof(master_log_name),
373 lines= strtoul(master_log_name, &first_non_digit, 10);
375 if (master_log_name[0]!=
'\0' &&
376 *first_non_digit==
'\0' && lines >= LINES_IN_MASTER_INFO_WITH_SSL)
379 if (from->get_info(master_log_name, (
size_t)
sizeof(master_log_name),
386 if (from->get_info(&temp_master_log_pos,
387 (ulong) BIN_LOG_HEADER_SIZE) ||
388 from->get_info(host, (
size_t)
sizeof(host), (
char *) 0) ||
389 from->get_info(user, (
size_t)
sizeof(user), (
char *)
"test") ||
390 from->get_info(password, (
size_t)
sizeof(password), (
char *) 0) ||
391 from->get_info((
int *) &port, (
int) MYSQL_PORT) ||
392 from->get_info((
int *) &connect_retry,
393 (
int) DEFAULT_CONNECT_RETRY))
402 if (lines >= LINES_IN_MASTER_INFO_WITH_SSL)
404 if (from->get_info(&temp_ssl, 0) ||
405 from->get_info(ssl_ca, (
size_t)
sizeof(ssl_ca), (
char *) 0) ||
406 from->get_info(ssl_capath, (
size_t)
sizeof(ssl_capath), (
char *) 0) ||
407 from->get_info(ssl_cert, (
size_t)
sizeof(ssl_cert), (
char *) 0) ||
408 from->get_info(ssl_cipher, (
size_t)
sizeof(ssl_cipher), (
char *) 0) ||
409 from->get_info(ssl_key, (
size_t)
sizeof(ssl_key), (
char *) 0))
417 if (lines >= LINE_FOR_MASTER_SSL_VERIFY_SERVER_CERT)
419 if (from->get_info(&temp_ssl_verify_server_cert, (
int) 0))
427 if (lines >= LINE_FOR_MASTER_HEARTBEAT_PERIOD)
429 if (from->get_info(&heartbeat_period, (
float) 0.0))
436 if (lines >= LINE_FOR_MASTER_BIND)
438 if (from->get_info(bind_addr, (
size_t)
sizeof(bind_addr), (
char *)
""))
446 if (lines >= LINE_FOR_REPLICATE_IGNORE_SERVER_IDS)
448 if (from->get_info(ignore_server_ids, (
Dynamic_ids *) NULL))
453 if (lines >= LINE_FOR_MASTER_UUID)
455 if (from->get_info(master_uuid, (
size_t)
sizeof(master_uuid),
461 retry_count= master_retry_count;
462 if (lines >= LINE_FOR_MASTER_RETRY_COUNT)
464 if (from->get_info(&retry_count, master_retry_count))
468 if (lines >= LINE_FOR_SSL_CRLPATH)
470 if (from->get_info(ssl_crl,
sizeof(ssl_crl), (
char *) 0) ||
471 from->get_info(ssl_crlpath,
sizeof(ssl_crlpath), (
char *) 0))
475 if (lines >= LINE_FOR_AUTO_POSITION)
477 if (from->get_info(&temp_auto_position, (
int) 0))
481 ssl= (my_bool)
test(temp_ssl);
482 ssl_verify_server_cert= (my_bool)
test(temp_ssl_verify_server_cert);
483 master_log_pos= (my_off_t) temp_master_log_pos;
484 auto_position=
test(temp_auto_position);
486 if (auto_position != 0 && gtid_mode != 3)
488 my_error(ER_AUTO_POSITION_REQUIRES_GTID_MODE_ON, MYF(0));
494 sql_print_warning(
"SSL information in the master info file "
495 "are ignored because this MySQL slave was "
496 "compiled without SSL support.");
502 bool Master_info::write_info(Rpl_info_handler *
to)
504 DBUG_ENTER(
"Master_info::write_info");
513 if (to->prepare_info_for_write() ||
514 to->set_info((
int) LINES_IN_MASTER_INFO) ||
515 to->set_info(master_log_name) ||
516 to->set_info((ulong) master_log_pos) ||
517 to->set_info(host) ||
518 to->set_info(user) ||
519 to->set_info(password) ||
520 to->set_info((
int) port) ||
521 to->set_info((
int) connect_retry) ||
522 to->set_info((
int) ssl) ||
523 to->set_info(ssl_ca) ||
524 to->set_info(ssl_capath) ||
525 to->set_info(ssl_cert) ||
526 to->set_info(ssl_cipher) ||
527 to->set_info(ssl_key) ||
528 to->set_info((
int) ssl_verify_server_cert) ||
529 to->set_info(heartbeat_period) ||
530 to->set_info(bind_addr) ||
531 to->set_info(ignore_server_ids) ||
532 to->set_info(master_uuid) ||
533 to->set_info(retry_count) ||
534 to->set_info(ssl_crl) ||
535 to->set_info(ssl_crlpath) ||
536 to->set_info((
int) auto_position))
542 bool Master_info::set_password(
const char* password_arg,
543 int password_arg_size __attribute__((unused)))
546 DBUG_ENTER(
"Master_info::set_password");
548 if (password_arg && start_user_configured)
550 strmake(start_password, password_arg,
sizeof(start_password) - 1);
553 else if (password_arg)
555 strmake(password, password_arg,
sizeof(password) - 1);
561 bool Master_info::get_password(
char *password_arg,
int *password_arg_size)
564 DBUG_ENTER(
"Master_info::get_password");
566 if (password_arg && start_user_configured)
568 *password_arg_size= strlen(start_password);
569 strmake(password_arg, start_password,
sizeof(start_password) - 1);
572 else if (password_arg)
574 *password_arg_size= strlen(password);
575 strmake(password_arg, password,
sizeof(password) - 1);
581 void Master_info::reset_start_info()
583 DBUG_ENTER(
"Master_info::reset_start_info");
584 start_plugin_auth[0]= 0;
585 start_plugin_dir[0]= 0;
586 start_user_configured=
false;
588 start_password[0]= 0;