Commit 7ab972b4 authored by Daniel Black's avatar Daniel Black

MDEV-23326: mysql_tzinfo_to_sql add --skip-wsrep-check

Several mysql_tzinfo_to_sql behaviours are dependent on
checking the wsrep_on==ON specificly for galera initialization
of timezone (or skipping of them).

There are two scenarios where the lack of the checking would
be very useful.

With the --skip-write-binary-log, binary logs are explictly
skipped, allowing for loading in classical replication scenarios.

Without the --skip-write-binary-log, innodb can be used for
loading the timezone tables signficantly faster than Aria
with TRANSACTIONAL=1.

The lack of checking the wsrep status also make it possible
to use mysql_tzinfo_to_sql in the mysqld --bootstrap input
allowing for a single initialization of all system tables.

In cleaning up part of MDEV-18778, when changing back from InnoDB
to MyISAM, include the ORDER BY, and don't include this if only
loading leap seconds.
parent 984a06db
...@@ -41,8 +41,8 @@ IF (select count(*) from information_schema.global_variables where ...@@ -41,8 +41,8 @@ IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on' and variable_value='ON') = 1 THEN variable_name='wsrep_on' and variable_value='ON') = 1 THEN
ALTER TABLE time_zone ENGINE=MyISAM; ALTER TABLE time_zone ENGINE=MyISAM;
ALTER TABLE time_zone_name ENGINE=MyISAM; ALTER TABLE time_zone_name ENGINE=MyISAM;
ALTER TABLE time_zone_transition ENGINE=MyISAM; ALTER TABLE time_zone_transition ENGINE=MyISAM, ORDER BY Time_zone_id, Transition_time;
ALTER TABLE time_zone_transition_type ENGINE=MyISAM; ALTER TABLE time_zone_transition_type ENGINE=MyISAM, ORDER BY Time_zone_id, Transition_type_id;
END IF| END IF|
\d ; \d ;
# Silent run # Silent run
...@@ -82,52 +82,25 @@ IF (select count(*) from information_schema.global_variables where ...@@ -82,52 +82,25 @@ IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on' and variable_value='ON') = 1 THEN variable_name='wsrep_on' and variable_value='ON') = 1 THEN
ALTER TABLE time_zone ENGINE=MyISAM; ALTER TABLE time_zone ENGINE=MyISAM;
ALTER TABLE time_zone_name ENGINE=MyISAM; ALTER TABLE time_zone_name ENGINE=MyISAM;
ALTER TABLE time_zone_transition ENGINE=MyISAM; ALTER TABLE time_zone_transition ENGINE=MyISAM, ORDER BY Time_zone_id, Transition_time;
ALTER TABLE time_zone_transition_type ENGINE=MyISAM; ALTER TABLE time_zone_transition_type ENGINE=MyISAM, ORDER BY Time_zone_id, Transition_type_id;
END IF| END IF|
\d ; \d ;
# #
# Testing with explicit timezonefile # Testing with explicit timezonefile
# #
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on' and variable_value='ON') = 1 THEN
ALTER TABLE time_zone ENGINE=InnoDB;
ALTER TABLE time_zone_name ENGINE=InnoDB;
ALTER TABLE time_zone_transition ENGINE=InnoDB;
ALTER TABLE time_zone_transition_type ENGINE=InnoDB;
END IF|
\d ;
INSERT INTO time_zone (Use_leap_seconds) VALUES ('N'); INSERT INTO time_zone (Use_leap_seconds) VALUES ('N');
SET @time_zone_id= LAST_INSERT_ID(); SET @time_zone_id= LAST_INSERT_ID();
INSERT INTO time_zone_name (Name, Time_zone_id) VALUES ('XXX', @time_zone_id); INSERT INTO time_zone_name (Name, Time_zone_id) VALUES ('XXX', @time_zone_id);
INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES
(@time_zone_id, 0, 0, 0, 'GMT') (@time_zone_id, 0, 0, 0, 'GMT')
; ;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on' and variable_value='ON') = 1 THEN
ALTER TABLE time_zone ENGINE=MyISAM;
ALTER TABLE time_zone_name ENGINE=MyISAM;
ALTER TABLE time_zone_transition ENGINE=MyISAM;
ALTER TABLE time_zone_transition_type ENGINE=MyISAM;
END IF|
\d ;
# #
# Testing --leap # Testing --leap
# #
\d | \d |
IF (select count(*) from information_schema.global_variables where IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on' and variable_value='ON') = 1 THEN variable_name='wsrep_on' and variable_value='ON') = 1 THEN
ALTER TABLE time_zone ENGINE=InnoDB;
ALTER TABLE time_zone_name ENGINE=InnoDB;
ALTER TABLE time_zone_transition ENGINE=InnoDB;
ALTER TABLE time_zone_transition_type ENGINE=InnoDB;
END IF|
\d ;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on' and variable_value='ON') = 1 THEN
ALTER TABLE time_zone_leap_second ENGINE=InnoDB; ALTER TABLE time_zone_leap_second ENGINE=InnoDB;
END IF| END IF|
\d ; \d ;
...@@ -139,12 +112,3 @@ ALTER TABLE time_zone_leap_second ENGINE=MyISAM; ...@@ -139,12 +112,3 @@ ALTER TABLE time_zone_leap_second ENGINE=MyISAM;
END IF| END IF|
\d ; \d ;
ALTER TABLE time_zone_leap_second ORDER BY Transition_time; ALTER TABLE time_zone_leap_second ORDER BY Transition_time;
\d |
IF (select count(*) from information_schema.global_variables where
variable_name='wsrep_on' and variable_value='ON') = 1 THEN
ALTER TABLE time_zone ENGINE=MyISAM;
ALTER TABLE time_zone_name ENGINE=MyISAM;
ALTER TABLE time_zone_transition ENGINE=MyISAM;
ALTER TABLE time_zone_transition_type ENGINE=MyISAM;
END IF|
\d ;
...@@ -15,10 +15,31 @@ ...@@ -15,10 +15,31 @@
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--exec $MYSQL_TZINFO_TO_SQL --verbose $MYSQLTEST_VARDIR/zoneinfo 2>&1 --exec $MYSQL_TZINFO_TO_SQL --verbose $MYSQLTEST_VARDIR/zoneinfo 2>&1
--echo # Silent run --echo # Run on zoneinfo directory
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--exec $MYSQL_TZINFO_TO_SQL $MYSQLTEST_VARDIR/zoneinfo 2>&1 --exec $MYSQL_TZINFO_TO_SQL $MYSQLTEST_VARDIR/zoneinfo 2>&1
--echo #
--echo # Run on zoneinfo directory --skip-write-binlog
--echo #
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--exec $MYSQL_TZINFO_TO_SQL --skip-write-binlog $MYSQLTEST_VARDIR/zoneinfo 2>&1
--echo #
--echo # Run on zoneinfo directory --skip-write-binlog --skip-wsrep-checks
--echo #
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--exec $MYSQL_TZINFO_TO_SQL --skip-write-binlog --skip-wsrep-checks $MYSQLTEST_VARDIR/zoneinfo 2>&1
--echo #
--echo # Run on zoneinfo directory --skip-wsrep-checks
--echo #
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--exec $MYSQL_TZINFO_TO_SQL --skip-wsrep-checks $MYSQLTEST_VARDIR/zoneinfo 2>&1
--echo # --echo #
--echo # Testing with explicit timezonefile --echo # Testing with explicit timezonefile
--echo # --echo #
...@@ -26,12 +47,49 @@ ...@@ -26,12 +47,49 @@
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--exec $MYSQL_TZINFO_TO_SQL $MYSQLTEST_VARDIR/zoneinfo/GMT XXX 2>&1 --exec $MYSQL_TZINFO_TO_SQL $MYSQLTEST_VARDIR/zoneinfo/GMT XXX 2>&1
--echo #
--echo # Testing with explicit timezonefile --skip-write-binlog
--echo #
--exec $MYSQL_TZINFO_TO_SQL --skip-write-binlog $MYSQLTEST_VARDIR/zoneinfo/GMT XXX 2>&1
--echo #
--echo # Testing with explicit timezonefile --skip-write-binlog --skip-wsrep-checks
--echo #
--exec $MYSQL_TZINFO_TO_SQL --skip-write-binlog --skip-wsrep-checks $MYSQLTEST_VARDIR/zoneinfo/GMT XXX 2>&1
--echo #
--echo # Testing with explicit timezonefile --skip-wsrep-checks
--echo #
--exec $MYSQL_TZINFO_TO_SQL --skip-wsrep-checks $MYSQLTEST_VARDIR/zoneinfo/GMT XXX 2>&1
--echo # --echo #
--echo # Testing --leap --echo # Testing --leap
--echo # --echo #
--exec $MYSQL_TZINFO_TO_SQL --leap $MYSQLTEST_VARDIR/zoneinfo/GMT 2>&1 --exec $MYSQL_TZINFO_TO_SQL --leap $MYSQLTEST_VARDIR/zoneinfo/GMT 2>&1
--echo #
--echo # Testing --skip-write-binlog --leap
--echo #
--exec $MYSQL_TZINFO_TO_SQL --skip-write-binlog --leap $MYSQLTEST_VARDIR/zoneinfo/GMT 2>&1
--echo #
--echo # Testing --skip-write-binlog --skip-wsrep-checks --leap
--echo #
--exec $MYSQL_TZINFO_TO_SQL --skip-write-binlog --skip-wsrep-checks --leap $MYSQLTEST_VARDIR/zoneinfo/GMT 2>&1
--echo #
--echo # Testing --skip-wsrep-checks --leap
--echo #
--exec $MYSQL_TZINFO_TO_SQL --skip-wsrep-checks --leap $MYSQLTEST_VARDIR/zoneinfo/GMT 2>&1
#
# #
# Cleanup # Cleanup
# #
......
...@@ -148,7 +148,7 @@ typedef struct st_time_zone_info ...@@ -148,7 +148,7 @@ typedef struct st_time_zone_info
static my_bool prepare_tz_info(TIME_ZONE_INFO *sp, MEM_ROOT *storage); static my_bool prepare_tz_info(TIME_ZONE_INFO *sp, MEM_ROOT *storage);
my_bool opt_leap, opt_verbose, opt_skip_write_binlog; my_bool opt_leap, opt_verbose, opt_skip_write_binlog, opt_skip_wsrep_check;
#if defined(TZINFO2SQL) || defined(TESTTIME) #if defined(TZINFO2SQL) || defined(TESTTIME)
...@@ -2439,12 +2439,16 @@ print_tz_leaps_as_sql(const TIME_ZONE_INFO *sp) ...@@ -2439,12 +2439,16 @@ print_tz_leaps_as_sql(const TIME_ZONE_INFO *sp)
For all timezones. For all timezones.
*/ */
if (!opt_skip_write_binlog) if (!opt_skip_write_binlog)
{
if (!opt_skip_wsrep_check)
printf("\\d |\n" printf("\\d |\n"
"IF (select count(*) from information_schema.global_variables where\n" "IF (select count(*) from information_schema.global_variables where\n"
"variable_name='wsrep_on' and variable_value='ON') = 1 THEN\n" "variable_name='wsrep_on' and variable_value='ON') = 1 THEN\n");
"ALTER TABLE time_zone_leap_second ENGINE=InnoDB;\n" printf("ALTER TABLE time_zone_leap_second ENGINE=InnoDB;\n");
"END IF|\n" if (!opt_skip_wsrep_check)
"\\d ;\n"); printf("END IF|\n"
"\\d ;\n");
}
printf("TRUNCATE TABLE time_zone_leap_second;\n"); printf("TRUNCATE TABLE time_zone_leap_second;\n");
...@@ -2459,12 +2463,16 @@ print_tz_leaps_as_sql(const TIME_ZONE_INFO *sp) ...@@ -2459,12 +2463,16 @@ print_tz_leaps_as_sql(const TIME_ZONE_INFO *sp)
} }
if (!opt_skip_write_binlog) if (!opt_skip_write_binlog)
{
if (!opt_skip_wsrep_check)
printf("\\d |\n" printf("\\d |\n"
"IF (select count(*) from information_schema.global_variables where\n" "IF (select count(*) from information_schema.global_variables where\n"
"variable_name='wsrep_on' and variable_value='ON') = 1 THEN\n" "variable_name='wsrep_on' and variable_value='ON') = 1 THEN\n");
"ALTER TABLE time_zone_leap_second ENGINE=MyISAM;\n" printf("ALTER TABLE time_zone_leap_second ENGINE=MyISAM;\n");
"END IF|\n" if (!opt_skip_wsrep_check)
"\\d ;\n"); printf("END IF|\n"
"\\d ;\n");
}
printf("ALTER TABLE time_zone_leap_second ORDER BY Transition_time;\n"); printf("ALTER TABLE time_zone_leap_second ORDER BY Transition_time;\n");
} }
...@@ -2642,8 +2650,10 @@ static struct my_option my_long_options[] = ...@@ -2642,8 +2650,10 @@ static struct my_option my_long_options[] =
&opt_verbose, &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, &opt_verbose, &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"version", 'V', "Output version information and exit.", {"version", 'V', "Output version information and exit.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"skip-write-binlog", 'S', "Do not replicate changes to time zone tables to other nodes in a Galera cluster", {"skip-write-binlog", 'S', "Do not replicate changes to time zone tables to the binary log, or to other nodes in a Galera cluster (if wsrep_on=ON)",
&opt_skip_write_binlog,&opt_skip_write_binlog, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, &opt_skip_write_binlog,&opt_skip_write_binlog, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"skip-wsrep-checks", 'G', "Do not check Galera status (wsrep_on=ON) for the --skip-write-binlog option. This also forces Innodb to be use for table loading if --skip-write-binlog is not specified (changing back to MyISAM upon completion).",
&opt_skip_wsrep_check,&opt_skip_wsrep_check, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
}; };
...@@ -2714,34 +2724,36 @@ main(int argc, char **argv) ...@@ -2714,34 +2724,36 @@ main(int argc, char **argv)
if (opt_skip_write_binlog) if (opt_skip_write_binlog)
{ {
/* If skip_write_binlog is set and wsrep is compiled in we disable /* If skip_write_binlog we disable sql_log_bin and wsrep_on to avoid Galera
sql_log_bin and wsrep_on to avoid Galera replicating below replicating the TRUNCATE TABLE clauses below. This will allow user to set
truncate table clauses. This will allow user to set different different time zones to nodes in Galera cluster.
time zones to nodes in Galera cluster. */ If skip_wsrep_check is enabled, we unconditionally do this. This is useful
printf("set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on' and variable_value='ON'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?');\n" in a traditional replication mode as the loading using ENGINE=Innodb is
"prepare set_wsrep_write_binlog from @prep1;\n" faster than Aria. Otherwise we do this only if WSREP_ON=ON. */
"set @toggle=0; execute set_wsrep_write_binlog using @toggle;\n"); if (opt_skip_wsrep_check)
} printf("SET SESSION SQL_LOG_BIN=0, WSREP_ON=OFF;\n");
else else
{ printf("set @prep1=if((select count(*) from information_schema.global_variables where variable_name='wsrep_on' and variable_value='ON'), 'SET SESSION SQL_LOG_BIN=?, WSREP_ON=OFF;', 'do ?');\n"
// Alter time zone tables to InnoDB if wsrep_on is enabled "prepare set_wsrep_write_binlog from @prep1;\n"
// to allow changes to them to replicate with Galera "set @toggle=0; execute set_wsrep_write_binlog using @toggle;\n");
printf("\\d |\n"
"IF (select count(*) from information_schema.global_variables where\n"
"variable_name='wsrep_on' and variable_value='ON') = 1 THEN\n"
"ALTER TABLE time_zone ENGINE=InnoDB;\n"
"ALTER TABLE time_zone_name ENGINE=InnoDB;\n"
"ALTER TABLE time_zone_transition ENGINE=InnoDB;\n"
"ALTER TABLE time_zone_transition_type ENGINE=InnoDB;\n"
"END IF|\n"
"\\d ;\n");
} }
if (argc == 1 && !opt_leap) if (argc == 1 && !opt_leap)
{ {
/* Argument is timezonedir */ if (!opt_skip_write_binlog)
{
root_name_end= strmake_buf(fullname, argv[0]); if (!opt_skip_wsrep_check)
printf("\\d |\n"
"IF (select count(*) from information_schema.global_variables where\n"
"variable_name='wsrep_on' and variable_value='ON') = 1 THEN\n");
printf("ALTER TABLE time_zone ENGINE=InnoDB;\n"
"ALTER TABLE time_zone_name ENGINE=InnoDB;\n"
"ALTER TABLE time_zone_transition ENGINE=InnoDB;\n"
"ALTER TABLE time_zone_transition_type ENGINE=InnoDB;\n");
if (!opt_skip_wsrep_check)
printf("END IF|\n"
"\\d ;\n");
}
printf("TRUNCATE TABLE time_zone;\n"); printf("TRUNCATE TABLE time_zone;\n");
printf("TRUNCATE TABLE time_zone_name;\n"); printf("TRUNCATE TABLE time_zone_name;\n");
...@@ -2749,6 +2761,9 @@ main(int argc, char **argv) ...@@ -2749,6 +2761,9 @@ main(int argc, char **argv)
printf("TRUNCATE TABLE time_zone_transition_type;\n"); printf("TRUNCATE TABLE time_zone_transition_type;\n");
printf("START TRANSACTION;\n"); printf("START TRANSACTION;\n");
/* Argument is timezonedir */
root_name_end= strmake_buf(fullname, argv[0]);
if (scan_tz_dir(root_name_end, 0, opt_verbose)) if (scan_tz_dir(root_name_end, 0, opt_verbose))
{ {
printf("ROLLBACK;\n"); printf("ROLLBACK;\n");
...@@ -2787,18 +2802,21 @@ main(int argc, char **argv) ...@@ -2787,18 +2802,21 @@ main(int argc, char **argv)
free_root(&tz_storage, MYF(0)); free_root(&tz_storage, MYF(0));
} }
if(!opt_skip_write_binlog) if (argc == 1 && !opt_skip_write_binlog && !opt_leap)
{ {
// Fall back to MyISAM // Fall back to MyISAM
if (!opt_skip_wsrep_check)
printf("\\d |\n" printf("\\d |\n"
"IF (select count(*) from information_schema.global_variables where\n" "IF (select count(*) from information_schema.global_variables where\n"
"variable_name='wsrep_on' and variable_value='ON') = 1 THEN\n" "variable_name='wsrep_on' and variable_value='ON') = 1 THEN\n");
"ALTER TABLE time_zone ENGINE=MyISAM;\n" printf(
"ALTER TABLE time_zone_name ENGINE=MyISAM;\n" "ALTER TABLE time_zone ENGINE=MyISAM;\n"
"ALTER TABLE time_zone_transition ENGINE=MyISAM;\n" "ALTER TABLE time_zone_name ENGINE=MyISAM;\n"
"ALTER TABLE time_zone_transition_type ENGINE=MyISAM;\n" "ALTER TABLE time_zone_transition ENGINE=MyISAM, ORDER BY Time_zone_id, Transition_time;\n"
"END IF|\n" "ALTER TABLE time_zone_transition_type ENGINE=MyISAM, ORDER BY Time_zone_id, Transition_type_id;\n");
"\\d ;\n"); if (!opt_skip_wsrep_check)
printf("END IF|\n"
"\\d ;\n");
} }
free_defaults(default_argv); free_defaults(default_argv);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment