mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
Merge 10.5 into 10.6
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
/*
|
||||
Copyright (c) 2000, 2015, Oracle and/or its affiliates.
|
||||
Copyright (c) 2008, 2020, MariaDB Corporation.
|
||||
Copyright (c) 2008, 2021, MariaDB Corporation.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@ -1531,16 +1531,29 @@ void THD::reset_db(const LEX_CSTRING *new_db)
|
||||
|
||||
/* Do operations that may take a long time */
|
||||
|
||||
void THD::cleanup(void)
|
||||
void THD::cleanup(bool have_mutex)
|
||||
{
|
||||
DBUG_ENTER("THD::cleanup");
|
||||
DBUG_ASSERT(cleanup_done == 0);
|
||||
|
||||
set_killed(KILL_CONNECTION);
|
||||
if (have_mutex)
|
||||
set_killed_no_mutex(KILL_CONNECTION,0,0);
|
||||
else
|
||||
set_killed(KILL_CONNECTION);
|
||||
#ifdef WITH_WSREP
|
||||
if (wsrep_cs().state() != wsrep::client_state::s_none)
|
||||
{
|
||||
wsrep_cs().cleanup();
|
||||
if (have_mutex)
|
||||
{
|
||||
mysql_mutex_assert_owner(static_cast<mysql_mutex_t*>
|
||||
(m_wsrep_mutex.native()));
|
||||
// Below wsrep-lib function will not acquire any mutexes
|
||||
wsrep::unique_lock<wsrep::mutex> lock(m_wsrep_mutex, std::adopt_lock);
|
||||
wsrep_cs().cleanup(lock);
|
||||
lock.release();
|
||||
}
|
||||
else
|
||||
wsrep_cs().cleanup();
|
||||
}
|
||||
wsrep_client_thread= false;
|
||||
#endif /* WITH_WSREP */
|
||||
@ -1614,16 +1627,38 @@ void THD::cleanup(void)
|
||||
void THD::free_connection()
|
||||
{
|
||||
DBUG_ASSERT(free_connection_done == 0);
|
||||
my_free((char*) db.str);
|
||||
/* Make sure threads are not available via server_threads. */
|
||||
assert_not_linked();
|
||||
|
||||
/*
|
||||
Other threads may have a lock on THD::LOCK_thd_data or
|
||||
THD::LOCK_thd_kill to ensure that this THD is not deleted
|
||||
while they access it. The following mutex_lock ensures
|
||||
that no one else is using this THD and it's now safe to
|
||||
continue.
|
||||
|
||||
For example consider KILL-statement execution on
|
||||
sql_parse.cc kill_one_thread() that will use
|
||||
THD::LOCK_thd_data to protect victim thread during
|
||||
THD::awake().
|
||||
*/
|
||||
mysql_mutex_lock(&LOCK_thd_data);
|
||||
mysql_mutex_lock(&LOCK_thd_kill);
|
||||
|
||||
#ifdef WITH_WSREP
|
||||
delete wsrep_rgi;
|
||||
wsrep_rgi= nullptr;
|
||||
#endif /* WITH_WSREP */
|
||||
my_free(const_cast<char*>(db.str));
|
||||
db= null_clex_str;
|
||||
#ifndef EMBEDDED_LIBRARY
|
||||
if (net.vio)
|
||||
vio_delete(net.vio);
|
||||
net.vio= 0;
|
||||
net.vio= nullptr;
|
||||
net_end(&net);
|
||||
#endif
|
||||
if (!cleanup_done)
|
||||
cleanup();
|
||||
if (!cleanup_done)
|
||||
cleanup(true); // We have locked THD::LOCK_thd_kill
|
||||
ha_close_connection(this);
|
||||
plugin_thdvar_cleanup(this);
|
||||
mysql_audit_free_thd(this);
|
||||
@ -1635,6 +1670,8 @@ void THD::free_connection()
|
||||
profiling.restart(); // Reset profiling
|
||||
#endif
|
||||
debug_sync_reset_thread(this);
|
||||
mysql_mutex_unlock(&LOCK_thd_kill);
|
||||
mysql_mutex_unlock(&LOCK_thd_data);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1690,24 +1727,10 @@ THD::~THD()
|
||||
if (!status_in_global)
|
||||
add_status_to_global();
|
||||
|
||||
/*
|
||||
Other threads may have a lock on LOCK_thd_kill to ensure that this
|
||||
THD is not deleted while they access it. The following mutex_lock
|
||||
ensures that no one else is using this THD and it's now safe to delete
|
||||
*/
|
||||
if (WSREP_NNULL(this)) mysql_mutex_lock(&LOCK_thd_data);
|
||||
mysql_mutex_lock(&LOCK_thd_kill);
|
||||
mysql_mutex_unlock(&LOCK_thd_kill);
|
||||
if (WSREP_NNULL(this)) mysql_mutex_unlock(&LOCK_thd_data);
|
||||
|
||||
if (!free_connection_done)
|
||||
free_connection();
|
||||
|
||||
#ifdef WITH_WSREP
|
||||
if (wsrep_rgi != NULL) {
|
||||
delete wsrep_rgi;
|
||||
wsrep_rgi = NULL;
|
||||
}
|
||||
mysql_cond_destroy(&COND_wsrep_thd);
|
||||
#endif
|
||||
mdl_context.destroy();
|
||||
@ -3154,12 +3177,12 @@ static File create_file(THD *thd, char *path, sql_exchange *exchange,
|
||||
}
|
||||
/* Create the file world readable */
|
||||
if ((file= mysql_file_create(key_select_to_file,
|
||||
path, 0666, O_WRONLY|O_EXCL, MYF(MY_WME))) < 0)
|
||||
path, 0644, O_WRONLY|O_EXCL, MYF(MY_WME))) < 0)
|
||||
return file;
|
||||
#ifdef HAVE_FCHMOD
|
||||
(void) fchmod(file, 0666); // Because of umask()
|
||||
(void) fchmod(file, 0644); // Because of umask()
|
||||
#else
|
||||
(void) chmod(path, 0666);
|
||||
(void) chmod(path, 0644);
|
||||
#endif
|
||||
if (init_io_cache(cache, file, 0L, WRITE_CACHE, 0L, 1, MYF(MY_WME)))
|
||||
{
|
||||
|
Reference in New Issue
Block a user