Skip to content

Commit f2300ce

Browse files
author
Luis Soares
committed
BUG#20980271: FIX GTID MODE TO WORK CORRECTLY IN --BOOTSTRAP/--INITIALIZE MODE
Patch to enable the needed GTID infrastructure when in bootstrap mode. The server was not starting the necessary memory structures to setup GTIDs when on bootstrap mode. This patch makes the server generate the auto.cnf file and set up GTID sets and the sidmap when operating in bootstrap mode. It also changes MTR. It needs to because the bootstrap of the server is done once, and then the same install dir is used for initializing the master and slave. Thence, we need to remove the auto.cnf file (which holds the UUID generated UUID at bootstrap time), before copying the install dir for provisioning the new server that MTR spawns. This was not needed before, because mysqld --initialize would not setup the UUID for the server, i.e., the auto.cnf file.
1 parent 7883078 commit f2300ce

File tree

2 files changed

+135
-133
lines changed

2 files changed

+135
-133
lines changed

mysql-test/mysql-test-run.pl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3801,6 +3801,13 @@ sub mysql_install_db {
38013801
"Could not install system database from $bootstrap_sql_file\n" .
38023802
"see $path_bootstrap_log for errors");
38033803
}
3804+
3805+
# Remove the auto.cnf so that a new auto.cnf is generated
3806+
# for master and slaves when the server is restarted
3807+
if (-f "$datadir/auto.cnf")
3808+
{
3809+
unlink "$datadir/auto.cnf";
3810+
}
38043811
}
38053812

38063813

sql/mysqld.cc

Lines changed: 128 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -4164,10 +4164,6 @@ a file name for --log-bin-index option", opt_binlog_index_name);
41644164
/// @todo: this looks suspicious, revisit this /sven
41654165
enum_gtid_mode gtid_mode= get_gtid_mode(GTID_MODE_LOCK_NONE);
41664166

4167-
/* TODO: remove this. */
4168-
if (gtid_mode != GTID_MODE_OFF && opt_bootstrap)
4169-
_gtid_mode= GTID_MODE_OFF;
4170-
41714167
if (gtid_mode == GTID_MODE_ON &&
41724168
_gtid_consistency_mode != GTID_CONSISTENCY_MODE_ON)
41734169
{
@@ -4603,158 +4599,157 @@ int mysqld_main(int argc, char **argv)
46034599
Each server should have one UUID. We will create it automatically, if it
46044600
does not exist.
46054601
*/
4606-
if (!opt_bootstrap)
4602+
if (init_server_auto_options())
46074603
{
4608-
if (init_server_auto_options())
4609-
{
4610-
sql_print_error("Initialization of the server's UUID failed because it could"
4611-
" not be read from the auto.cnf file. If this is a new"
4612-
" server, the initialization failed because it was not"
4613-
" possible to generate a new UUID.");
4614-
unireg_abort(MYSQLD_ABORT_EXIT);
4615-
}
4604+
sql_print_error("Initialization of the server's UUID failed because it could"
4605+
" not be read from the auto.cnf file. If this is a new"
4606+
" server, the initialization failed because it was not"
4607+
" possible to generate a new UUID.");
4608+
unireg_abort(MYSQLD_ABORT_EXIT);
4609+
}
46164610

4617-
/*
4618-
Add server_uuid to the sid_map. This must be done after
4619-
server_uuid has been initialized in init_server_auto_options and
4620-
after the binary log (and sid_map file) has been initialized in
4621-
init_server_components().
4622-
4623-
No error message is needed: init_sid_map() prints a message.
4624-
4625-
Strictly speaking, this is not currently needed when
4626-
opt_bin_log==0, since the variables that gtid_state->init
4627-
initializes are not currently used in that case. But we call it
4628-
regardless to avoid possible future bugs if gtid_state ever
4629-
needs to do anything else.
4630-
*/
4631-
global_sid_lock->rdlock();
4632-
int ret= gtid_state->init();
4633-
global_sid_lock->unlock();
4634-
// Initialize executed_gtids from mysql.gtid_executed table.
4635-
if (gtid_state->read_gtid_executed_from_table() == -1)
4636-
unireg_abort(1);
4611+
/*
4612+
Add server_uuid to the sid_map. This must be done after
4613+
server_uuid has been initialized in init_server_auto_options and
4614+
after the binary log (and sid_map file) has been initialized in
4615+
init_server_components().
4616+
4617+
No error message is needed: init_sid_map() prints a message.
4618+
4619+
Strictly speaking, this is not currently needed when
4620+
opt_bin_log==0, since the variables that gtid_state->init
4621+
initializes are not currently used in that case. But we call it
4622+
regardless to avoid possible future bugs if gtid_state ever
4623+
needs to do anything else.
4624+
*/
4625+
global_sid_lock->rdlock();
4626+
int gtid_ret= gtid_state->init();
4627+
global_sid_lock->unlock();
46374628

4638-
if (opt_bin_log)
4639-
{
4640-
if (ret)
4641-
unireg_abort(MYSQLD_ABORT_EXIT);
4629+
if (gtid_ret)
4630+
unireg_abort(MYSQLD_ABORT_EXIT);
46424631

4643-
/*
4644-
Initialize GLOBAL.GTID_EXECUTED and GLOBAL.GTID_PURGED from
4645-
gtid_executed table and binlog files during server startup.
4646-
*/
4647-
Gtid_set *executed_gtids=
4648-
const_cast<Gtid_set *>(gtid_state->get_executed_gtids());
4649-
Gtid_set *lost_gtids=
4650-
const_cast<Gtid_set *>(gtid_state->get_lost_gtids());
4651-
Gtid_set *gtids_only_in_table=
4652-
const_cast<Gtid_set *>(gtid_state->get_gtids_only_in_table());
4653-
Gtid_set *previous_gtids_logged=
4654-
const_cast<Gtid_set *>(gtid_state->get_previous_gtids_logged());
4655-
4656-
Gtid_set purged_gtids_from_binlog(global_sid_map, global_sid_lock);
4657-
Gtid_set gtids_in_binlog(global_sid_map, global_sid_lock);
4658-
Gtid_set gtids_in_binlog_not_in_table(global_sid_map, global_sid_lock);
4659-
4660-
if (mysql_bin_log.init_gtid_sets(&gtids_in_binlog,
4661-
&purged_gtids_from_binlog,
4662-
opt_master_verify_checksum,
4663-
true/*true=need lock*/,
4664-
NULL/*trx_parser*/,
4665-
NULL/*gtid_partial_trx*/,
4666-
true/*is_server_starting*/))
4667-
unireg_abort(MYSQLD_ABORT_EXIT);
4632+
// Initialize executed_gtids from mysql.gtid_executed table.
4633+
if (gtid_state->read_gtid_executed_from_table() == -1)
4634+
unireg_abort(1);
46684635

4669-
global_sid_lock->wrlock();
4636+
if (opt_bin_log)
4637+
{
4638+
/*
4639+
Initialize GLOBAL.GTID_EXECUTED and GLOBAL.GTID_PURGED from
4640+
gtid_executed table and binlog files during server startup.
4641+
*/
4642+
Gtid_set *executed_gtids=
4643+
const_cast<Gtid_set *>(gtid_state->get_executed_gtids());
4644+
Gtid_set *lost_gtids=
4645+
const_cast<Gtid_set *>(gtid_state->get_lost_gtids());
4646+
Gtid_set *gtids_only_in_table=
4647+
const_cast<Gtid_set *>(gtid_state->get_gtids_only_in_table());
4648+
Gtid_set *previous_gtids_logged=
4649+
const_cast<Gtid_set *>(gtid_state->get_previous_gtids_logged());
4650+
4651+
Gtid_set purged_gtids_from_binlog(global_sid_map, global_sid_lock);
4652+
Gtid_set gtids_in_binlog(global_sid_map, global_sid_lock);
4653+
Gtid_set gtids_in_binlog_not_in_table(global_sid_map, global_sid_lock);
4654+
4655+
if (mysql_bin_log.init_gtid_sets(&gtids_in_binlog,
4656+
&purged_gtids_from_binlog,
4657+
opt_master_verify_checksum,
4658+
true/*true=need lock*/,
4659+
NULL/*trx_parser*/,
4660+
NULL/*gtid_partial_trx*/,
4661+
true/*is_server_starting*/))
4662+
unireg_abort(MYSQLD_ABORT_EXIT);
46704663

4671-
if (!gtids_in_binlog.is_empty() &&
4672-
!gtids_in_binlog.is_subset(executed_gtids))
4673-
{
4674-
gtids_in_binlog_not_in_table.add_gtid_set(&gtids_in_binlog);
4675-
if (!executed_gtids->is_empty())
4676-
gtids_in_binlog_not_in_table.remove_gtid_set(executed_gtids);
4677-
/*
4678-
Save unsaved GTIDs into gtid_executed table, in the following
4679-
four cases:
4680-
1. the upgrade case.
4681-
2. the case that a slave is provisioned from a backup of
4682-
the master and the slave is cleaned by RESET MASTER
4683-
and RESET SLAVE before this.
4684-
3. the case that no binlog rotation happened from the
4685-
last RESET MASTER on the server before it crashes.
4686-
4. The set of GTIDs of the last binlog is not saved into the
4687-
gtid_executed table if server crashes, so we save it into
4688-
gtid_executed table and executed_gtids during recovery
4689-
from the crash.
4690-
*/
4691-
if (gtid_state->save(&gtids_in_binlog_not_in_table) == -1)
4692-
{
4693-
global_sid_lock->unlock();
4694-
unireg_abort(MYSQLD_ABORT_EXIT);
4695-
}
4696-
executed_gtids->add_gtid_set(&gtids_in_binlog_not_in_table);
4697-
}
4664+
global_sid_lock->wrlock();
46984665

4699-
/* gtids_only_in_table= executed_gtids - gtids_in_binlog */
4700-
if (gtids_only_in_table->add_gtid_set(executed_gtids) !=
4701-
RETURN_STATUS_OK)
4702-
{
4703-
global_sid_lock->unlock();
4704-
unireg_abort(MYSQLD_ABORT_EXIT);
4705-
}
4706-
gtids_only_in_table->remove_gtid_set(&gtids_in_binlog);
4666+
if (!gtids_in_binlog.is_empty() &&
4667+
!gtids_in_binlog.is_subset(executed_gtids))
4668+
{
4669+
gtids_in_binlog_not_in_table.add_gtid_set(&gtids_in_binlog);
4670+
if (!executed_gtids->is_empty())
4671+
gtids_in_binlog_not_in_table.remove_gtid_set(executed_gtids);
47074672
/*
4708-
lost_gtids = executed_gtids -
4709-
(gtids_in_binlog - purged_gtids_from_binlog)
4710-
= gtids_only_in_table + purged_gtids_from_binlog;
4673+
Save unsaved GTIDs into gtid_executed table, in the following
4674+
four cases:
4675+
1. the upgrade case.
4676+
2. the case that a slave is provisioned from a backup of
4677+
the master and the slave is cleaned by RESET MASTER
4678+
and RESET SLAVE before this.
4679+
3. the case that no binlog rotation happened from the
4680+
last RESET MASTER on the server before it crashes.
4681+
4. The set of GTIDs of the last binlog is not saved into the
4682+
gtid_executed table if server crashes, so we save it into
4683+
gtid_executed table and executed_gtids during recovery
4684+
from the crash.
47114685
*/
4712-
DBUG_ASSERT(lost_gtids->is_empty());
4713-
if (lost_gtids->add_gtid_set(gtids_only_in_table) != RETURN_STATUS_OK ||
4714-
lost_gtids->add_gtid_set(&purged_gtids_from_binlog) !=
4715-
RETURN_STATUS_OK)
4686+
if (gtid_state->save(&gtids_in_binlog_not_in_table) == -1)
47164687
{
47174688
global_sid_lock->unlock();
47184689
unireg_abort(MYSQLD_ABORT_EXIT);
47194690
}
4691+
executed_gtids->add_gtid_set(&gtids_in_binlog_not_in_table);
4692+
}
47204693

4721-
/* Prepare previous_gtids_logged for next binlog */
4722-
if (previous_gtids_logged->add_gtid_set(&gtids_in_binlog) !=
4723-
RETURN_STATUS_OK)
4724-
{
4725-
global_sid_lock->unlock();
4726-
unireg_abort(MYSQLD_ABORT_EXIT);
4727-
}
4694+
/* gtids_only_in_table= executed_gtids - gtids_in_binlog */
4695+
if (gtids_only_in_table->add_gtid_set(executed_gtids) !=
4696+
RETURN_STATUS_OK)
4697+
{
4698+
global_sid_lock->unlock();
4699+
unireg_abort(MYSQLD_ABORT_EXIT);
4700+
}
4701+
gtids_only_in_table->remove_gtid_set(&gtids_in_binlog);
4702+
/*
4703+
lost_gtids = executed_gtids -
4704+
(gtids_in_binlog - purged_gtids_from_binlog)
4705+
= gtids_only_in_table + purged_gtids_from_binlog;
4706+
*/
4707+
DBUG_ASSERT(lost_gtids->is_empty());
4708+
if (lost_gtids->add_gtid_set(gtids_only_in_table) != RETURN_STATUS_OK ||
4709+
lost_gtids->add_gtid_set(&purged_gtids_from_binlog) !=
4710+
RETURN_STATUS_OK)
4711+
{
4712+
global_sid_lock->unlock();
4713+
unireg_abort(MYSQLD_ABORT_EXIT);
4714+
}
47284715

4729-
/*
4730-
Write the previous set of gtids at this point because during
4731-
the creation of the binary log this is not done as we cannot
4732-
move the init_gtid_sets() to a place before openning the binary
4733-
log. This requires some investigation.
4716+
/* Prepare previous_gtids_logged for next binlog */
4717+
if (previous_gtids_logged->add_gtid_set(&gtids_in_binlog) !=
4718+
RETURN_STATUS_OK)
4719+
{
4720+
global_sid_lock->unlock();
4721+
unireg_abort(MYSQLD_ABORT_EXIT);
4722+
}
47344723

4735-
/Alfranio
4736-
*/
4737-
Previous_gtids_log_event prev_gtids_ev(&gtids_in_binlog);
4724+
/*
4725+
Write the previous set of gtids at this point because during
4726+
the creation of the binary log this is not done as we cannot
4727+
move the init_gtid_sets() to a place before openning the binary
4728+
log. This requires some investigation.
47384729
4739-
global_sid_lock->unlock();
4730+
/Alfranio
4731+
*/
4732+
Previous_gtids_log_event prev_gtids_ev(&gtids_in_binlog);
47404733

4741-
(prev_gtids_ev.common_footer)->checksum_alg=
4742-
static_cast<enum_binlog_checksum_alg>(binlog_checksum_options);
4734+
global_sid_lock->unlock();
47434735

4744-
if (prev_gtids_ev.write(mysql_bin_log.get_log_file()))
4745-
unireg_abort(MYSQLD_ABORT_EXIT);
4746-
mysql_bin_log.add_bytes_written(
4747-
prev_gtids_ev.common_header->data_written);
4736+
(prev_gtids_ev.common_footer)->checksum_alg=
4737+
static_cast<enum_binlog_checksum_alg>(binlog_checksum_options);
47484738

4749-
if (flush_io_cache(mysql_bin_log.get_log_file()) ||
4750-
mysql_file_sync(mysql_bin_log.get_log_file()->file, MYF(MY_WME)))
4751-
unireg_abort(MYSQLD_ABORT_EXIT);
4752-
mysql_bin_log.update_binlog_end_pos();
4739+
if (prev_gtids_ev.write(mysql_bin_log.get_log_file()))
4740+
unireg_abort(MYSQLD_ABORT_EXIT);
4741+
mysql_bin_log.add_bytes_written(
4742+
prev_gtids_ev.common_header->data_written);
47534743

4754-
(void) RUN_HOOK(server_state, after_engine_recovery, (NULL));
4755-
}
4744+
if (flush_io_cache(mysql_bin_log.get_log_file()) ||
4745+
mysql_file_sync(mysql_bin_log.get_log_file()->file, MYF(MY_WME)))
4746+
unireg_abort(MYSQLD_ABORT_EXIT);
4747+
mysql_bin_log.update_binlog_end_pos();
4748+
4749+
(void) RUN_HOOK(server_state, after_engine_recovery, (NULL));
47564750
}
47574751

4752+
47584753
if (init_ssl())
47594754
unireg_abort(MYSQLD_ABORT_EXIT);
47604755
if (network_init())

0 commit comments

Comments
 (0)