#
# WL6117 : Resize the InnoDB Buffer Pool Online
# (innodb_buffer_pool_chunk_size used case)
#

--source include/have_innodb.inc
--source include/have_innodb_zip.inc
--source include/big_test.inc

let $wait_timeout = 180;
let $wait_condition =
  SELECT SUBSTR(variable_value, 1, 34) = 'Completed resizing buffer pool at '
  FROM information_schema.global_status
  WHERE LOWER(variable_name) = 'innodb_buffer_pool_resize_status';

--disable_query_log
set @old_innodb_buffer_pool_size = @@innodb_buffer_pool_size;
if (`select (version() like '%debug%') > 0`)
{
    set @old_innodb_disable_resize = @@innodb_disable_resize_buffer_pool_debug;
    set global innodb_disable_resize_buffer_pool_debug = OFF;
}
--enable_query_log

select @@innodb_buffer_pool_chunk_size;

# fill buffer pool
create table t1 (id int not null, val int not null default '0', primary key (id)) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
create or replace view view0 as select 1 union all select 1;

set @`v_id` := 0;
set @`v_val` := 0;

# 2^18 == 262144 records
replace into t1 select (@`v_id` := (@`v_id` + 4) mod 4294967296) as id, (@`v_val` := (@`v_val` + 4) mod 4294967296) as val from view0 v0, view0 v1, view0 v2, view0 v3, view0 v4, view0 v5, view0 v6, view0 v7, view0 v8, view0 v9, view0 v10, view0 v11, view0 v12, view0 v13, view0 v14, view0 v15, view0 v16, view0 v17;

# Shrink buffer pool to 7MB
set global innodb_buffer_pool_size = 7340032;
--source include/wait_condition.inc

select count(val) from t1;

# Expand buffer pool to 16MB
set global innodb_buffer_pool_size = 16777216;
--source include/wait_condition.inc

select count(val) from t1;

drop table t1;
drop view view0;

# Try to shrink buffer pool to smaller than chunk size
set global innodb_buffer_pool_size = 1048576;
--source include/wait_condition.inc
select @@innodb_buffer_pool_size;

--disable_query_log
set global innodb_buffer_pool_size = @old_innodb_buffer_pool_size;
if (`select (version() like '%debug%') > 0`)
{
    set global innodb_disable_resize_buffer_pool_debug = @old_innodb_disable_resize;
}
--enable_query_log
--source include/wait_condition.inc
