diff options
Diffstat (limited to 'storage/innobase/srv/srv0srv.cc')
-rw-r--r-- | storage/innobase/srv/srv0srv.cc | 79 |
1 files changed, 33 insertions, 46 deletions
diff --git a/storage/innobase/srv/srv0srv.cc b/storage/innobase/srv/srv0srv.cc index d25a705c2ef..34638dfda25 100644 --- a/storage/innobase/srv/srv0srv.cc +++ b/storage/innobase/srv/srv0srv.cc @@ -3,7 +3,7 @@ Copyright (c) 1995, 2017, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, 2009 Google Inc. Copyright (c) 2009, Percona Inc. -Copyright (c) 2013, 2018, MariaDB Corporation. +Copyright (c) 2013, 2019, MariaDB Corporation. Portions of this file contain modifications contributed and copyrighted by Google, Inc. Those modifications are gratefully acknowledged and are described @@ -46,14 +46,11 @@ Created 10/8/1995 Heikki Tuuri // #include "mysql/psi/mysql_stage.h" // #include "mysql/psi/psi.h" -#include "ha_prototypes.h" - #include "btr0sea.h" #include "buf0flu.h" #include "buf0lru.h" #include "dict0boot.h" #include "dict0load.h" -#include "fsp0sysspace.h" #include "ibuf0ibuf.h" #include "lock0lock.h" #include "log0recv.h" @@ -79,10 +76,6 @@ Created 10/8/1995 Heikki Tuuri #include <my_service_manager.h> -#ifdef WITH_WSREP -extern int wsrep_debug; -extern int wsrep_trx_is_aborting(void *thd_ptr); -#endif /* The following is the maximum allowed duration of a lock wait. */ UNIV_INTERN ulong srv_fatal_semaphore_wait_threshold = DEFAULT_SRV_FATAL_SEMAPHORE_TIMEOUT; @@ -500,10 +493,6 @@ UNIV_INTERN ulong srv_buf_dump_status_frequency; mutex_enter(&srv_sys.mutex); \ } while (0) -/** Test if the system mutex is owned. */ -#define srv_sys_mutex_own() (mutex_own(&srv_sys.mutex) \ - && !srv_read_only_mode) - /** Release the system mutex. */ #define srv_sys_mutex_exit() do { \ mutex_exit(&srv_sys.mutex); \ @@ -599,11 +588,12 @@ struct srv_sys_t{ sys_threads[]->event are covered by srv_sys_t::mutex */ - ulint n_threads_active[SRV_MASTER + 1]; + Atomic_counter<ulint> + n_threads_active[SRV_MASTER + 1]; /*!< number of threads active in a thread class; protected - by both my_atomic_addlint() - and mutex */ + by both std::atomic and + mutex */ srv_stats_t::ulint_ctr_1_t activity_count; /*!< For tracking server @@ -615,7 +605,7 @@ static srv_sys_t srv_sys; /** @return whether the purge coordinator thread is active */ bool purge_sys_t::running() { - return my_atomic_loadlint(&srv_sys.n_threads_active[SRV_PURGE]); + return srv_sys.n_threads_active[SRV_PURGE]; } /** Event to signal srv_monitor_thread. Not protected by a mutex. @@ -814,7 +804,7 @@ srv_reserve_slot( ut_ad(srv_slot_get_type(slot) == type); - my_atomic_addlint(&srv_sys.n_threads_active[type], 1); + srv_sys.n_threads_active[type]++; srv_sys_mutex_exit(); @@ -831,7 +821,7 @@ srv_suspend_thread_low( srv_slot_t* slot) /*!< in/out: thread slot */ { ut_ad(!srv_read_only_mode); - ut_ad(srv_sys_mutex_own()); + ut_ad(mutex_own(&srv_sys.mutex)); ut_ad(slot->in_use); @@ -861,8 +851,7 @@ srv_suspend_thread_low( ut_a(!slot->suspended); slot->suspended = TRUE; - if (lint(my_atomic_addlint(&srv_sys.n_threads_active[type], ulint(-1))) - < 0) { + if (srv_sys.n_threads_active[type]-- == 0) { ut_error; } @@ -919,7 +908,7 @@ srv_resume_thread(srv_slot_t* slot, int64_t sig_count = 0, bool wait = true, ut_ad(slot->suspended); slot->suspended = FALSE; - my_atomic_addlint(&srv_sys.n_threads_active[slot->type], 1); + srv_sys.n_threads_active[slot->type]++; srv_sys_mutex_exit(); return(timeout); } @@ -1073,8 +1062,6 @@ srv_init() trx_i_s_cache_init(trx_i_s_cache); ut_crc32_init(); - - dict_mem_init(); } /*********************************************************************//** @@ -1332,7 +1319,7 @@ srv_printf_innodb_monitor( fprintf(file, "Total large memory allocated " ULINTPF "\n" "Dictionary memory allocated " ULINTPF "\n", - os_total_large_mem_allocated, + ulint{os_total_large_mem_allocated}, dict_sys_get_size()); buf_print_io(file); @@ -1581,7 +1568,7 @@ srv_export_innodb_status(void) export_vars.innodb_system_rows_deleted = srv_stats.n_system_rows_deleted; - export_vars.innodb_num_open_files = fil_n_file_opened; + export_vars.innodb_num_open_files = fil_system.n_open; export_vars.innodb_truncated_status_writes = srv_truncated_status_writes; @@ -1912,11 +1899,11 @@ void srv_active_wake_master_thread_low() { ut_ad(!srv_read_only_mode); - ut_ad(!srv_sys_mutex_own()); + ut_ad(!mutex_own(&srv_sys.mutex)); srv_inc_activity_count(); - if (my_atomic_loadlint(&srv_sys.n_threads_active[SRV_MASTER]) == 0) { + if (srv_sys.n_threads_active[SRV_MASTER] == 0) { srv_slot_t* slot; srv_sys_mutex_enter(); @@ -1938,11 +1925,12 @@ srv_active_wake_master_thread_low() void srv_wake_purge_thread_if_not_active() { - ut_ad(!srv_sys_mutex_own()); + ut_ad(!srv_read_only_mode); + ut_ad(!mutex_own(&srv_sys.mutex)); if (purge_sys.enabled() && !purge_sys.paused() - && !my_atomic_loadlint(&srv_sys.n_threads_active[SRV_PURGE]) - && trx_sys.history_size()) { + && !srv_sys.n_threads_active[SRV_PURGE] + && trx_sys.rseg_history_len) { srv_release_threads(SRV_PURGE, 1); } @@ -2415,7 +2403,8 @@ static bool srv_purge_should_exit() return(true); } /* Slow shutdown was requested. */ - if (ulint history_size = trx_sys.history_size()) { + uint32_t history_size = trx_sys.rseg_history_len; + if (history_size) { #if defined HAVE_SYSTEMD && !defined EMBEDDED_LIBRARY static ib_time_t progress_time; ib_time_t time = ut_time(); @@ -2423,7 +2412,7 @@ static bool srv_purge_should_exit() progress_time = time; service_manager_extend_timeout( INNODB_EXTEND_TIMEOUT_INTERVAL, - "InnoDB: to purge " ULINTPF " transactions", + "InnoDB: to purge %u transactions", history_size); } #endif @@ -2448,7 +2437,7 @@ static bool srv_task_execute() UT_LIST_REMOVE(srv_sys.tasks, thr); mutex_exit(&srv_sys.tasks_mutex); que_run_threads(thr); - my_atomic_addlint(&purge_sys.n_completed, 1); + purge_sys.n_tasks.fetch_sub(1, std::memory_order_release); return true; } @@ -2484,7 +2473,7 @@ DECLARE_THREAD(srv_worker_thread)( slot = srv_reserve_slot(SRV_WORKER); ut_a(srv_n_purge_threads > 1); - ut_a(ulong(my_atomic_loadlint(&srv_sys.n_threads_active[SRV_WORKER])) + ut_a(ulong(srv_sys.n_threads_active[SRV_WORKER]) < srv_n_purge_threads); /* We need to ensure that the worker threads exit after the @@ -2526,14 +2515,14 @@ DECLARE_THREAD(srv_worker_thread)( @param[in,out] n_total_purged total number of purged pages @return length of history list before the last purge batch. */ static -ulint +uint32_t srv_do_purge(ulint* n_total_purged) { ulint n_pages_purged; static ulint count = 0; static ulint n_use_threads = 0; - static ulint rseg_history_len = 0; + static uint32_t rseg_history_len = 0; ulint old_activity_count = srv_get_activity_count(); const ulint n_threads = srv_n_purge_threads; @@ -2551,7 +2540,7 @@ srv_do_purge(ulint* n_total_purged) } do { - if (trx_sys.history_size() > rseg_history_len + if (trx_sys.rseg_history_len > rseg_history_len || (srv_max_purge_lag > 0 && rseg_history_len > srv_max_purge_lag)) { @@ -2580,7 +2569,7 @@ srv_do_purge(ulint* n_total_purged) ut_a(n_use_threads <= n_threads); /* Take a snapshot of the history list before purge. */ - if (!(rseg_history_len = trx_sys.history_size())) { + if (!(rseg_history_len = trx_sys.rseg_history_len)) { break; } @@ -2604,7 +2593,7 @@ srv_purge_coordinator_suspend( /*==========================*/ srv_slot_t* slot, /*!< in/out: Purge coordinator thread slot */ - ulint rseg_history_len) /*!< in: history list length + uint32_t rseg_history_len) /*!< in: history list length before last purge */ { ut_ad(!srv_read_only_mode); @@ -2621,7 +2610,7 @@ srv_purge_coordinator_suspend( /* We don't wait right away on the the non-timed wait because we want to signal the thread that wants to suspend purge. */ const bool wait = stop - || rseg_history_len <= trx_sys.history_size(); + || rseg_history_len <= trx_sys.rseg_history_len; const bool timeout = srv_resume_thread( slot, sig_count, wait, stop ? 0 : SRV_PURGE_MAX_TIMEOUT); @@ -2631,12 +2620,12 @@ srv_purge_coordinator_suspend( rw_lock_x_lock(&purge_sys.latch); stop = srv_shutdown_state == SRV_SHUTDOWN_NONE - && purge_sys.paused_latched(); + && purge_sys.paused(); if (!stop) { if (timeout && rseg_history_len < 5000 - && rseg_history_len == trx_sys.history_size()) { + && rseg_history_len == trx_sys.rseg_history_len) { /* No new records were added since the wait started. Simply wait for new records. The magic number 5000 is an @@ -2689,7 +2678,7 @@ DECLARE_THREAD(srv_purge_coordinator_thread)( slot = srv_reserve_slot(SRV_PURGE); - ulint rseg_history_len = trx_sys.history_size(); + uint32_t rseg_history_len = trx_sys.rseg_history_len; do { /* If there are no records to purge or the last @@ -2813,9 +2802,7 @@ srv_purge_wakeup() srv_release_threads(SRV_WORKER, n_workers); } - } while (!my_atomic_loadptr_explicit(reinterpret_cast<void**> - (&srv_running), - MY_MEMORY_ORDER_RELAXED) + } while (!srv_running.load(std::memory_order_relaxed) && (srv_sys.n_threads_active[SRV_WORKER] || srv_sys.n_threads_active[SRV_PURGE])); } |