-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
MDEV-15111 - fix simple InnoDB data race #582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -305,7 +305,7 @@ is_partition( | |
|
|
||
| /** Signal to shut down InnoDB (NULL if shutdown was signaled, or if | ||
| running in innodb_read_only mode, srv_read_only_mode) */ | ||
| volatile st_my_thread_var *srv_running; | ||
| st_my_thread_var *srv_running; | ||
| /** Service thread that waits for the server shutdown and stops purge threads. | ||
| Purge workers have THDs that are needed to calculate virtual columns. | ||
| This THDs must be destroyed rather early in the server shutdown sequence. | ||
|
|
@@ -332,12 +332,16 @@ thd_destructor_proxy(void *) | |
| myvar->current_cond = &thd_destructor_cond; | ||
|
|
||
| mysql_mutex_lock(&thd_destructor_mutex); | ||
| srv_running = myvar; | ||
| my_atomic_storeptr_explicit(&srv_running, myvar, | ||
| MY_MEMORY_ORDER_RELAXED); | ||
| /* wait until the server wakes the THD to abort and die */ | ||
| while (!srv_running->abort) | ||
| while (!my_atomic_loadptr_explicit(&srv_running, | ||
| MY_MEMORY_ORDER_RELAXED) | ||
| ->abort) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reverted this atomic load: no other thread can update |
||
| mysql_cond_wait(&thd_destructor_cond, &thd_destructor_mutex); | ||
| mysql_mutex_unlock(&thd_destructor_mutex); | ||
| srv_running = NULL; | ||
| my_atomic_storeptr_explicit(&srv_running, NULL, | ||
| MY_MEMORY_ORDER_RELAXED); | ||
|
|
||
| while (srv_fast_shutdown == 0 && | ||
| (trx_sys_any_active_transactions() || | ||
|
|
@@ -4333,7 +4337,8 @@ innobase_init( | |
| mysql_thread_create(thd_destructor_thread_key, | ||
| &thd_destructor_thread, | ||
| NULL, thd_destructor_proxy, NULL); | ||
| while (!srv_running) | ||
| while (!my_atomic_loadptr_explicit(&srv_running, | ||
| MY_MEMORY_ORDER_RELAXED)) | ||
| os_thread_sleep(20); | ||
| } | ||
|
|
||
|
|
@@ -4427,10 +4432,12 @@ innobase_end(handlerton*, ha_panic_function) | |
| hash_table_free(innobase_open_tables); | ||
| innobase_open_tables = NULL; | ||
|
|
||
| if (!abort_loop && srv_running) { | ||
| st_my_thread_var* running = my_atomic_loadptr_explicit( | ||
| &srv_running, MY_MEMORY_ORDER_RELAXED); | ||
| if (!abort_loop && running) { | ||
| // may be UNINSTALL PLUGIN statement | ||
| srv_running->abort = 1; | ||
| mysql_cond_broadcast(srv_running->current_cond); | ||
| running->abort = 1; | ||
| mysql_cond_broadcast(running->current_cond); | ||
| } | ||
|
|
||
| if (!srv_read_only_mode) { | ||
|
|
@@ -17764,7 +17771,9 @@ fast_shutdown_validate( | |
|
|
||
| uint new_val = *reinterpret_cast<uint*>(save); | ||
|
|
||
| if (srv_fast_shutdown && !new_val && !srv_running) { | ||
| if (srv_fast_shutdown && !new_val | ||
| && !my_atomic_loadptr_explicit(&srv_running, | ||
| MY_MEMORY_ORDER_RELAXED)) { | ||
| return(1); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -527,7 +527,8 @@ struct TTASEventMutex { | |
| int32 state() const | ||
| UNIV_NOTHROW | ||
| { | ||
| return(m_lock_word); | ||
| return(my_atomic_load32_explicit(&m_lock_word, | ||
| MY_MEMORY_ORDER_RELAXED)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine, thanks! |
||
| } | ||
|
|
||
| /** The event that the mutex will wait in sync0arr.cc | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1170,7 +1170,16 @@ srv_refresh_innodb_monitor_stats(void) | |
| { | ||
| mutex_enter(&srv_innodb_monitor_mutex); | ||
|
|
||
| srv_last_monitor_time = time(NULL); | ||
| time_t current_time = time(NULL); | ||
|
|
||
| if (difftime(current_time, srv_last_monitor_time) > 60) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I inverted this condition, so that original meaning retained. |
||
| /* We referesh InnoDB Monitor values so that averages are | ||
| printed from at most 60 last seconds */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to unlock mutex here, right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Sorry once more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I will go through this patch once again soon. So far looks good. |
||
| mutex_exit(&srv_innodb_monitor_mutex); | ||
| return; | ||
| } | ||
|
|
||
| srv_last_monitor_time = current_time; | ||
|
|
||
| os_aio_refresh_stats(); | ||
|
|
||
|
|
@@ -1792,6 +1801,8 @@ DECLARE_THREAD(srv_monitor_thread)(void*) | |
| } | ||
| } | ||
|
|
||
| srv_refresh_innodb_monitor_stats(); | ||
|
|
||
| if (srv_shutdown_state != SRV_SHUTDOWN_NONE) { | ||
| goto exit_func; | ||
| } | ||
|
|
@@ -1863,13 +1874,6 @@ DECLARE_THREAD(srv_error_monitor_thread)(void*) | |
| old_lsn = new_lsn; | ||
| } | ||
|
|
||
| if (difftime(time(NULL), srv_last_monitor_time) > 60) { | ||
| /* We referesh InnoDB Monitor values so that averages are | ||
| printed from at most 60 last seconds */ | ||
|
|
||
| srv_refresh_innodb_monitor_stats(); | ||
| } | ||
|
|
||
| /* Update the statistics collected for deciding LRU | ||
| eviction policy. */ | ||
| buf_LRU_stat_update(); | ||
|
|
@@ -2938,7 +2942,8 @@ srv_purge_wakeup() | |
|
|
||
| srv_release_threads(SRV_WORKER, n_workers); | ||
| } | ||
| } while (!srv_running | ||
| } while (!my_atomic_loadptr_explicit(&srv_running, | ||
| MY_MEMORY_ORDER_RELAXED) | ||
| && (srv_sys.n_threads_active[SRV_WORKER] | ||
| || srv_sys.n_threads_active[SRV_PURGE])); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of alright, but FWICS it is just a half of the fix. Though probably it is acceptable.
A few lines below there's second assignment
srv_running = NULL. As well as two loads insrv0start.ccandsrv0srv.ccthat are most probably affected by data race as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made all accesses atomical.