MCPcopy Create free account
hub / github.com/MariaDB/server / change_master

Function change_master

sql/sql_repl.cc:4412–4872  ·  view source on GitHub ↗

Execute a CHANGE MASTER statement. @param thd Pointer to THD object for the client thread executing the statement. @param mi Pointer to Master_info object belonging to the slave's IO thread. @param master_info_added Out parameter saying if the Master_info *mi was added to the global list of masters. This is useful in error conditions to know if caller should free Master_info *mi.

Source from the content-addressed store, hash-verified

4410 @retval TRUE error
4411*/
4412bool change_master(THD* thd, Master_info* mi, bool *master_info_added)
4413{
4414 int thread_mask;
4415 const char* errmsg= 0;
4416 bool need_relay_log_purge= 1;
4417 bool ret= FALSE;
4418 char saved_host[HOSTNAME_LENGTH + 1];
4419 uint saved_port;
4420 char saved_log_name[FN_REFLEN];
4421 enum_master_use_gtid saved_using_gtid;
4422 char master_info_file_tmp[FN_REFLEN];
4423 char relay_log_info_file_tmp[FN_REFLEN];
4424 my_off_t saved_log_pos;
4425 LEX_MASTER_INFO* lex_mi= &thd->lex->mi;
4426 DYNAMIC_ARRAY *do_ids, *ignore_ids;
4427
4428 DBUG_ENTER("change_master");
4429
4430 DBUG_ASSERT(master_info_index);
4431 mysql_mutex_assert_owner(&LOCK_active_mi);
4432
4433 *master_info_added= false;
4434 /*
4435 We need to check if there is an empty master_host. Otherwise
4436 change master succeeds, a master.info file is created containing
4437 empty master_host string and when issuing: start slave; an error
4438 is thrown stating that the server is not configured as slave.
4439 (See BUG#28796).
4440 */
4441 if (lex_mi->host && !*lex_mi->host)
4442 {
4443 my_error(ER_WRONG_ARGUMENTS, MYF(0), "MASTER_HOST");
4444 DBUG_RETURN(TRUE);
4445 }
4446 if (master_info_index->check_duplicate_master_info(&lex_mi->connection_name,
4447 lex_mi->host,
4448 lex_mi->port))
4449 DBUG_RETURN(TRUE);
4450
4451 mi->lock_slave_threads();
4452 if (mi->killed)
4453 {
4454 /* connection was deleted while we waited for lock_slave_threads */
4455 mi->unlock_slave_threads();
4456 my_error(WARN_NO_MASTER_INFO, MYF(0), (int) mi->connection_name.length,
4457 mi->connection_name.str);
4458 DBUG_RETURN(TRUE);
4459 }
4460
4461 init_thread_mask(&thread_mask,mi,0 /*not inverse*/);
4462 if (thread_mask) // We refuse if any slave thread is running
4463 {
4464 my_error(ER_SLAVE_MUST_STOP, MYF(0), (int) mi->connection_name.length,
4465 mi->connection_name.str);
4466 ret= TRUE;
4467 goto err;
4468 }
4469

Callers 1

sql_parse.ccFile · 0.85

Calls 15

my_errorFunction · 0.85
init_thread_maskFunction · 0.85
init_master_infoFunction · 0.85
get_string_parameterFunction · 0.85
get_dynamicFunction · 0.85
update_change_master_idsFunction · 0.85
push_warningFunction · 0.85
push_warning_printfFunction · 0.85
rpl_append_gtid_stateFunction · 0.85
flush_master_infoFunction · 0.85
purge_relay_logsFunction · 0.85

Tested by

no test coverage detected