Commit 2f29fc3c authored by Marko Mäkelä's avatar Marko Mäkelä

10.1 additions for MDEV-12052 Shutdown crash presumably due to master thread activity

btr_defragment_thread(): Create the thread in the same place as other
threads. Do not invoke btr_defragment_shutdown(), because
row_drop_tables_for_mysql_in_background() in the master thread can still
keep invoking btr_defragment_remove_table().

logs_empty_and_mark_files_at_shutdown(): Wait for btr_defragment_thread()
to exit.

innobase_start_or_create_for_mysql(), innobase_shutdown_for_mysql():
Skip encryption and scrubbing in innodb_read_only_mode.

srv_export_innodb_status(): Do not export encryption or scrubbing
statistics in innodb_read_only mode, because the threads will not
be running.
parent 4abc2dd0
...@@ -154,7 +154,6 @@ btr_defragment_init() ...@@ -154,7 +154,6 @@ btr_defragment_init()
1000000.0 / srv_defragment_frequency); 1000000.0 / srv_defragment_frequency);
mutex_create(btr_defragment_mutex_key, &btr_defragment_mutex, mutex_create(btr_defragment_mutex_key, &btr_defragment_mutex,
SYNC_ANY_LATCH); SYNC_ANY_LATCH);
os_thread_create(btr_defragment_thread, NULL, NULL);
} }
/******************************************************************//** /******************************************************************//**
...@@ -735,14 +734,13 @@ btr_defragment_n_pages( ...@@ -735,14 +734,13 @@ btr_defragment_n_pages(
return current_block; return current_block;
} }
/******************************************************************//** /** Whether btr_defragment_thread is active */
Thread that merges consecutive b-tree pages into fewer pages to defragment bool btr_defragment_thread_active;
the index. */
/** Merge consecutive b-tree pages into fewer pages to defragment indexes */
extern "C" UNIV_INTERN extern "C" UNIV_INTERN
os_thread_ret_t os_thread_ret_t
DECLARE_THREAD(btr_defragment_thread)( DECLARE_THREAD(btr_defragment_thread)(void*)
/*==========================================*/
void* arg) /*!< in: work queue */
{ {
btr_pcur_t* pcur; btr_pcur_t* pcur;
btr_cur_t* cursor; btr_cur_t* cursor;
...@@ -752,6 +750,8 @@ DECLARE_THREAD(btr_defragment_thread)( ...@@ -752,6 +750,8 @@ DECLARE_THREAD(btr_defragment_thread)(
buf_block_t* last_block; buf_block_t* last_block;
while (srv_shutdown_state == SRV_SHUTDOWN_NONE) { while (srv_shutdown_state == SRV_SHUTDOWN_NONE) {
ut_ad(btr_defragment_thread_active);
/* If defragmentation is disabled, sleep before /* If defragmentation is disabled, sleep before
checking whether it's enabled. */ checking whether it's enabled. */
if (!srv_defragment) { if (!srv_defragment) {
...@@ -825,9 +825,9 @@ DECLARE_THREAD(btr_defragment_thread)( ...@@ -825,9 +825,9 @@ DECLARE_THREAD(btr_defragment_thread)(
btr_defragment_remove_item(item); btr_defragment_remove_item(item);
} }
} }
btr_defragment_shutdown();
btr_defragment_thread_active = false;
os_thread_exit(NULL); os_thread_exit(NULL);
OS_THREAD_DUMMY_RETURN; OS_THREAD_DUMMY_RETURN;
} }
#endif /* !UNIV_HOTBACKUP */ #endif /* !UNIV_HOTBACKUP */
/***************************************************************************** /*****************************************************************************
Copyright (C) 2013, 2014 Facebook, Inc. All Rights Reserved. Copyright (C) 2013, 2014 Facebook, Inc. All Rights Reserved.
Copyright (C) 2014, 2015, MariaDB Corporation. Copyright (C) 2014, 2017, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under 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 the Free Software the terms of the GNU General Public License as published by the Free Software
...@@ -89,16 +89,14 @@ UNIV_INTERN ...@@ -89,16 +89,14 @@ UNIV_INTERN
void void
btr_defragment_save_defrag_stats_if_needed( btr_defragment_save_defrag_stats_if_needed(
dict_index_t* index); /*!< in: index */ dict_index_t* index); /*!< in: index */
/******************************************************************//**
Thread that merges consecutive b-tree pages into fewer pages to defragment /** Merge consecutive b-tree pages into fewer pages to defragment indexes */
the index. */
extern "C" UNIV_INTERN extern "C" UNIV_INTERN
os_thread_ret_t os_thread_ret_t
DECLARE_THREAD(btr_defragment_thread)( DECLARE_THREAD(btr_defragment_thread)(void*);
/*==========================================*/
void* arg); /*!< in: a dummy parameter required by
os_thread_create */
/** Whether btr_defragment_thread is active */
extern bool btr_defragment_thread_active;
#endif /* !UNIV_HOTBACKUP */ #endif /* !UNIV_HOTBACKUP */
#endif #endif
...@@ -45,12 +45,13 @@ Created 12/9/1995 Heikki Tuuri ...@@ -45,12 +45,13 @@ Created 12/9/1995 Heikki Tuuri
#include "mem0mem.h" #include "mem0mem.h"
#include "buf0buf.h" #include "buf0buf.h"
#include "buf0flu.h" #include "buf0flu.h"
#include "srv0srv.h"
#include "lock0lock.h" #include "lock0lock.h"
#include "log0recv.h" #include "log0recv.h"
#include "fil0fil.h" #include "fil0fil.h"
#include "dict0boot.h" #include "dict0boot.h"
#include "dict0stats_bg.h" /* dict_stats_event */ #include "dict0stats_bg.h"
#include "btr0defragment.h"
#include "srv0srv.h"
#include "srv0start.h" #include "srv0start.h"
#include "trx0sys.h" #include "trx0sys.h"
#include "trx0trx.h" #include "trx0trx.h"
...@@ -3300,6 +3301,8 @@ logs_empty_and_mark_files_at_shutdown(void) ...@@ -3300,6 +3301,8 @@ logs_empty_and_mark_files_at_shutdown(void)
thread_name = "lock_wait_timeout_thread"; thread_name = "lock_wait_timeout_thread";
} else if (srv_buf_dump_thread_active) { } else if (srv_buf_dump_thread_active) {
thread_name = "buf_dump_thread"; thread_name = "buf_dump_thread";
} else if (btr_defragment_thread_active) {
thread_name = "btr_defragment_thread";
} else if (srv_fast_shutdown != 2 && trx_rollback_or_clean_is_active) { } else if (srv_fast_shutdown != 2 && trx_rollback_or_clean_is_active) {
thread_name = "rollback of recovered transactions"; thread_name = "rollback of recovered transactions";
} else { } else {
......
...@@ -1457,8 +1457,10 @@ srv_export_innodb_status(void) ...@@ -1457,8 +1457,10 @@ srv_export_innodb_status(void)
buf_get_total_stat(&stat); buf_get_total_stat(&stat);
buf_get_total_list_len(&LRU_len, &free_len, &flush_list_len); buf_get_total_list_len(&LRU_len, &free_len, &flush_list_len);
buf_get_total_list_size_in_bytes(&buf_pools_list_size); buf_get_total_list_size_in_bytes(&buf_pools_list_size);
if (!srv_read_only_mode) {
fil_crypt_total_stat(&crypt_stat); fil_crypt_total_stat(&crypt_stat);
btr_scrub_total_stat(&scrub_stat); btr_scrub_total_stat(&scrub_stat);
}
mutex_enter(&srv_innodb_monitor_mutex); mutex_enter(&srv_innodb_monitor_mutex);
...@@ -1660,6 +1662,7 @@ srv_export_innodb_status(void) ...@@ -1660,6 +1662,7 @@ srv_export_innodb_status(void)
export_vars.innodb_sec_rec_cluster_reads_avoided = export_vars.innodb_sec_rec_cluster_reads_avoided =
srv_stats.n_sec_rec_cluster_reads_avoided; srv_stats.n_sec_rec_cluster_reads_avoided;
if (!srv_read_only_mode) {
export_vars.innodb_encryption_rotation_pages_read_from_cache = export_vars.innodb_encryption_rotation_pages_read_from_cache =
crypt_stat.pages_read_from_cache; crypt_stat.pages_read_from_cache;
export_vars.innodb_encryption_rotation_pages_read_from_disk = export_vars.innodb_encryption_rotation_pages_read_from_disk =
...@@ -1687,6 +1690,7 @@ srv_export_innodb_status(void) ...@@ -1687,6 +1690,7 @@ srv_export_innodb_status(void)
scrub_stat.page_split_failures_missing_index; scrub_stat.page_split_failures_missing_index;
export_vars.innodb_scrub_page_split_failures_unknown = export_vars.innodb_scrub_page_split_failures_unknown =
scrub_stat.page_split_failures_unknown; scrub_stat.page_split_failures_unknown;
}
mutex_exit(&srv_innodb_monitor_mutex); mutex_exit(&srv_innodb_monitor_mutex);
} }
......
...@@ -2981,13 +2981,15 @@ innobase_start_or_create_for_mysql(void) ...@@ -2981,13 +2981,15 @@ innobase_start_or_create_for_mysql(void)
fil_system_enter(); fil_system_enter();
fil_crypt_threads_init(); fil_crypt_threads_init();
fil_system_exit(); fil_system_exit();
}
/* Init data for datafile scrub threads */ /* Init data for datafile scrub threads */
btr_scrub_init(); btr_scrub_init();
/* Initialize online defragmentation. */ /* Initialize online defragmentation. */
btr_defragment_init(); btr_defragment_init();
btr_defragment_thread_active = true;
os_thread_create(btr_defragment_thread, NULL, NULL);
}
srv_was_started = TRUE; srv_was_started = TRUE;
...@@ -3158,10 +3160,9 @@ innobase_shutdown_for_mysql(void) ...@@ -3158,10 +3160,9 @@ innobase_shutdown_for_mysql(void)
if (!srv_read_only_mode) { if (!srv_read_only_mode) {
dict_stats_thread_deinit(); dict_stats_thread_deinit();
fil_crypt_threads_cleanup(); fil_crypt_threads_cleanup();
}
/* Cleanup data for datafile scrubbing */
btr_scrub_cleanup(); btr_scrub_cleanup();
btr_defragment_shutdown();
}
#ifdef __WIN__ #ifdef __WIN__
/* MDEV-361: ha_innodb.dll leaks handles on Windows /* MDEV-361: ha_innodb.dll leaks handles on Windows
......
...@@ -154,7 +154,6 @@ btr_defragment_init() ...@@ -154,7 +154,6 @@ btr_defragment_init()
1000000.0 / srv_defragment_frequency); 1000000.0 / srv_defragment_frequency);
mutex_create(btr_defragment_mutex_key, &btr_defragment_mutex, mutex_create(btr_defragment_mutex_key, &btr_defragment_mutex,
SYNC_ANY_LATCH); SYNC_ANY_LATCH);
os_thread_create(btr_defragment_thread, NULL, NULL);
} }
/******************************************************************//** /******************************************************************//**
...@@ -735,14 +734,13 @@ btr_defragment_n_pages( ...@@ -735,14 +734,13 @@ btr_defragment_n_pages(
return current_block; return current_block;
} }
/******************************************************************//** /** Whether btr_defragment_thread is active */
Thread that merges consecutive b-tree pages into fewer pages to defragment bool btr_defragment_thread_active;
the index. */
/** Merge consecutive b-tree pages into fewer pages to defragment indexes */
extern "C" UNIV_INTERN extern "C" UNIV_INTERN
os_thread_ret_t os_thread_ret_t
DECLARE_THREAD(btr_defragment_thread)( DECLARE_THREAD(btr_defragment_thread)(void*)
/*==========================================*/
void* arg) /*!< in: work queue */
{ {
btr_pcur_t* pcur; btr_pcur_t* pcur;
btr_cur_t* cursor; btr_cur_t* cursor;
...@@ -752,6 +750,8 @@ DECLARE_THREAD(btr_defragment_thread)( ...@@ -752,6 +750,8 @@ DECLARE_THREAD(btr_defragment_thread)(
buf_block_t* last_block; buf_block_t* last_block;
while (srv_shutdown_state == SRV_SHUTDOWN_NONE) { while (srv_shutdown_state == SRV_SHUTDOWN_NONE) {
ut_ad(btr_defragment_thread_active);
/* If defragmentation is disabled, sleep before /* If defragmentation is disabled, sleep before
checking whether it's enabled. */ checking whether it's enabled. */
if (!srv_defragment) { if (!srv_defragment) {
...@@ -825,9 +825,9 @@ DECLARE_THREAD(btr_defragment_thread)( ...@@ -825,9 +825,9 @@ DECLARE_THREAD(btr_defragment_thread)(
btr_defragment_remove_item(item); btr_defragment_remove_item(item);
} }
} }
btr_defragment_shutdown();
btr_defragment_thread_active = false;
os_thread_exit(NULL); os_thread_exit(NULL);
OS_THREAD_DUMMY_RETURN; OS_THREAD_DUMMY_RETURN;
} }
#endif /* !UNIV_HOTBACKUP */ #endif /* !UNIV_HOTBACKUP */
/***************************************************************************** /*****************************************************************************
Copyright (C) 2013, 2014 Facebook, Inc. All Rights Reserved. Copyright (C) 2013, 2014 Facebook, Inc. All Rights Reserved.
Copyright (C) 2014, 2015, MariaDB Corporation. Copyright (C) 2014, 2017, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under 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 the Free Software the terms of the GNU General Public License as published by the Free Software
...@@ -89,15 +89,14 @@ UNIV_INTERN ...@@ -89,15 +89,14 @@ UNIV_INTERN
void void
btr_defragment_save_defrag_stats_if_needed( btr_defragment_save_defrag_stats_if_needed(
dict_index_t* index); /*!< in: index */ dict_index_t* index); /*!< in: index */
/******************************************************************//**
Thread that merges consecutive b-tree pages into fewer pages to defragment /** Merge consecutive b-tree pages into fewer pages to defragment indexes */
the index. */
extern "C" UNIV_INTERN extern "C" UNIV_INTERN
os_thread_ret_t os_thread_ret_t
DECLARE_THREAD(btr_defragment_thread)( DECLARE_THREAD(btr_defragment_thread)(void*);
/*==========================================*/
void* arg); /*!< in: a dummy parameter required by /** Whether btr_defragment_thread is active */
os_thread_create */ extern bool btr_defragment_thread_active;
#endif /* !UNIV_HOTBACKUP */ #endif /* !UNIV_HOTBACKUP */
#endif #endif
...@@ -55,12 +55,13 @@ Created 12/9/1995 Heikki Tuuri ...@@ -55,12 +55,13 @@ Created 12/9/1995 Heikki Tuuri
#include "mem0mem.h" #include "mem0mem.h"
#include "buf0buf.h" #include "buf0buf.h"
#include "buf0flu.h" #include "buf0flu.h"
#include "srv0srv.h"
#include "lock0lock.h" #include "lock0lock.h"
#include "log0recv.h" #include "log0recv.h"
#include "fil0fil.h" #include "fil0fil.h"
#include "dict0boot.h" #include "dict0boot.h"
#include "dict0stats_bg.h" /* dict_stats_event */ #include "dict0stats_bg.h"
#include "dict0stats_bg.h"
#include "btr0defragment.h"
#include "srv0srv.h" #include "srv0srv.h"
#include "srv0start.h" #include "srv0start.h"
#include "trx0sys.h" #include "trx0sys.h"
...@@ -3618,6 +3619,8 @@ logs_empty_and_mark_files_at_shutdown(void) ...@@ -3618,6 +3619,8 @@ logs_empty_and_mark_files_at_shutdown(void)
thread_name = "lock_wait_timeout_thread"; thread_name = "lock_wait_timeout_thread";
} else if (srv_buf_dump_thread_active) { } else if (srv_buf_dump_thread_active) {
thread_name = "buf_dump_thread"; thread_name = "buf_dump_thread";
} else if (btr_defragment_thread_active) {
thread_name = "btr_defragment_thread";
} else if (srv_fast_shutdown != 2 && trx_rollback_or_clean_is_active) { } else if (srv_fast_shutdown != 2 && trx_rollback_or_clean_is_active) {
thread_name = "rollback of recovered transactions"; thread_name = "rollback of recovered transactions";
} else { } else {
......
...@@ -1784,8 +1784,10 @@ srv_export_innodb_status(void) ...@@ -1784,8 +1784,10 @@ srv_export_innodb_status(void)
buf_get_total_stat(&stat); buf_get_total_stat(&stat);
buf_get_total_list_len(&LRU_len, &free_len, &flush_list_len); buf_get_total_list_len(&LRU_len, &free_len, &flush_list_len);
buf_get_total_list_size_in_bytes(&buf_pools_list_size); buf_get_total_list_size_in_bytes(&buf_pools_list_size);
if (!srv_read_only_mode) {
fil_crypt_total_stat(&crypt_stat); fil_crypt_total_stat(&crypt_stat);
btr_scrub_total_stat(&scrub_stat); btr_scrub_total_stat(&scrub_stat);
}
mem_adaptive_hash = 0; mem_adaptive_hash = 0;
...@@ -2099,6 +2101,7 @@ srv_export_innodb_status(void) ...@@ -2099,6 +2101,7 @@ srv_export_innodb_status(void)
export_vars.innodb_sec_rec_cluster_reads_avoided = export_vars.innodb_sec_rec_cluster_reads_avoided =
srv_stats.n_sec_rec_cluster_reads_avoided; srv_stats.n_sec_rec_cluster_reads_avoided;
if (!srv_read_only_mode) {
export_vars.innodb_encryption_rotation_pages_read_from_cache = export_vars.innodb_encryption_rotation_pages_read_from_cache =
crypt_stat.pages_read_from_cache; crypt_stat.pages_read_from_cache;
export_vars.innodb_encryption_rotation_pages_read_from_disk = export_vars.innodb_encryption_rotation_pages_read_from_disk =
...@@ -2126,6 +2129,7 @@ srv_export_innodb_status(void) ...@@ -2126,6 +2129,7 @@ srv_export_innodb_status(void)
scrub_stat.page_split_failures_missing_index; scrub_stat.page_split_failures_missing_index;
export_vars.innodb_scrub_page_split_failures_unknown = export_vars.innodb_scrub_page_split_failures_unknown =
scrub_stat.page_split_failures_unknown; scrub_stat.page_split_failures_unknown;
}
mutex_exit(&srv_innodb_monitor_mutex); mutex_exit(&srv_innodb_monitor_mutex);
} }
......
...@@ -3089,13 +3089,15 @@ innobase_start_or_create_for_mysql(void) ...@@ -3089,13 +3089,15 @@ innobase_start_or_create_for_mysql(void)
fil_system_enter(); fil_system_enter();
fil_crypt_threads_init(); fil_crypt_threads_init();
fil_system_exit(); fil_system_exit();
}
/* Init data for datafile scrub threads */ /* Init data for datafile scrub threads */
btr_scrub_init(); btr_scrub_init();
/* Initialize online defragmentation. */ /* Initialize online defragmentation. */
btr_defragment_init(); btr_defragment_init();
btr_defragment_thread_active = true;
os_thread_create(btr_defragment_thread, NULL, NULL);
}
srv_was_started = TRUE; srv_was_started = TRUE;
...@@ -3260,10 +3262,9 @@ innobase_shutdown_for_mysql(void) ...@@ -3260,10 +3262,9 @@ innobase_shutdown_for_mysql(void)
if (!srv_read_only_mode) { if (!srv_read_only_mode) {
dict_stats_thread_deinit(); dict_stats_thread_deinit();
fil_crypt_threads_cleanup(); fil_crypt_threads_cleanup();
}
/* Cleanup data for datafile scrubbing */
btr_scrub_cleanup(); btr_scrub_cleanup();
btr_defragment_shutdown();
}
#ifdef __WIN__ #ifdef __WIN__
/* MDEV-361: ha_innodb.dll leaks handles on Windows /* MDEV-361: ha_innodb.dll leaks handles on Windows
......
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