Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PS-4711: crash on TokuDB PFS-instrumented mutexes deinitialization #2479

Merged
merged 1 commit into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mysql-test/suite/tokudb.perfschema/r/bug-ps-4711.result
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# restart
9 changes: 9 additions & 0 deletions mysql-test/suite/tokudb.perfschema/t/bug-ps-4711.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# PS-4711 test
# All PFS objects deinitialization must be before PFS shutdown, otherwise
# there will be crash on server shutdown

--source include/not_embedded.inc
--source include/have_perfschema.inc
--source include/have_tokudb.inc

--source include/restart_mysqld.inc
2 changes: 1 addition & 1 deletion storage/tokudb/PerconaFT
Submodule PerconaFT updated 1 files
+3 −0 src/ydb.cc
6 changes: 5 additions & 1 deletion storage/tokudb/hatoku_hton.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.

======= */

#ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
#ident \
"Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."

#include "hatoku_hton.h"
#include "src/ydb.h"

#include <dlfcn.h>

Expand Down Expand Up @@ -648,6 +650,8 @@ static int tokudb_done_func(TOKUDB_UNUSED(void* p)) {
toku_global_status_variables = NULL;
tokudb::memory::free(toku_global_status_rows);
toku_global_status_rows = NULL;
tokudb_map_mutex.deinit();
toku_ydb_destroy();
TOKUDB_DBUG_RETURN(0);
}

Expand Down
35 changes: 20 additions & 15 deletions storage/tokudb/tokudb_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ class mutex_t {
~mutex_t(void);

void reinit(pfs_key_t key);
void deinit();
void lock(
#if defined(SAFE_MUTEX) || defined(HAVE_PSI_MUTEX_INTERFACE)
const char* src_file,
uint src_line
#endif // SAFE_MUTEX || HAVE_PSI_MUTEX_INTERFACE
);
);
void unlock(
#if defined(SAFE_MUTEX)
const char* src_file,
Expand All @@ -61,8 +62,9 @@ class mutex_t {
#ifdef TOKUDB_DEBUG
bool is_owned_by_me(void) const;
#endif
private:
private:
static pthread_t _null_owner;
bool initialized;
mysql_mutex_t _mutex;
#ifdef TOKUDB_DEBUG
uint _owners;
Expand Down Expand Up @@ -199,37 +201,40 @@ class thread_t {

inline uint my_tid(void) { return (uint)toku_os_gettid(); }

inline mutex_t::mutex_t(pfs_key_t key) {
inline mutex_t::mutex_t(pfs_key_t key) : initialized(false) {
#ifdef TOKUDB_DEBUG
_owners = 0;
_owner = _null_owner;
#endif
int r MY_ATTRIBUTE((unused)) = mysql_mutex_init(key, &_mutex, MY_MUTEX_INIT_FAST);
int r MY_ATTRIBUTE((unused)) =
mysql_mutex_init(key, &_mutex, MY_MUTEX_INIT_FAST);
assert_debug(r == 0);
initialized = true;
}
inline mutex_t::~mutex_t(void) {
#ifdef TOKUDB_DEBUG
assert_debug(_owners == 0);
#endif
int r MY_ATTRIBUTE((unused)) = mysql_mutex_destroy(&_mutex);
inline mutex_t::~mutex_t(void) { deinit(); }
inline void mutex_t::reinit(pfs_key_t key) {
deinit();
int r MY_ATTRIBUTE((unused)) =
mysql_mutex_init(key, &_mutex, MY_MUTEX_INIT_FAST);
assert_debug(r == 0);
initialized = true;
}
inline void mutex_t::reinit(pfs_key_t key) {
inline void mutex_t::deinit() {
#ifdef TOKUDB_DEBUG
assert_debug(_owners == 0);
#endif
int r MY_ATTRIBUTE((unused));
r = mysql_mutex_destroy(&_mutex);
assert_debug(r == 0);
r = mysql_mutex_init(key, &_mutex, MY_MUTEX_INIT_FAST);
if (!initialized)
return;
int r MY_ATTRIBUTE((unused)) = mysql_mutex_destroy(&_mutex);
assert_debug(r == 0);
initialized = false;
}
inline void mutex_t::lock(
#if defined(SAFE_MUTEX) || defined(HAVE_PSI_MUTEX_INTERFACE)
const char* src_file,
uint src_line
#endif // SAFE_MUTEX || HAVE_PSI_MUTEX_INTERFACE
) {
) {
assert_debug(is_owned_by_me() == false);
int r MY_ATTRIBUTE((unused)) = inline_mysql_mutex_lock(&_mutex
#if defined(SAFE_MUTEX) || defined(HAVE_PSI_MUTEX_INTERFACE)
Expand Down