Commit a39d92ca authored by Sergey Vojtovich's avatar Sergey Vojtovich

gtid_pos_table: my_atomic to std::atomic

parent 4d9977e5
...@@ -257,7 +257,7 @@ rpl_slave_state::rpl_slave_state() ...@@ -257,7 +257,7 @@ rpl_slave_state::rpl_slave_state()
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(); truncate_hash();
my_hash_free(&hash); my_hash_free(&hash);
delete_dynamic(&gtid_sort_array); delete_dynamic(&gtid_sort_array);
...@@ -497,21 +497,18 @@ gtid_check_rpl_slave_state_table(TABLE *table) ...@@ -497,21 +497,18 @@ gtid_check_rpl_slave_state_table(TABLE *table)
void void
rpl_slave_state::select_gtid_pos_table(THD *thd, LEX_CSTRING *out_tablename) 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 See comments on rpl_slave_state::gtid_pos_tables for rules around proper
access to the list. access to the list.
*/ */
list= (struct gtid_pos_table *) auto list= gtid_pos_tables.load(std::memory_order_acquire);
my_atomic_loadptr_explicit(&gtid_pos_tables, MY_MEMORY_ORDER_ACQUIRE);
Ha_trx_info *ha_info; Ha_trx_info *ha_info;
uint count = 0; uint count = 0;
for (ha_info= thd->transaction.all.ha_list; ha_info; ha_info= ha_info->next()) for (ha_info= thd->transaction.all.ha_list; ha_info; ha_info= ha_info->next())
{ {
void *trx_hton= ha_info->ht(); void *trx_hton= ha_info->ht();
table_entry= list; auto table_entry= list;
if (!ha_info->is_trx_read_write() || trx_hton == binlog_hton) if (!ha_info->is_trx_read_write() || trx_hton == binlog_hton)
continue; continue;
...@@ -820,14 +817,11 @@ rpl_slave_state::gtid_grab_pending_delete_list() ...@@ -820,14 +817,11 @@ rpl_slave_state::gtid_grab_pending_delete_list()
LEX_CSTRING * LEX_CSTRING *
rpl_slave_state::select_gtid_pos_table(void *hton) 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 See comments on rpl_slave_state::gtid_pos_tables for rules around proper
access to the list. access to the list.
*/ */
table_entry= (struct gtid_pos_table *) auto table_entry= gtid_pos_tables.load(std::memory_order_acquire);
my_atomic_loadptr_explicit(&gtid_pos_tables, MY_MEMORY_ORDER_ACQUIRE);
while (table_entry) while (table_entry)
{ {
...@@ -1437,11 +1431,9 @@ void ...@@ -1437,11 +1431,9 @@ void
rpl_slave_state::set_gtid_pos_tables_list(rpl_slave_state::gtid_pos_table *new_list, rpl_slave_state::set_gtid_pos_tables_list(rpl_slave_state::gtid_pos_table *new_list,
rpl_slave_state::gtid_pos_table *default_entry) rpl_slave_state::gtid_pos_table *default_entry)
{ {
gtid_pos_table *old_list;
mysql_mutex_assert_owner(&LOCK_slave_state); mysql_mutex_assert_owner(&LOCK_slave_state);
old_list= (struct gtid_pos_table *)gtid_pos_tables; auto old_list= gtid_pos_tables.load(std::memory_order_relaxed);
my_atomic_storeptr_explicit(&gtid_pos_tables, new_list, MY_MEMORY_ORDER_RELEASE); gtid_pos_tables.store(new_list, std::memory_order_release);
default_gtid_pos_table.store(default_entry, std::memory_order_release); default_gtid_pos_table.store(default_entry, std::memory_order_release);
free_gtid_pos_tables(old_list); free_gtid_pos_tables(old_list);
} }
...@@ -1451,8 +1443,8 @@ void ...@@ -1451,8 +1443,8 @@ void
rpl_slave_state::add_gtid_pos_table(rpl_slave_state::gtid_pos_table *entry) rpl_slave_state::add_gtid_pos_table(rpl_slave_state::gtid_pos_table *entry)
{ {
mysql_mutex_assert_owner(&LOCK_slave_state); mysql_mutex_assert_owner(&LOCK_slave_state);
entry->next= (struct gtid_pos_table *)gtid_pos_tables; entry->next= gtid_pos_tables.load(std::memory_order_relaxed);
my_atomic_storeptr_explicit(&gtid_pos_tables, entry, MY_MEMORY_ORDER_RELEASE); gtid_pos_tables.store(entry, std::memory_order_release);
} }
......
...@@ -217,11 +217,8 @@ struct rpl_slave_state ...@@ -217,11 +217,8 @@ struct rpl_slave_state
The list can be read without lock by an SQL driver thread or worker thread 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, 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. 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. */ /* The default entry in gtid_pos_tables, mysql.gtid_slave_pos. */
std::atomic<gtid_pos_table*> default_gtid_pos_table; std::atomic<gtid_pos_table*> default_gtid_pos_table;
bool loaded; bool loaded;
......
...@@ -2019,10 +2019,9 @@ find_gtid_slave_pos_tables(THD *thd) ...@@ -2019,10 +2019,9 @@ find_gtid_slave_pos_tables(THD *thd)
However we can add new entries, and warn about any tables that However we can add new entries, and warn about any tables that
disappeared, but may still be visible to running SQL threads. disappeared, but may still be visible to running SQL threads.
*/ */
rpl_slave_state::gtid_pos_table *old_entry, *new_entry, **next_ptr_ptr; rpl_slave_state::gtid_pos_table *new_entry, **next_ptr_ptr;
auto old_entry= rpl_global_gtid_slave_state->
old_entry= (rpl_slave_state::gtid_pos_table *) gtid_pos_tables.load(std::memory_order_relaxed);
rpl_global_gtid_slave_state->gtid_pos_tables;
while (old_entry) while (old_entry)
{ {
new_entry= cb_data.table_list; new_entry= cb_data.table_list;
...@@ -2044,8 +2043,8 @@ find_gtid_slave_pos_tables(THD *thd) ...@@ -2044,8 +2043,8 @@ find_gtid_slave_pos_tables(THD *thd)
while (new_entry) while (new_entry)
{ {
/* Check if we already have a table with this storage engine. */ /* Check if we already have a table with this storage engine. */
old_entry= (rpl_slave_state::gtid_pos_table *) old_entry= rpl_global_gtid_slave_state->
rpl_global_gtid_slave_state->gtid_pos_tables; gtid_pos_tables.load(std::memory_order_relaxed);
while (old_entry) while (old_entry)
{ {
if (new_entry->table_hton == old_entry->table_hton) if (new_entry->table_hton == old_entry->table_hton)
......
...@@ -397,8 +397,8 @@ handle_gtid_pos_auto_create_request(THD *thd, void *hton) ...@@ -397,8 +397,8 @@ handle_gtid_pos_auto_create_request(THD *thd, void *hton)
/* Find the entry for the table to auto-create. */ /* Find the entry for the table to auto-create. */
mysql_mutex_lock(&rpl_global_gtid_slave_state->LOCK_slave_state); mysql_mutex_lock(&rpl_global_gtid_slave_state->LOCK_slave_state);
entry= (rpl_slave_state::gtid_pos_table *) entry= rpl_global_gtid_slave_state->
rpl_global_gtid_slave_state->gtid_pos_tables; gtid_pos_tables.load(std::memory_order_relaxed);
while (entry) while (entry)
{ {
if (entry->table_hton == hton && if (entry->table_hton == hton &&
...@@ -434,8 +434,8 @@ handle_gtid_pos_auto_create_request(THD *thd, void *hton) ...@@ -434,8 +434,8 @@ handle_gtid_pos_auto_create_request(THD *thd, void *hton)
/* Now enable the entry for the auto-created table. */ /* Now enable the entry for the auto-created table. */
mysql_mutex_lock(&rpl_global_gtid_slave_state->LOCK_slave_state); mysql_mutex_lock(&rpl_global_gtid_slave_state->LOCK_slave_state);
entry= (rpl_slave_state::gtid_pos_table *) entry= rpl_global_gtid_slave_state->
rpl_global_gtid_slave_state->gtid_pos_tables; gtid_pos_tables.load(std::memory_order_relaxed);
while (entry) while (entry)
{ {
if (entry->table_hton == hton && if (entry->table_hton == hton &&
......
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