diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2020-03-23 10:50:14 +0200 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2020-03-23 10:50:14 +0200 |
commit | 3b250837858c137f3a4082af6c0a20f95fde31d4 (patch) | |
tree | 9224188f329bb77443e9eb35680f91039e51adaf /sql | |
parent | 1a4998e98271ffd8126331336c4c4ae71029afc7 (diff) | |
parent | f7599f47999bb197dba36e54d0d5677b3b15f12a (diff) | |
download | mariadb-git-3b250837858c137f3a4082af6c0a20f95fde31d4.tar.gz |
Merge 10.4 into 10.5
Diffstat (limited to 'sql')
-rw-r--r-- | sql/handler.cc | 12 | ||||
-rw-r--r-- | sql/mysqld.cc | 4 | ||||
-rw-r--r-- | sql/mysqld.h | 7 | ||||
-rw-r--r-- | sql/rpl_gtid.cc | 36 | ||||
-rw-r--r-- | sql/rpl_gtid.h | 9 | ||||
-rw-r--r-- | sql/rpl_rli.cc | 11 | ||||
-rw-r--r-- | sql/slave.cc | 8 | ||||
-rw-r--r-- | sql/table_cache.cc | 34 | ||||
-rw-r--r-- | sql/table_cache.h | 3 |
9 files changed, 58 insertions, 66 deletions
diff --git a/sql/handler.cc b/sql/handler.cc index d43a9a0aaa0..eb7b5b82c34 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -474,9 +474,9 @@ static int ha_finish_errors(void) return 0; } -static volatile int32 need_full_discover_for_existence= 0; -static volatile int32 engines_with_discover_file_names= 0; -static volatile int32 engines_with_discover= 0; +static Atomic_counter<int32> need_full_discover_for_existence(0); +static Atomic_counter<int32> engines_with_discover_file_names(0); +static Atomic_counter<int32> engines_with_discover(0); static int full_discover_for_existence(handlerton *, const char *, const char *) { return 0; } @@ -498,13 +498,13 @@ static int hton_ext_based_table_discovery(handlerton *hton, LEX_CSTRING *db, static void update_discovery_counters(handlerton *hton, int val) { if (hton->discover_table_existence == full_discover_for_existence) - my_atomic_add32(&need_full_discover_for_existence, val); + need_full_discover_for_existence+= val; if (hton->discover_table_names && hton->tablefile_extensions[0]) - my_atomic_add32(&engines_with_discover_file_names, val); + engines_with_discover_file_names+= val; if (hton->discover_table) - my_atomic_add32(&engines_with_discover, val); + engines_with_discover+= val; } int ha_finalize_handlerton(st_plugin_int *plugin) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 387482ef6f0..e2fff60db3b 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -479,7 +479,7 @@ ulonglong test_flags; ulonglong query_cache_size=0; ulong query_cache_limit=0; ulong executed_events=0; -query_id_t global_query_id; +Atomic_counter<query_id_t> global_query_id; ulong aborted_threads, aborted_connects, aborted_connects_preauth; ulong delayed_insert_timeout, delayed_insert_limit, delayed_queue_size; ulong delayed_insert_threads, delayed_insert_writes, delayed_rows_in_use; @@ -7631,7 +7631,7 @@ SHOW_VAR status_vars[]= { {"Subquery_cache_miss", (char*) &subquery_cache_miss, SHOW_LONG}, {"Table_locks_immediate", (char*) &locks_immediate, SHOW_LONG}, {"Table_locks_waited", (char*) &locks_waited, SHOW_LONG}, - {"Table_open_cache_active_instances", (char*) &tc_active_instances, SHOW_UINT}, + {"Table_open_cache_active_instances", (char*) &show_tc_active_instances, SHOW_SIMPLE_FUNC}, {"Table_open_cache_hits", (char*) offsetof(STATUS_VAR, table_open_cache_hits), SHOW_LONGLONG_STATUS}, {"Table_open_cache_misses", (char*) offsetof(STATUS_VAR, table_open_cache_misses), SHOW_LONGLONG_STATUS}, {"Table_open_cache_overflows", (char*) offsetof(STATUS_VAR, table_open_cache_overflows), SHOW_LONGLONG_STATUS}, diff --git a/sql/mysqld.h b/sql/mysqld.h index 018c8cdcaf5..fc14c587403 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -23,7 +23,6 @@ #include "sql_bitmap.h" /* Bitmap */ #include "my_decimal.h" /* my_decimal */ #include "mysql_com.h" /* SERVER_VERSION_LENGTH */ -#include "my_atomic.h" #include "my_counter.h" #include "mysql/psi/mysql_file.h" /* MYSQL_FILE */ #include "mysql/psi/mysql_socket.h" /* MYSQL_SOCKET */ @@ -892,17 +891,17 @@ enum enum_query_type /* query_id */ -extern query_id_t global_query_id; +extern Atomic_counter<query_id_t> global_query_id; /* increment query_id and return it. */ inline __attribute__((warn_unused_result)) query_id_t next_query_id() { - return my_atomic_add64_explicit(&global_query_id, 1, MY_MEMORY_ORDER_RELAXED); + return global_query_id++; } inline query_id_t get_query_id() { - return my_atomic_load64_explicit(&global_query_id, MY_MEMORY_ORDER_RELAXED); + return global_query_id; } /* increment global_thread_id and return it. */ diff --git a/sql/rpl_gtid.cc b/sql/rpl_gtid.cc index e7ad4c02a19..94c36dfcb20 100644 --- a/sql/rpl_gtid.cc +++ b/sql/rpl_gtid.cc @@ -258,7 +258,7 @@ rpl_slave_state::rpl_slave_state() rpl_slave_state::~rpl_slave_state() { - free_gtid_pos_tables((struct gtid_pos_table *)gtid_pos_tables); + free_gtid_pos_tables(gtid_pos_tables.load(std::memory_order_relaxed)); truncate_hash(); my_hash_free(&hash); delete_dynamic(>id_sort_array); @@ -499,21 +499,18 @@ gtid_check_rpl_slave_state_table(TABLE *table) void rpl_slave_state::select_gtid_pos_table(THD *thd, LEX_CSTRING *out_tablename) { - struct gtid_pos_table *list, *table_entry, *default_entry; - /* See comments on rpl_slave_state::gtid_pos_tables for rules around proper access to the list. */ - list= (struct gtid_pos_table *) - my_atomic_loadptr_explicit(>id_pos_tables, MY_MEMORY_ORDER_ACQUIRE); + auto list= gtid_pos_tables.load(std::memory_order_acquire); Ha_trx_info *ha_info; uint count = 0; for (ha_info= thd->transaction.all.ha_list; ha_info; ha_info= ha_info->next()) { void *trx_hton= ha_info->ht(); - table_entry= list; + auto table_entry= list; if (!ha_info->is_trx_read_write() || trx_hton == binlog_hton) continue; @@ -567,9 +564,8 @@ rpl_slave_state::select_gtid_pos_table(THD *thd, LEX_CSTRING *out_tablename) already active in the transaction, or if there is no current transaction engines available, we return the default gtid_slave_pos table. */ - default_entry= (struct gtid_pos_table *) - my_atomic_loadptr_explicit(&default_gtid_pos_table, MY_MEMORY_ORDER_ACQUIRE); - *out_tablename= default_entry->table_name; + *out_tablename= + default_gtid_pos_table.load(std::memory_order_acquire)->table_name; /* Record in status that we failed to find a suitable gtid_pos table. */ if (count > 0) { @@ -823,14 +819,11 @@ rpl_slave_state::gtid_grab_pending_delete_list() LEX_CSTRING * rpl_slave_state::select_gtid_pos_table(void *hton) { - struct gtid_pos_table *table_entry; - /* See comments on rpl_slave_state::gtid_pos_tables for rules around proper access to the list. */ - table_entry= (struct gtid_pos_table *) - my_atomic_loadptr_explicit(>id_pos_tables, MY_MEMORY_ORDER_ACQUIRE); + auto table_entry= gtid_pos_tables.load(std::memory_order_acquire); while (table_entry) { @@ -842,9 +835,7 @@ rpl_slave_state::select_gtid_pos_table(void *hton) table_entry= table_entry->next; } - table_entry= (struct gtid_pos_table *) - my_atomic_loadptr_explicit(&default_gtid_pos_table, MY_MEMORY_ORDER_ACQUIRE); - return &table_entry->table_name; + return &default_gtid_pos_table.load(std::memory_order_acquire)->table_name; } @@ -1443,13 +1434,10 @@ void rpl_slave_state::set_gtid_pos_tables_list(rpl_slave_state::gtid_pos_table *new_list, rpl_slave_state::gtid_pos_table *default_entry) { - gtid_pos_table *old_list; - mysql_mutex_assert_owner(&LOCK_slave_state); - old_list= (struct gtid_pos_table *)gtid_pos_tables; - my_atomic_storeptr_explicit(>id_pos_tables, new_list, MY_MEMORY_ORDER_RELEASE); - my_atomic_storeptr_explicit(&default_gtid_pos_table, default_entry, - MY_MEMORY_ORDER_RELEASE); + auto old_list= gtid_pos_tables.load(std::memory_order_relaxed); + gtid_pos_tables.store(new_list, std::memory_order_release); + default_gtid_pos_table.store(default_entry, std::memory_order_release); free_gtid_pos_tables(old_list); } @@ -1458,8 +1446,8 @@ void rpl_slave_state::add_gtid_pos_table(rpl_slave_state::gtid_pos_table *entry) { mysql_mutex_assert_owner(&LOCK_slave_state); - entry->next= (struct gtid_pos_table *)gtid_pos_tables; - my_atomic_storeptr_explicit(>id_pos_tables, entry, MY_MEMORY_ORDER_RELEASE); + entry->next= gtid_pos_tables.load(std::memory_order_relaxed); + gtid_pos_tables.store(entry, std::memory_order_release); } diff --git a/sql/rpl_gtid.h b/sql/rpl_gtid.h index 523af4856ae..11541c8000c 100644 --- a/sql/rpl_gtid.h +++ b/sql/rpl_gtid.h @@ -18,7 +18,7 @@ #include "hash.h" #include "queues.h" - +#include <atomic> /* Definitions for MariaDB global transaction ID (GTID). */ @@ -219,13 +219,10 @@ struct rpl_slave_state The list can be read without lock by an SQL driver thread or worker thread by reading the gtid_pos_tables pointer atomically with acquire semantics, to ensure that it will see the correct next pointer of a new head element. - - The type is struct gtid_pos_table *, but needs to be void * to allow using - my_atomic operations without violating C strict aliasing semantics. */ - void * volatile gtid_pos_tables; + std::atomic<gtid_pos_table*> gtid_pos_tables; /* The default entry in gtid_pos_tables, mysql.gtid_slave_pos. */ - void * volatile default_gtid_pos_table; + std::atomic<gtid_pos_table*> default_gtid_pos_table; bool loaded; rpl_slave_state(); diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index c8914fcb5b0..8225f774f7b 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -2023,10 +2023,9 @@ find_gtid_slave_pos_tables(THD *thd) However we can add new entries, and warn about any tables that disappeared, but may still be visible to running SQL threads. */ - rpl_slave_state::gtid_pos_table *old_entry, *new_entry, **next_ptr_ptr; - - old_entry= (rpl_slave_state::gtid_pos_table *) - rpl_global_gtid_slave_state->gtid_pos_tables; + rpl_slave_state::gtid_pos_table *new_entry, **next_ptr_ptr; + auto old_entry= rpl_global_gtid_slave_state-> + gtid_pos_tables.load(std::memory_order_relaxed); while (old_entry) { new_entry= cb_data.table_list; @@ -2048,8 +2047,8 @@ find_gtid_slave_pos_tables(THD *thd) while (new_entry) { /* Check if we already have a table with this storage engine. */ - old_entry= (rpl_slave_state::gtid_pos_table *) - rpl_global_gtid_slave_state->gtid_pos_tables; + old_entry= rpl_global_gtid_slave_state-> + gtid_pos_tables.load(std::memory_order_relaxed); while (old_entry) { if (new_entry->table_hton == old_entry->table_hton) diff --git a/sql/slave.cc b/sql/slave.cc index e9af0f75186..b6cfd2deef4 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -399,8 +399,8 @@ handle_gtid_pos_auto_create_request(THD *thd, void *hton) /* Find the entry for the table to auto-create. */ mysql_mutex_lock(&rpl_global_gtid_slave_state->LOCK_slave_state); - entry= (rpl_slave_state::gtid_pos_table *) - rpl_global_gtid_slave_state->gtid_pos_tables; + entry= rpl_global_gtid_slave_state-> + gtid_pos_tables.load(std::memory_order_relaxed); while (entry) { if (entry->table_hton == hton && @@ -436,8 +436,8 @@ handle_gtid_pos_auto_create_request(THD *thd, void *hton) /* Now enable the entry for the auto-created table. */ mysql_mutex_lock(&rpl_global_gtid_slave_state->LOCK_slave_state); - entry= (rpl_slave_state::gtid_pos_table *) - rpl_global_gtid_slave_state->gtid_pos_tables; + entry= rpl_global_gtid_slave_state-> + gtid_pos_tables.load(std::memory_order_relaxed); while (entry) { if (entry->table_hton == hton && diff --git a/sql/table_cache.cc b/sql/table_cache.cc index d8786f72244..ec5fd0ca0c7 100644 --- a/sql/table_cache.cc +++ b/sql/table_cache.cc @@ -56,7 +56,7 @@ ulong tdc_size; /**< Table definition cache threshold for LRU eviction. */ ulong tc_size; /**< Table cache threshold for LRU eviction. */ uint32 tc_instances; -uint32 tc_active_instances= 1; +static std::atomic<uint32_t> tc_active_instances(1); static std::atomic<bool> tc_contention_warning_reported; /** Data collections. */ @@ -162,7 +162,7 @@ struct Table_cache_instance overhead on TABLE object release. All other table cache mutex acquistions are considered out of hot path and are not instrumented either. */ - void lock_and_check_contention(uint32 n_instances, uint32 instance) + void lock_and_check_contention(uint32_t n_instances, uint32_t instance) { if (mysql_mutex_trylock(&LOCK_table_cache)) { @@ -171,11 +171,10 @@ struct Table_cache_instance { if (n_instances < tc_instances) { - if (my_atomic_cas32_weak_explicit((int32*) &tc_active_instances, - (int32*) &n_instances, - (int32) n_instances + 1, - MY_MEMORY_ORDER_RELAXED, - MY_MEMORY_ORDER_RELAXED)) + if (tc_active_instances. + compare_exchange_weak(n_instances, n_instances + 1, + std::memory_order_relaxed, + std::memory_order_relaxed)) { sql_print_information("Detected table cache mutex contention at instance %d: " "%d%% waits. Additional table cache instance " @@ -353,8 +352,8 @@ void tc_purge() void tc_add_table(THD *thd, TABLE *table) { - uint32 i= thd->thread_id % my_atomic_load32_explicit((int32*) &tc_active_instances, - MY_MEMORY_ORDER_RELAXED); + uint32_t i= + thd->thread_id % tc_active_instances.load(std::memory_order_relaxed); TABLE *LRU_table= 0; TDC_element *element= table->s->tdc; @@ -407,10 +406,8 @@ void tc_add_table(THD *thd, TABLE *table) TABLE *tc_acquire_table(THD *thd, TDC_element *element) { - uint32 n_instances= - my_atomic_load32_explicit((int32*) &tc_active_instances, - MY_MEMORY_ORDER_RELAXED); - uint32 i= thd->thread_id % n_instances; + uint32_t n_instances= tc_active_instances.load(std::memory_order_relaxed); + uint32_t i= thd->thread_id % n_instances; TABLE *table; tc[i].lock_and_check_contention(n_instances, i); @@ -1279,3 +1276,14 @@ int tdc_iterate(THD *thd, my_hash_walk_action action, void *argument, } return res; } + + +int show_tc_active_instances(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope) +{ + var->type= SHOW_UINT; + var->value= buff; + *(reinterpret_cast<uint32_t*>(buff))= + tc_active_instances.load(std::memory_order_relaxed); + return 0; +} diff --git a/sql/table_cache.h b/sql/table_cache.h index f971c377992..37faab87f0c 100644 --- a/sql/table_cache.h +++ b/sql/table_cache.h @@ -68,7 +68,6 @@ enum enum_tdc_remove_table_type extern ulong tdc_size; extern ulong tc_size; extern uint32 tc_instances; -extern uint32 tc_active_instances; extern bool tdc_init(void); extern void tdc_start_shutdown(void); @@ -91,6 +90,8 @@ extern int tdc_iterate(THD *thd, my_hash_walk_action action, void *argument, bool no_dups= false); extern uint tc_records(void); +int show_tc_active_instances(THD *thd, SHOW_VAR *var, char *buff, + enum enum_var_type scope); extern void tc_purge(); extern void tc_add_table(THD *thd, TABLE *table); extern void tc_release_table(TABLE *table); |