Skip to content

Commit d953f2c

Browse files
committed
MDEV-36868: Inconsistency when shrinking innodb_buffer_pool_size
buf_pool_t::resize(): After successfully shrinking the buffer pool, announce the success. The size had already been updated in shrunk(). After failing to shrink the buffer pool, re-enable the adaptive hash index if it had been enabled. Reviewed by: Debarun Banerjee
1 parent 49f351f commit d953f2c

File tree

5 files changed

+48
-15
lines changed

5 files changed

+48
-15
lines changed

mysql-test/suite/innodb/r/innodb_buffer_pool_resize.result

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ create table t1 (id int primary key, val int not null)
1414
ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
1515
SET STATEMENT foreign_key_checks=0, unique_checks=0 FOR
1616
INSERT INTO t1 SELECT seq*4,seq*4 FROM seq_1_to_262144;
17+
SELECT @@GLOBAL.innodb_adaptive_hash_index;
18+
@@GLOBAL.innodb_adaptive_hash_index
19+
1
20+
SET STATEMENT max_statement_time=1e-9 FOR
21+
SET GLOBAL innodb_buffer_pool_size = 7340032;
22+
SELECT @@GLOBAL.innodb_adaptive_hash_index;
23+
@@GLOBAL.innodb_adaptive_hash_index
24+
1
25+
FOUND 1 /innodb_buffer_pool_size=7m.*resized from|innodb_buffer_pool_size change aborted/ in mysqld.1.err
1726
set global innodb_buffer_pool_size = 7340032;
1827
select count(val) from t1;
1928
count(val)

mysql-test/suite/innodb/r/innodb_buffer_pool_resize_temporary.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ SET @save_limit=@@GLOBAL.innodb_limit_optimistic_insert_debug;
22
SET @save_size=@@GLOBAL.innodb_buffer_pool_size;
33
SET GLOBAL innodb_limit_optimistic_insert_debug=2;
44
SET GLOBAL innodb_buffer_pool_size=16777216;
5+
call mtr.add_suppression("innodb_buffer_pool_size change aborted");
6+
SET @old_innodb_adaptive_hash_index = @@innodb_adaptive_hash_index;
7+
SET GLOBAL innodb_adaptive_hash_index = ON;
8+
SET STATEMENT debug_dbug='+d,buf_shrink_fail' FOR
9+
SET GLOBAL innodb_buffer_pool_size=8388608;
10+
ERROR HY000: innodb_buffer_pool_size change aborted
11+
SELECT @@GLOBAL.innodb_adaptive_hash_index,@@GLOBAL.innodb_buffer_pool_size;
12+
@@GLOBAL.innodb_adaptive_hash_index @@GLOBAL.innodb_buffer_pool_size
13+
1 16777216
14+
SET GLOBAL innodb_adaptive_hash_index = @old_innodb_adaptive_hash_index;
515
CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
616
INSERT INTO t1 SELECT seq FROM seq_1_to_200;
717
SET GLOBAL innodb_max_purge_lag_wait=0;

mysql-test/suite/innodb/t/innodb_buffer_pool_resize.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
--source include/have_innodb.inc
22
--source include/have_sequence.inc
3+
--source include/not_embedded.inc # there are no messages in mysqld.1.err
34

45
--echo #
56
--echo # MDEV-29445: Reorganize buffer pool (and remove chunks)
@@ -37,6 +38,17 @@ INSERT INTO t1 SELECT seq*4,seq*4 FROM seq_1_to_262144;
3738
SET GLOBAL innodb_read_only_compressed=@save_innodb_read_only_compressed;
3839
--enable_query_log
3940

41+
SELECT @@GLOBAL.innodb_adaptive_hash_index;
42+
--error 0,ER_WRONG_USAGE
43+
SET STATEMENT max_statement_time=1e-9 FOR
44+
SET GLOBAL innodb_buffer_pool_size = 7340032;
45+
SELECT @@GLOBAL.innodb_adaptive_hash_index;
46+
47+
--let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err
48+
--let SEARCH_PATTERN= InnoDB: Trying to shrink innodb_buffer_pool_size=7m
49+
--let SEARCH_PATTERN= innodb_buffer_pool_size=7m.*resized from|innodb_buffer_pool_size change aborted
50+
--source include/search_pattern_in_file.inc
51+
4052
# Attempt to shrink the buffer pool. This may occasionally fail.
4153
--error 0,ER_WRONG_USAGE
4254
set global innodb_buffer_pool_size = 7340032;

mysql-test/suite/innodb/t/innodb_buffer_pool_resize_temporary.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ SET @save_size=@@GLOBAL.innodb_buffer_pool_size;
88
SET GLOBAL innodb_limit_optimistic_insert_debug=2;
99
SET GLOBAL innodb_buffer_pool_size=16777216;
1010

11+
call mtr.add_suppression("innodb_buffer_pool_size change aborted");
12+
13+
SET @old_innodb_adaptive_hash_index = @@innodb_adaptive_hash_index;
14+
SET GLOBAL innodb_adaptive_hash_index = ON;
15+
--error ER_WRONG_USAGE
16+
SET STATEMENT debug_dbug='+d,buf_shrink_fail' FOR
17+
SET GLOBAL innodb_buffer_pool_size=8388608;
18+
SELECT @@GLOBAL.innodb_adaptive_hash_index,@@GLOBAL.innodb_buffer_pool_size;
19+
SET GLOBAL innodb_adaptive_hash_index = @old_innodb_adaptive_hash_index;
20+
1121
CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
1222
INSERT INTO t1 SELECT seq FROM seq_1_to_200;
1323

storage/innobase/buf/buf0buf.cc

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,7 @@ ATTRIBUTE_COLD buf_pool_t::shrink_status buf_pool_t::shrink(size_t size)
16141614
noexcept
16151615
{
16161616
mysql_mutex_assert_owner(&mutex);
1617+
DBUG_EXECUTE_IF("buf_shrink_fail", return SHRINK_ABORT;);
16171618
buf_load_abort();
16181619

16191620
if (!n_blocks_to_withdraw)
@@ -2014,25 +2015,12 @@ ATTRIBUTE_COLD void buf_pool_t::resize(size_t size, THD *thd) noexcept
20142015
if (ahi_disabled)
20152016
btr_search.enable(true);
20162017
#endif
2017-
mysql_mutex_lock(&LOCK_global_system_variables);
2018-
bool resized= n_blocks_removed < 0;
2019-
if (n_blocks_removed > 0)
2020-
{
2021-
mysql_mutex_lock(&mutex);
2022-
resized= size_in_bytes == old_size;
2023-
if (resized)
2024-
{
2025-
size_in_bytes_requested= size;
2026-
size_in_bytes= size;
2027-
}
2028-
mysql_mutex_unlock(&mutex);
2029-
}
2030-
2031-
if (resized)
2018+
if (n_blocks_removed)
20322019
sql_print_information("InnoDB: innodb_buffer_pool_size=%zum (%zu pages)"
20332020
" resized from %zum (%zu pages)",
20342021
size >> 20, n_blocks_new, old_size >> 20,
20352022
old_blocks);
2023+
mysql_mutex_lock(&LOCK_global_system_variables);
20362024
}
20372025
else
20382026
{
@@ -2095,6 +2083,10 @@ ATTRIBUTE_COLD void buf_pool_t::resize(size_t size, THD *thd) noexcept
20952083
mysql_mutex_unlock(&mutex);
20962084
my_printf_error(ER_WRONG_USAGE, "innodb_buffer_pool_size change aborted",
20972085
MYF(ME_ERROR_LOG));
2086+
#ifdef BTR_CUR_HASH_ADAPT
2087+
if (ahi_disabled)
2088+
btr_search.enable(true);
2089+
#endif
20982090
mysql_mutex_lock(&LOCK_global_system_variables);
20992091
}
21002092

0 commit comments

Comments
 (0)