Skip to content

Commit 111acb7

Browse files
author
Jan Lindström
committed
MDEV-9359: encryption.create_or_replace fails sporadically in buildbot: failing assertion: mutex->magic_n == MUTEX_MAGIC_N
Make sure that encryption threads mutex is initialized before starting encryption threads.
1 parent 56e0de0 commit 111acb7

File tree

6 files changed

+52
-20
lines changed

6 files changed

+52
-20
lines changed

storage/innobase/fil/fil0crypt.cc

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,6 +2294,10 @@ fil_crypt_set_thread_cnt(
22942294
/*=====================*/
22952295
uint new_cnt) /*!< in: New key rotation thread count */
22962296
{
2297+
if (!fil_crypt_threads_inited) {
2298+
fil_crypt_threads_init();
2299+
}
2300+
22972301
if (new_cnt > srv_n_fil_crypt_threads) {
22982302
uint add = new_cnt - srv_n_fil_crypt_threads;
22992303
srv_n_fil_crypt_threads = new_cnt;
@@ -2358,15 +2362,18 @@ void
23582362
fil_crypt_threads_init()
23592363
/*====================*/
23602364
{
2361-
fil_crypt_event = os_event_create();
2362-
fil_crypt_threads_event = os_event_create();
2363-
mutex_create(fil_crypt_threads_mutex_key,
2364-
&fil_crypt_threads_mutex, SYNC_NO_ORDER_CHECK);
2365-
2366-
uint cnt = srv_n_fil_crypt_threads;
2367-
srv_n_fil_crypt_threads = 0;
2368-
fil_crypt_set_thread_cnt(cnt);
2369-
fil_crypt_threads_inited = true;
2365+
ut_ad(mutex_own(&fil_system->mutex));
2366+
if (!fil_crypt_threads_inited) {
2367+
fil_crypt_event = os_event_create();
2368+
fil_crypt_threads_event = os_event_create();
2369+
mutex_create(fil_crypt_threads_mutex_key,
2370+
&fil_crypt_threads_mutex, SYNC_NO_ORDER_CHECK);
2371+
2372+
uint cnt = srv_n_fil_crypt_threads;
2373+
srv_n_fil_crypt_threads = 0;
2374+
fil_crypt_threads_inited = true;
2375+
fil_crypt_set_thread_cnt(cnt);
2376+
}
23702377
}
23712378

23722379
/*********************************************************************
@@ -2389,6 +2396,7 @@ fil_crypt_threads_cleanup()
23892396
{
23902397
os_event_free(fil_crypt_event);
23912398
os_event_free(fil_crypt_threads_event);
2399+
fil_crypt_threads_inited = false;
23922400
}
23932401

23942402
/*********************************************************************

storage/innobase/srv/srv0start.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2984,7 +2984,9 @@ innobase_start_or_create_for_mysql(void)
29842984
fts_optimize_init();
29852985

29862986
/* Create thread(s) that handles key rotation */
2987+
fil_system_enter();
29872988
fil_crypt_threads_init();
2989+
fil_system_exit();
29882990

29892991
/* Create the log scrub thread */
29902992
if (srv_scrub_log)

storage/innobase/sync/sync0sync.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,13 @@ mutex_validate(
422422
const ib_mutex_t* mutex) /*!< in: mutex */
423423
{
424424
ut_a(mutex);
425-
ut_a(mutex->magic_n == MUTEX_MAGIC_N);
425+
426+
if (mutex->magic_n != MUTEX_MAGIC_N) {
427+
ib_logf(IB_LOG_LEVEL_ERROR,
428+
"Mutex %p not initialized file %s line %lu.",
429+
mutex, mutex->cfile_name, mutex->cline);
430+
}
431+
ut_ad(mutex->magic_n == MUTEX_MAGIC_N);
426432

427433
return(TRUE);
428434
}

storage/xtradb/fil/fil0crypt.cc

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,6 +2294,10 @@ fil_crypt_set_thread_cnt(
22942294
/*=====================*/
22952295
uint new_cnt) /*!< in: New key rotation thread count */
22962296
{
2297+
if (!fil_crypt_threads_inited) {
2298+
fil_crypt_threads_init();
2299+
}
2300+
22972301
if (new_cnt > srv_n_fil_crypt_threads) {
22982302
uint add = new_cnt - srv_n_fil_crypt_threads;
22992303
srv_n_fil_crypt_threads = new_cnt;
@@ -2358,15 +2362,18 @@ void
23582362
fil_crypt_threads_init()
23592363
/*====================*/
23602364
{
2361-
fil_crypt_event = os_event_create();
2362-
fil_crypt_threads_event = os_event_create();
2363-
mutex_create(fil_crypt_threads_mutex_key,
2364-
&fil_crypt_threads_mutex, SYNC_NO_ORDER_CHECK);
2365-
2366-
uint cnt = srv_n_fil_crypt_threads;
2367-
srv_n_fil_crypt_threads = 0;
2368-
fil_crypt_set_thread_cnt(cnt);
2369-
fil_crypt_threads_inited = true;
2365+
ut_ad(mutex_own(&fil_system->mutex));
2366+
if (!fil_crypt_threads_inited) {
2367+
fil_crypt_event = os_event_create();
2368+
fil_crypt_threads_event = os_event_create();
2369+
mutex_create(fil_crypt_threads_mutex_key,
2370+
&fil_crypt_threads_mutex, SYNC_NO_ORDER_CHECK);
2371+
2372+
uint cnt = srv_n_fil_crypt_threads;
2373+
srv_n_fil_crypt_threads = 0;
2374+
fil_crypt_threads_inited = true;
2375+
fil_crypt_set_thread_cnt(cnt);
2376+
}
23702377
}
23712378

23722379
/*********************************************************************
@@ -2389,6 +2396,7 @@ fil_crypt_threads_cleanup()
23892396
{
23902397
os_event_free(fil_crypt_event);
23912398
os_event_free(fil_crypt_threads_event);
2399+
fil_crypt_threads_inited = false;
23922400
}
23932401

23942402
/*********************************************************************

storage/xtradb/srv/srv0start.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,7 +3076,9 @@ innobase_start_or_create_for_mysql(void)
30763076
fts_optimize_init();
30773077

30783078
/* Create thread(s) that handles key rotation */
3079+
fil_system_enter();
30793080
fil_crypt_threads_init();
3081+
fil_system_exit();
30803082

30813083
/* Create the log scrub thread */
30823084
if (srv_scrub_log)

storage/xtradb/sync/sync0sync.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,13 @@ mutex_validate(
482482
const ib_mutex_t* mutex) /*!< in: mutex */
483483
{
484484
ut_a(mutex);
485-
ut_a(mutex->magic_n == MUTEX_MAGIC_N);
485+
486+
if (mutex->magic_n != MUTEX_MAGIC_N) {
487+
ib_logf(IB_LOG_LEVEL_ERROR,
488+
"Mutex %p not initialized file %s line %lu.",
489+
mutex, mutex->cfile_name, mutex->cline);
490+
}
491+
ut_ad(mutex->magic_n == MUTEX_MAGIC_N);
486492

487493
return(TRUE);
488494
}

0 commit comments

Comments
 (0)