Skip to content

Commit 7b4b759

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 bcd02c7 commit 7b4b759

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
@@ -18,6 +18,15 @@ SET STATEMENT foreign_key_checks=0, unique_checks=0 FOR
1818
INSERT INTO t1 SELECT seq*4,seq*4 FROM seq_1_to_262144;
1919
SET STATEMENT foreign_key_checks=0, unique_checks=0 FOR
2020
INSERT INTO t2 SELECT seq*4,seq*4 FROM seq_1_to_16384;
21+
SELECT @@GLOBAL.innodb_adaptive_hash_index;
22+
@@GLOBAL.innodb_adaptive_hash_index
23+
1
24+
SET STATEMENT max_statement_time=1e-9 FOR
25+
SET GLOBAL innodb_buffer_pool_size = 7340032;
26+
SELECT @@GLOBAL.innodb_adaptive_hash_index;
27+
@@GLOBAL.innodb_adaptive_hash_index
28+
1
29+
FOUND 1 /innodb_buffer_pool_size=7m.*resized from|innodb_buffer_pool_size change aborted/ in mysqld.1.err
2130
set global innodb_buffer_pool_size = 7340032;
2231
select count(val) from t1;
2332
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)
@@ -42,6 +43,17 @@ INSERT INTO t2 SELECT seq*4,seq*4 FROM seq_1_to_16384;
4243
SET GLOBAL innodb_read_only_compressed=@save_innodb_read_only_compressed;
4344
--enable_query_log
4445

46+
SELECT @@GLOBAL.innodb_adaptive_hash_index;
47+
--error 0,ER_WRONG_USAGE
48+
SET STATEMENT max_statement_time=1e-9 FOR
49+
SET GLOBAL innodb_buffer_pool_size = 7340032;
50+
SELECT @@GLOBAL.innodb_adaptive_hash_index;
51+
52+
--let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err
53+
--let SEARCH_PATTERN= InnoDB: Trying to shrink innodb_buffer_pool_size=7m
54+
--let SEARCH_PATTERN= innodb_buffer_pool_size=7m.*resized from|innodb_buffer_pool_size change aborted
55+
--source include/search_pattern_in_file.inc
56+
4557
# Attempt to shrink the buffer pool. This may occasionally fail.
4658
--error 0,ER_WRONG_USAGE
4759
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
@@ -1606,6 +1606,7 @@ ATTRIBUTE_COLD buf_pool_t::shrink_status buf_pool_t::shrink(size_t size)
16061606
noexcept
16071607
{
16081608
mysql_mutex_assert_owner(&mutex);
1609+
DBUG_EXECUTE_IF("buf_shrink_fail", return SHRINK_ABORT;);
16091610
buf_load_abort();
16101611

16111612
if (!n_blocks_to_withdraw)
@@ -2011,25 +2012,12 @@ ATTRIBUTE_COLD void buf_pool_t::resize(size_t size, THD *thd) noexcept
20112012
if (ahi_disabled)
20122013
btr_search_enable(true);
20132014
#endif
2014-
mysql_mutex_lock(&LOCK_global_system_variables);
2015-
bool resized= n_blocks_removed < 0;
2016-
if (n_blocks_removed > 0)
2017-
{
2018-
mysql_mutex_lock(&mutex);
2019-
resized= size_in_bytes == old_size;
2020-
if (resized)
2021-
{
2022-
size_in_bytes_requested= size;
2023-
size_in_bytes= size;
2024-
}
2025-
mysql_mutex_unlock(&mutex);
2026-
}
2027-
2028-
if (resized)
2015+
if (n_blocks_removed)
20292016
sql_print_information("InnoDB: innodb_buffer_pool_size=%zum (%zu pages)"
20302017
" resized from %zum (%zu pages)",
20312018
size >> 20, n_blocks_new, old_size >> 20,
20322019
old_blocks);
2020+
mysql_mutex_lock(&LOCK_global_system_variables);
20332021
}
20342022
else
20352023
{
@@ -2092,6 +2080,10 @@ ATTRIBUTE_COLD void buf_pool_t::resize(size_t size, THD *thd) noexcept
20922080
mysql_mutex_unlock(&mutex);
20932081
my_printf_error(ER_WRONG_USAGE, "innodb_buffer_pool_size change aborted",
20942082
MYF(ME_ERROR_LOG));
2083+
#ifdef BTR_CUR_HASH_ADAPT
2084+
if (ahi_disabled)
2085+
btr_search_enable(true);
2086+
#endif
20952087
mysql_mutex_lock(&LOCK_global_system_variables);
20962088
}
20972089

0 commit comments

Comments
 (0)