Skip to content

Commit c88fd54

Browse files
committed
Execute bootstrap in main thread
Bootstrap in a separate thread was introduced in 746f0b3 to workaround OS/2 small stack size. OS/2 support was discontinued in 2006 and modern operating systems have default stack size a few times larger than default thread_stack and it is tunable. Aim is to reduce usage of LOCK_thread_count and COND_thread_count. Part of MDEV-15135.
1 parent 7ad742b commit c88fd54

File tree

7 files changed

+23
-126
lines changed

7 files changed

+23
-126
lines changed

sql/mysqld.cc

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -400,20 +400,6 @@ uint volatile global_disable_checkpoint;
400400
#if defined(_WIN32) && !defined(EMBEDDED_LIBRARY)
401401
ulong slow_start_timeout;
402402
#endif
403-
/*
404-
True if the bootstrap thread is running. Protected by LOCK_start_thread.
405-
Used in bootstrap() function to determine if the bootstrap thread
406-
has completed. Note, that we can't use 'thread_count' instead,
407-
since in 5.1, in presence of the Event Scheduler, there may be
408-
event threads running in parallel, so it's impossible to know
409-
what value of 'thread_count' is a sign of completion of the
410-
bootstrap thread.
411-
412-
At the same time, we can't start the event scheduler after
413-
bootstrap either, since we want to be able to process event-related
414-
SQL commands in the init file and in --bootstrap mode.
415-
*/
416-
bool volatile in_bootstrap= FALSE;
417403
/**
418404
@brief 'grant_option' is used to indicate if privileges needs
419405
to be checked, in which case the lock, LOCK_grant, is used
@@ -663,7 +649,6 @@ Lt_creator lt_creator;
663649
Ge_creator ge_creator;
664650
Le_creator le_creator;
665651

666-
MYSQL_FILE *bootstrap_file;
667652
int bootstrap_error;
668653

669654
I_List<THD> threads;
@@ -736,7 +721,6 @@ mysql_mutex_t LOCK_thread_count;
736721
other threads.
737722
738723
It also protects these variables:
739-
in_bootstrap
740724
select_thread_in_use
741725
slave_init_thread_running
742726
check_temp_dir() call
@@ -1542,7 +1526,6 @@ void handle_connections_sockets();
15421526
#endif
15431527

15441528
pthread_handler_t kill_server_thread(void *arg);
1545-
static void bootstrap(MYSQL_FILE *file);
15461529
static bool read_init_file(char *file_name);
15471530
pthread_handler_t handle_slave(void *arg);
15481531
static void clean_up(bool print_message);
@@ -6320,54 +6303,6 @@ int mysqld_main(int argc, char **argv)
63206303
#endif
63216304

63226305

6323-
/**
6324-
Execute all commands from a file. Used by the mysql_install_db script to
6325-
create MySQL privilege tables without having to start a full MySQL server
6326-
and by read_init_file() if mysqld was started with the option --init-file.
6327-
*/
6328-
6329-
static void bootstrap(MYSQL_FILE *file)
6330-
{
6331-
DBUG_ENTER("bootstrap");
6332-
6333-
THD *thd= new THD(next_thread_id());
6334-
#ifdef WITH_WSREP
6335-
thd->variables.wsrep_on= 0;
6336-
#endif
6337-
thd->bootstrap=1;
6338-
my_net_init(&thd->net,(st_vio*) 0, thd, MYF(0));
6339-
thd->max_client_packet_length= thd->net.max_packet;
6340-
thd->security_ctx->master_access= ~(ulong)0;
6341-
in_bootstrap= TRUE;
6342-
6343-
bootstrap_file=file;
6344-
#ifndef EMBEDDED_LIBRARY // TODO: Enable this
6345-
int error;
6346-
if ((error= mysql_thread_create(key_thread_bootstrap,
6347-
&thd->real_id, &connection_attrib,
6348-
handle_bootstrap,
6349-
(void*) thd)))
6350-
{
6351-
sql_print_warning("Can't create thread to handle bootstrap (errno= %d)",
6352-
error);
6353-
bootstrap_error=-1;
6354-
delete thd;
6355-
DBUG_VOID_RETURN;
6356-
}
6357-
/* Wait for thread to die */
6358-
mysql_mutex_lock(&LOCK_thread_count);
6359-
while (in_bootstrap)
6360-
mysql_cond_wait(&COND_thread_count, &LOCK_thread_count);
6361-
mysql_mutex_unlock(&LOCK_thread_count);
6362-
#else
6363-
thd->mysql= 0;
6364-
do_handle_bootstrap(thd);
6365-
#endif
6366-
6367-
DBUG_VOID_RETURN;
6368-
}
6369-
6370-
63716306
static bool read_init_file(char *file_name)
63726307
{
63736308
MYSQL_FILE *file;

sql/mysqld.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ extern bool opt_ignore_builtin_innodb;
128128
extern my_bool opt_character_set_client_handshake;
129129
extern my_bool debug_assert_on_not_freed_memory;
130130
extern bool volatile abort_loop;
131-
extern bool volatile in_bootstrap;
132131
extern uint connection_count;
133132
extern my_bool opt_safe_user_create;
134133
extern my_bool opt_safe_show_db, opt_local_infile, opt_myisam_use_mmap;
@@ -297,7 +296,6 @@ extern int mysqld_server_started, mysqld_server_initialized;
297296
extern "C" MYSQL_PLUGIN_IMPORT int orig_argc;
298297
extern "C" MYSQL_PLUGIN_IMPORT char **orig_argv;
299298
extern pthread_attr_t connection_attrib;
300-
extern MYSQL_FILE *bootstrap_file;
301299
extern my_bool old_mode;
302300
extern LEX_STRING opt_init_connect, opt_init_slave;
303301
extern int bootstrap_error;

sql/sql_acl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3318,7 +3318,7 @@ static int check_alter_user(THD *thd, const char *host, const char *user)
33183318

33193319
if (IF_WSREP((!WSREP(thd) || !thd->wsrep_applier), 1) &&
33203320
!thd->slave_thread && !thd->security_ctx->priv_user[0] &&
3321-
!in_bootstrap)
3321+
!thd->bootstrap)
33223322
{
33233323
my_message(ER_PASSWORD_ANONYMOUS_USER,
33243324
ER_THD(thd, ER_PASSWORD_ANONYMOUS_USER),

sql/sql_db.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ mysql_rm_db_internal(THD *thd, const LEX_CSTRING *db, bool if_exists, bool silen
882882
lock_db_routines(thd, dbnorm))
883883
goto exit;
884884

885-
if (!in_bootstrap && !rm_mysql_schema)
885+
if (!thd->bootstrap && !rm_mysql_schema)
886886
{
887887
for (table= tables; table; table= table->next_local)
888888
{

sql/sql_parse.cc

Lines changed: 19 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -979,15 +979,28 @@ static char *fgets_fn(char *buffer, size_t size, fgets_input_t input, int *error
979979
}
980980

981981

982-
static void handle_bootstrap_impl(THD *thd)
982+
void bootstrap(MYSQL_FILE *file)
983983
{
984-
MYSQL_FILE *file= bootstrap_file;
985-
DBUG_ENTER("handle_bootstrap_impl");
984+
DBUG_ENTER("handle_bootstrap");
985+
986+
THD *thd= new THD(next_thread_id());
987+
#ifdef WITH_WSREP
988+
thd->variables.wsrep_on= 0;
989+
#endif
990+
thd->bootstrap=1;
991+
my_net_init(&thd->net,(st_vio*) 0, thd, MYF(0));
992+
thd->max_client_packet_length= thd->net.max_packet;
993+
thd->security_ctx->master_access= ~(ulong)0;
986994

987995
#ifndef EMBEDDED_LIBRARY
988-
pthread_detach_this_thread();
996+
mysql_thread_set_psi_id(thd->thread_id);
997+
#else
998+
thd->mysql= 0;
999+
#endif
1000+
1001+
/* The following must be called before DBUG_ENTER */
9891002
thd->thread_stack= (char*) &thd;
990-
#endif /* EMBEDDED_LIBRARY */
1003+
thd->store_globals();
9911004

9921005
thd->security_ctx->user= (char*) my_strdup("boot", MYF(MY_WME));
9931006
thd->security_ctx->priv_user[0]= thd->security_ctx->priv_host[0]=
@@ -1095,56 +1108,8 @@ static void handle_bootstrap_impl(THD *thd)
10951108
free_root(&thd->transaction.mem_root,MYF(MY_KEEP_PREALLOC));
10961109
thd->lex->restore_set_statement_var();
10971110
}
1098-
1099-
DBUG_VOID_RETURN;
1100-
}
1101-
1102-
1103-
/**
1104-
Execute commands from bootstrap_file.
1105-
1106-
Used when creating the initial grant tables.
1107-
*/
1108-
1109-
pthread_handler_t handle_bootstrap(void *arg)
1110-
{
1111-
THD *thd=(THD*) arg;
1112-
1113-
mysql_thread_set_psi_id(thd->thread_id);
1114-
1115-
do_handle_bootstrap(thd);
1116-
return 0;
1117-
}
1118-
1119-
void do_handle_bootstrap(THD *thd)
1120-
{
1121-
/* The following must be called before DBUG_ENTER */
1122-
thd->thread_stack= (char*) &thd;
1123-
if (my_thread_init() || thd->store_globals())
1124-
{
1125-
#ifndef EMBEDDED_LIBRARY
1126-
close_connection(thd, ER_OUT_OF_RESOURCES);
1127-
#endif
1128-
thd->fatal_error();
1129-
goto end;
1130-
}
1131-
1132-
handle_bootstrap_impl(thd);
1133-
1134-
end:
11351111
delete thd;
1136-
1137-
mysql_mutex_lock(&LOCK_thread_count);
1138-
in_bootstrap = FALSE;
1139-
mysql_cond_broadcast(&COND_thread_count);
1140-
mysql_mutex_unlock(&LOCK_thread_count);
1141-
1142-
#ifndef EMBEDDED_LIBRARY
1143-
my_thread_end();
1144-
pthread_exit(0);
1145-
#endif
1146-
1147-
return;
1112+
DBUG_VOID_RETURN;
11481113
}
11491114

11501115

sql/sql_parse.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,9 @@ void create_table_set_open_action_and_adjust_tables(LEX *lex);
9999
void mysql_init_multi_delete(LEX *lex);
100100
bool multi_delete_set_locks_and_link_aux_tables(LEX *lex);
101101
void create_table_set_open_action_and_adjust_tables(LEX *lex);
102-
pthread_handler_t handle_bootstrap(void *arg);
102+
void bootstrap(MYSQL_FILE *file);
103103
int mysql_execute_command(THD *thd);
104104
bool do_command(THD *thd);
105-
void do_handle_bootstrap(THD *thd);
106105
bool dispatch_command(enum enum_server_command command, THD *thd,
107106
char* packet, uint packet_length,
108107
bool is_com_multi, bool is_next_command);

sql/sql_table.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,7 @@ bool mysql_rm_table(THD *thd,TABLE_LIST *tables, bool if_exists,
21042104
}
21052105
}
21062106
/* We remove statistics for table last, after we have the DDL lock */
2107-
if (!in_bootstrap)
2107+
if (!thd->bootstrap)
21082108
{
21092109
for (table= tables; table; table= table->next_local)
21102110
{

0 commit comments

Comments
 (0)