Skip to content

Commit c8e3bcf

Browse files
committed
MDEV-11026 Make InnoDB number of IO write/read threads dynamic
Fix concurrency error - avoid accessing deleted memory, when io_slots is resized. the deleted memory in this case was vftable pointer in aiocb::m_internal_task The fix avoids calling dummy release function, via a flag in task_group.
1 parent 49e660b commit c8e3bcf

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

storage/innobase/os/os0file.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ class io_slots
8484
int m_max_aio;
8585
public:
8686
io_slots(int max_submitted_io, int max_callback_concurrency) :
87-
m_cache(max_submitted_io),
88-
m_group(max_callback_concurrency),
87+
m_cache(max_submitted_io), m_group(max_callback_concurrency, false),
8988
m_max_aio(max_submitted_io)
9089
{
9190
}

tpool/task_group.cc

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,26 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 - 1301 USA*/
2525
#endif
2626
namespace tpool
2727
{
28-
task_group::task_group(unsigned int max_concurrency) :
28+
29+
/**
30+
Task_group constructor
31+
32+
@param max_threads - maximum number of threads allowed to execute
33+
tasks from the group at the same time.
34+
35+
@param enable_task_release - if true (default), task::release() will be
36+
called after task execution.'false' should only be used in rare cases
37+
when accessing memory, pointed by task structures, would be unsafe after.
38+
the callback. Also 'false' is only possible ,if task::release() is a trivial function
39+
*/
40+
task_group::task_group(unsigned int max_concurrency,
41+
bool enable_task_release)
42+
:
2943
m_queue(8),
3044
m_mtx(),
3145
m_tasks_running(),
32-
m_max_concurrent_tasks(max_concurrency)
46+
m_max_concurrent_tasks(max_concurrency),
47+
m_enable_task_release(enable_task_release)
3348
{};
3449

3550
void task_group::set_max_tasks(unsigned int max_concurrency)
@@ -53,7 +68,8 @@ namespace tpool
5368
if (t)
5469
{
5570
t->m_func(t->m_arg);
56-
t->release();
71+
if (m_enable_task_release)
72+
t->release();
5773
}
5874
lk.lock();
5975

tpool/tpool.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ class task_group
6868
std::condition_variable m_cv;
6969
unsigned int m_tasks_running;
7070
unsigned int m_max_concurrent_tasks;
71+
const bool m_enable_task_release;
72+
7173
public:
72-
task_group(unsigned int max_concurrency= 100000);
74+
task_group(unsigned int max_concurrency= 100000, bool m_enable_task_release= true);
7375
void set_max_tasks(unsigned int max_concurrent_tasks);
7476
void execute(task* t);
7577
void cancel_pending(task *t);

0 commit comments

Comments
 (0)