diff options
-rw-r--r-- | sql/rpl_gtid.cc | 24 | ||||
-rw-r--r-- | sql/rpl_gtid.h | 5 | ||||
-rw-r--r-- | sql/rpl_rli.cc | 11 | ||||
-rw-r--r-- | sql/slave.cc | 8 |
4 files changed, 18 insertions, 30 deletions
diff --git a/sql/rpl_gtid.cc b/sql/rpl_gtid.cc index 8f9fdcaffde..f58df09623c 100644 --- a/sql/rpl_gtid.cc +++ b/sql/rpl_gtid.cc @@ -257,7 +257,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); @@ -497,21 +497,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; - /* 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; @@ -820,14 +817,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) { @@ -1437,11 +1431,9 @@ 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); + 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); } @@ -1451,8 +1443,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 a795290d780..b633716bfe5 100644 --- a/sql/rpl_gtid.h +++ b/sql/rpl_gtid.h @@ -217,11 +217,8 @@ 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. */ std::atomic<gtid_pos_table*> default_gtid_pos_table; bool loaded; diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index d645fea6968..18ee6a98ed0 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -2019,10 +2019,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; @@ -2044,8 +2043,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 714e47424fe..fcb4777b189 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -397,8 +397,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 && @@ -434,8 +434,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 && |