Commit graph

116 commits

Author SHA1 Message Date
Marko Mäkelä
c7920fa8ff MDEV-16264: Eliminate unsafe os_aio_userdata_t type cast 2020-03-12 19:43:45 +02:00
Vicențiu Ciorbaru
efa9079fbd Fix compilation error due to type mismatch in tpool_generic.cc
size_t compared to int
2020-02-13 13:42:01 +02:00
Marko Mäkelä
8b97eba31b MDEV-21674 purge_sys.stop() fails to wait for purge workers to complete
Since commit 5e62b6a5e0 (MDEV-16264),
purge_sys_t::stop() no longer waited for all purge activity to stop.

This caused problems on FLUSH TABLES...FOR EXPORT because of
purge running concurrently with the buffer pool flush.
The assertion at the end of buf_flush_dirty_pages() could fail.

The, implemented by Vladislav Vaintroub, aims to eliminate race
conditions when stopping or resuming purge:

waitable_task::disable(): Wait for the task to complete, then replace
the task callback function with noop.

waitable_task::enable(): Restore the original task callback function
after disable().

purge_sys_t::stop(): Invoke purge_coordinator_task.disable().

purge_sys_t::resume(): Invoke purge_coordinator_task.enable().

purge_sys_t::running(): Add const qualifier, and clarify the comment.
The purge coordinator task will remain active as long as any purge
worker task is active.

purge_worker_callback(): Assert purge_sys.running().

srv_purge_wakeup(): Merge with the only caller purge_sys_t::resume().

purge_coordinator_task: Use static linkage.
2020-02-07 08:12:58 +02:00
Vladislav Vaintroub
b19760b843 MDEV-21551 : Assertion `m_active_threads.size() >= m_long_tasks_count + m_waiting_task_count' failed"
Happened when running innodb_fts.sync_ddl

m_long_task_count could be wrongly reset to 0, if m_task_queue is
empty.
2020-01-23 15:23:46 +01:00
Vladislav Vaintroub
fde1589f9b MDEV-21551 Fix race condition in thread_pool_generic::wait_begin()
While waiting for mutex, thread_pool_generic::wait_begin(),
current task can be marked long-running. This is done by periodic
mantainence task, that runs in parallel.

Fix to recheck is_long_task() after the mutex acquisition.
2020-01-22 19:36:08 +01:00
Marko Mäkelä
588eac58fd MDEV-21551: Fix -Wsign-compare
An assertion added in commit c20bf8fd49
includes a sign mismatch. Make the affected data members unsigned.
2020-01-22 10:06:07 +02:00
Vladislav Vaintroub
c20bf8fd49 MDEV-21551 Fix calculation of current concurrency level in
maybe_wake_or_create_thread()

A task that is executed,could be counted as waiting (after wait_begin()
before wait_end()) or as long-running (callback runs for a long time).

If task is both marked waiting and long running, then calculation of
current concurrency (# of executing tasks - # of long tasks - #of waiting tasks)
is wrong, as task is counted twice.

Thus current concurrency could go negative, but with unsigned arithmetic
it will become a huge number.

As a result, maybe_wake_or_create_thread() would neither wake or create
a thread, when it should. Which may result in a deadlock.
2020-01-22 00:01:25 +01:00
Vladislav Vaintroub
508bc20a85 tpool - misc fixes 2020-01-12 21:34:59 +01:00
Vladislav Vaintroub
c27577a1ad MDEV-21326 : Address TSAN warnings in tpool.
1. Fix places where data race warnings were relevant.

tls_worker_data::m_state should be modified under mutex protection,
since both maintainence timer and current worker set this flag.

2. Suppress warnings that are legitimate, yet harmless.
Apparently, the dirty reads in waitable_task::get_ref_count() or
write_slots->pending_io_count()

Avoiding race entirely without side-effects here is tricky,
and the effects of race is harmless.

The worst thing that can happen due to race is an extra wait notification,
under rare circumstances.
2020-01-12 20:30:26 +01:00
Vladislav Vaintroub
bada05a883 tpool - implement post-task callback (for Innodb debugging) 2020-01-12 19:08:02 +01:00
Vladislav Vaintroub
66de4fef76 MDEV-16264 - some improvements
- wait notification, tpool_wait_begin/tpool_wait_end - to notify the
threadpool that current thread is going to wait

Use it to wait for IOs to complete and also when purge waits for workers.
2019-12-09 21:12:13 +01:00
Marko Mäkelä
57444a3b30 MDEV-16264: Minor cleanup
aio_linux::m_max_io_count: Unused data member; remove.

aiocb::m_ret_len: Declare as the more compatible type size_t.
Unfortunately, ssize_t is not available on Microsoft Visual Studio.
2019-12-03 11:05:18 +02:00
Vladislav Vaintroub
86407a59b3 MDEV-16264 - Fix assertion `m_queue.empty() && !m_tasks_running' in tpool::task_group destructor
This particular assertion happened when shutting down Innodb IO.IO shutdown properly waits for all IOs to finish


However there is a race condition -
right after releasing last IO slot and before decrementing task count
in group, pending_io_count will be 0, but tasks_running will be 1,
leading to assertion.

The fix is to make task_group destructor to wait for last running task
to finish.
2019-11-25 17:10:01 +01:00
Vladislav Vaintroub
c233d406cb Fix compile error on centos6. it does not like std::this_thread::sleep()
Simplify task_group destructor.
No tasks must be running or queued into task group is being destroyed.
2019-11-15 23:51:49 +01:00
Marko Mäkelä
8040998624 MDEV-16264: Fix some white space 2019-11-15 19:55:13 +02:00
Vladislav Vaintroub
00ee8d85c9 MDEV-16264: Add threadpool library
The library is capable of
- asynchronous execution of tasks (and optionally waiting for them)
- asynchronous file IO
  This is implemented using libaio on Linux and completion ports on
  Windows. Elsewhere, async io is "simulated", which means worker threads
  are performing synchronous IO.
- timers, scheduling work asynchronously in some point of the future.
  Also periodic timers are implemented.
2019-11-15 16:50:22 +01:00