Skip to content

Commit 6870f17

Browse files
committed
Merge remote-tracking branch 'origin/bb-10.10-MDEV-11026' into 10.11
2 parents 7253cdf + c8e3bcf commit 6870f17

12 files changed

+219
-45
lines changed

mysql-test/suite/sys_vars/r/innodb_file_io_threads_basic.result

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,10 @@ COUNT(@@GLOBAL.innodb_write_io_threads)
88
1
99
1 Expected
1010
'#---------------------BS_STVARS_027_02----------------------#'
11-
SET @@GLOBAL.innodb_read_io_threads=1;
12-
ERROR HY000: Variable 'innodb_read_io_threads' is a read only variable
13-
Expected error 'Read only variable'
1411
SELECT COUNT(@@GLOBAL.innodb_read_io_threads);
1512
COUNT(@@GLOBAL.innodb_read_io_threads)
1613
1
1714
1 Expected
18-
SET @@GLOBAL.innodb_write_io_threads=1;
19-
ERROR HY000: Variable 'innodb_write_io_threads' is a read only variable
20-
Expected error 'Read only variable'
2115
SELECT COUNT(@@GLOBAL.innodb_write_io_threads);
2216
COUNT(@@GLOBAL.innodb_write_io_threads)
2317
1

mysql-test/suite/sys_vars/r/innodb_read_io_threads_basic.result

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ INNODB_READ_IO_THREADS 2
1515
select * from information_schema.session_variables where variable_name='innodb_read_io_threads';
1616
VARIABLE_NAME VARIABLE_VALUE
1717
INNODB_READ_IO_THREADS 2
18-
set global innodb_read_io_threads=1;
19-
ERROR HY000: Variable 'innodb_read_io_threads' is a read only variable
18+
select @@innodb_read_io_threads into @n;
19+
set global innodb_read_io_threads = 1;
20+
select @@innodb_read_io_threads;
21+
@@innodb_read_io_threads
22+
1
23+
set global innodb_read_io_threads=64;
24+
select @@innodb_read_io_threads;
25+
@@innodb_read_io_threads
26+
64
2027
set session innodb_read_io_threads=1;
21-
ERROR HY000: Variable 'innodb_read_io_threads' is a read only variable
28+
ERROR HY000: Variable 'innodb_read_io_threads' is a GLOBAL variable and should be set with SET GLOBAL
29+
set global innodb_read_io_threads=@n;

mysql-test/suite/sys_vars/r/innodb_write_io_threads_basic.result

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ INNODB_WRITE_IO_THREADS 2
1515
select * from information_schema.session_variables where variable_name='innodb_write_io_threads';
1616
VARIABLE_NAME VARIABLE_VALUE
1717
INNODB_WRITE_IO_THREADS 2
18+
select @@innodb_write_io_threads into @n;
1819
set global innodb_write_io_threads=1;
19-
ERROR HY000: Variable 'innodb_write_io_threads' is a read only variable
20-
set session innodb_write_io_threads=1;
21-
ERROR HY000: Variable 'innodb_write_io_threads' is a read only variable
20+
select @@innodb_write_io_threads;
21+
@@innodb_write_io_threads
22+
2
23+
set global innodb_write_io_threads=64;
24+
select @@innodb_write_io_threads;
25+
@@innodb_write_io_threads
26+
64
27+
set global innodb_write_io_threads=@n;

mysql-test/suite/sys_vars/r/sysvars_innodb.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ NUMERIC_MIN_VALUE 1
13491349
NUMERIC_MAX_VALUE 64
13501350
NUMERIC_BLOCK_SIZE 0
13511351
ENUM_VALUE_LIST NULL
1352-
READ_ONLYYES
1352+
READ_ONLYNO
13531353
COMMAND_LINE_ARGUMENT REQUIRED
13541354
VARIABLE_NAME INNODB_READ_ONLY
13551355
SESSION_VALUE NULL
@@ -1697,5 +1697,5 @@ NUMERIC_MIN_VALUE 2
16971697
NUMERIC_MAX_VALUE 64
16981698
NUMERIC_BLOCK_SIZE 0
16991699
ENUM_VALUE_LIST NULL
1700-
READ_ONLYYES
1700+
READ_ONLYNO
17011701
COMMAND_LINE_ARGUMENT REQUIRED

mysql-test/suite/sys_vars/t/innodb_file_io_threads_basic.test

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,10 @@ SELECT COUNT(@@GLOBAL.innodb_write_io_threads);
3939
# Check if Value can set #
4040
####################################################################
4141

42-
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
43-
SET @@GLOBAL.innodb_read_io_threads=1;
44-
--echo Expected error 'Read only variable'
4542

4643
SELECT COUNT(@@GLOBAL.innodb_read_io_threads);
4744
--echo 1 Expected
4845

49-
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
50-
SET @@GLOBAL.innodb_write_io_threads=1;
51-
--echo Expected error 'Read only variable'
52-
5346
SELECT COUNT(@@GLOBAL.innodb_write_io_threads);
5447
--echo 1 Expected
5548

mysql-test/suite/sys_vars/t/innodb_read_io_threads_basic.test

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@ select * from information_schema.session_variables where variable_name='innodb_r
1919
--enable_warnings
2020

2121
#
22-
# show that it's read-only
22+
# show that it's not read-only
2323
#
24-
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
25-
set global innodb_read_io_threads=1;
26-
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
24+
select @@innodb_read_io_threads into @n;
25+
--disable_warnings
26+
set global innodb_read_io_threads = 1;
27+
--enable_warnings
28+
select @@innodb_read_io_threads;
29+
--disable_warnings
30+
set global innodb_read_io_threads=64;
31+
--enable_warnings
32+
select @@innodb_read_io_threads;
33+
--error ER_GLOBAL_VARIABLE
2734
set session innodb_read_io_threads=1;
35+
set global innodb_read_io_threads=@n;
2836

mysql-test/suite/sys_vars/t/innodb_write_io_threads_basic.test

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@ select * from information_schema.session_variables where variable_name='innodb_w
1919
--enable_warnings
2020

2121
#
22-
# show that it's read-only
22+
# show that it's not read-only
2323
#
24-
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
24+
select @@innodb_write_io_threads into @n;
25+
--disable_warnings
2526
set global innodb_write_io_threads=1;
26-
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
27-
set session innodb_write_io_threads=1;
27+
--enable_warnings
28+
select @@innodb_write_io_threads;
29+
--disable_warnings
30+
set global innodb_write_io_threads=64;
31+
--enable_warnings
32+
select @@innodb_write_io_threads;
33+
--disable_warnings
34+
set global innodb_write_io_threads=@n;
35+
--enable_warnings
2836

storage/innobase/handler/ha_innodb.cc

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19271,15 +19271,44 @@ static MYSQL_SYSVAR_BOOL(optimize_fulltext_only, innodb_optimize_fulltext_only,
1927119271
"Only optimize the Fulltext index of the table",
1927219272
NULL, NULL, FALSE);
1927319273

19274+
extern int os_aio_resize(ulint n_reader_threads, ulint n_writer_threads);
19275+
static void innodb_update_io_thread_count(THD *thd,ulint n_read, ulint n_write)
19276+
{
19277+
int res = os_aio_resize(n_read, n_write);
19278+
if (res)
19279+
{
19280+
#ifndef __linux__
19281+
ut_ad(0);
19282+
#else
19283+
ut_a(srv_use_native_aio);
19284+
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
19285+
ER_UNKNOWN_ERROR,
19286+
"Could not reserve max. number of concurrent ios."
19287+
"Increase the /proc/sys/fs/aio-max-nr to fix.");
19288+
#endif
19289+
}
19290+
}
19291+
19292+
static void innodb_read_io_threads_update(THD* thd, struct st_mysql_sys_var*, void*, const void* save)
19293+
{
19294+
srv_n_read_io_threads = *static_cast<const uint*>(save);
19295+
innodb_update_io_thread_count(thd, srv_n_read_io_threads, srv_n_write_io_threads);
19296+
}
19297+
static void innodb_write_io_threads_update(THD* thd, struct st_mysql_sys_var*, void*, const void* save)
19298+
{
19299+
srv_n_write_io_threads = *static_cast<const uint*>(save);
19300+
innodb_update_io_thread_count(thd, srv_n_read_io_threads, srv_n_write_io_threads);
19301+
}
19302+
1927419303
static MYSQL_SYSVAR_UINT(read_io_threads, srv_n_read_io_threads,
19275-
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
19304+
PLUGIN_VAR_RQCMDARG,
1927619305
"Number of background read I/O threads in InnoDB.",
19277-
NULL, NULL, 4, 1, 64, 0);
19306+
NULL, innodb_read_io_threads_update , 4, 1, 64, 0);
1927819307

1927919308
static MYSQL_SYSVAR_UINT(write_io_threads, srv_n_write_io_threads,
19280-
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
19309+
PLUGIN_VAR_RQCMDARG,
1928119310
"Number of background write I/O threads in InnoDB.",
19282-
NULL, NULL, 4, 2, 64, 0);
19311+
NULL, innodb_write_io_threads_update, 4, 2, 64, 0);
1928319312

1928419313
static MYSQL_SYSVAR_ULONG(force_recovery, srv_force_recovery,
1928519314
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,

storage/innobase/os/os0file.cc

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ class io_slots
8383
int m_max_aio;
8484
public:
8585
io_slots(int max_submitted_io, int max_callback_concurrency) :
86-
m_cache(max_submitted_io),
87-
m_group(max_callback_concurrency),
86+
m_cache(max_submitted_io), m_group(max_callback_concurrency, false),
8887
m_max_aio(max_submitted_io)
8988
{
9089
}
@@ -105,6 +104,11 @@ class io_slots
105104
}
106105

107106
/* Wait for completions of all AIO operations */
107+
void wait(std::unique_lock<std::mutex> &lk)
108+
{
109+
m_cache.wait(lk);
110+
}
111+
108112
void wait()
109113
{
110114
m_cache.wait();
@@ -124,6 +128,24 @@ class io_slots
124128
{
125129
wait();
126130
}
131+
132+
std::mutex& mutex()
133+
{
134+
return m_cache.mutex();
135+
}
136+
137+
void resize(int max_submitted_io, int max_callback_concurrency, std::unique_lock<std::mutex> &lk)
138+
{
139+
ut_a(lk.owns_lock());
140+
m_cache.resize(max_submitted_io);
141+
m_group.set_max_tasks(max_callback_concurrency);
142+
m_max_aio = max_submitted_io;
143+
}
144+
145+
tpool::task_group& task_group()
146+
{
147+
return m_group;
148+
}
127149
};
128150

129151
static io_slots *read_slots;
@@ -3691,6 +3713,58 @@ int os_aio_init()
36913713
}
36923714

36933715

3716+
/**
3717+
Change reader or writer thread parameter on a running server.
3718+
This includes resizing the io slots, as we calculate
3719+
number of outstanding IOs based on the these variables.
3720+
3721+
It is trickier with when Linux AIO is involved (io_context
3722+
needs to be recreated to account for different number of
3723+
max_events). With Linux AIO, depending on fs-max-aio number
3724+
and user and system wide max-aio limitation, this can fail.
3725+
3726+
Otherwise, we just resize the slots, and allow for
3727+
more concurrent threads via thread_group setting.
3728+
3729+
@param[in] n_reader_threads - max number of concurrently
3730+
executing read callbacks
3731+
@param[in] n_writer_thread - max number of cuncurrently
3732+
executing write callbacks
3733+
@return 0 for success, !=0 for error.
3734+
*/
3735+
int os_aio_resize(ulint n_reader_threads, ulint n_writer_threads)
3736+
{
3737+
/* Lock the slots, and wait until all current IOs finish.*/
3738+
std::unique_lock<std::mutex> lk_read(read_slots->mutex());
3739+
std::unique_lock<std::mutex> lk_write(write_slots->mutex());
3740+
3741+
read_slots->wait(lk_read);
3742+
write_slots->wait(lk_write);
3743+
3744+
/* Now, all IOs have finished and no new ones can start, due to locks. */
3745+
int max_read_events= int(n_reader_threads * OS_AIO_N_PENDING_IOS_PER_THREAD);
3746+
int max_write_events= int(n_writer_threads * OS_AIO_N_PENDING_IOS_PER_THREAD);
3747+
int events= max_read_events + max_write_events;
3748+
3749+
/** Do the Linux AIO dance (this will try to create a new
3750+
io context with changed max_events ,etc*/
3751+
3752+
if (int ret= srv_thread_pool->reconfigure_aio(srv_use_native_aio, events))
3753+
{
3754+
/** Do the best effort. We can't change the parallel io number,
3755+
but we still can adjust the number of concurrent completion handlers.*/
3756+
read_slots->task_group().set_max_tasks(static_cast<int>(n_reader_threads));
3757+
write_slots->task_group().set_max_tasks(static_cast<int>(n_writer_threads));
3758+
return ret;
3759+
}
3760+
3761+
/* Allocation succeeded, resize the slots*/
3762+
read_slots->resize(max_read_events, static_cast<int>(n_reader_threads), lk_read);
3763+
write_slots->resize(max_write_events, static_cast<int>(n_writer_threads), lk_write);
3764+
3765+
return 0;
3766+
}
3767+
36943768
void os_aio_free()
36953769
{
36963770
srv_thread_pool->disable_aio();

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

0 commit comments

Comments
 (0)