Bug #79751 file size was not correctly set in function fil_ibd_create
Submitted: 23 Dec 2015 8:25 Modified: 24 Dec 2015 7:59
Reporter: zhai weixiang (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:5.7, 5.6 OS:Any
Assigned to: CPU Architecture:Any

[23 Dec 2015 8:25] zhai weixiang
Description:
In function fil_ibd_create, a ibd file was init to 4 pages and the unit of page  is UNIV_PAGE_SIZE. After the ibd file is created. It will create the in-memory file structure, such as fil_space_t and fil_node_t. 

Here fil_space_t::size and fil_node_t::size are both set to 4. It's correct for uncompressed table. But when it comes to compressed table, should take zip_size into account.

I am not sure if this is a designed behavior.  In 5.6 version ,it may do unnecessary writes while trying to extend the file size. It's ok in 5.7 because it will check if the desired size is exceed physical size, If not, then skip extending. 

How to repeat:
make a breakpoint in function  fil_space_extend  (code based on MySQL5.7.10)

create  table t1 (a int) row_format=compressed key_block_size=2;

the file size is already inited to 64kb (default page size is 16kb, 16kb * 4)

$ls -l /u01/my57/data/xx/t1.ibd 
-rw-r----- 1 xxx xxx 65536 Dec 23 15:43 /u01/my57/data/xx/t1.ibd

but the current node size (fil_node_t::size) is 4, which should be 32 because the page size of this compressed table is 2kb (key_block_size = 2)

Print these variables by using gdb

(gdb) f 0
#0  fil_space_extend (space=0x2b13b03881a8, size=Unhandled dwarf expression opcode 0xf3
) at /u01/yf_57/mysql-server/storage/innobase/fil/fil0fil.cc:5000
5000                    os_has_said_disk_full = FALSE;
(gdb) p space->name
$22 = 0x2b13b036e778 "xx/t1"
(gdb) p space->size
$23 = 4
(gdb) p node->size
$24 = 4
(gdb) p n_node_physical_pages
$25 = 32

Suggested fix:
correct fil_node_t::size and fil_space_t::size in function fil_ibd_create
[24 Dec 2015 7:59] MySQL Verification Team
Hello Zhai,

Thank you for the report.
Observed this with 5.7.10 src build.

Thanks,
Umesh
[24 Dec 2015 8:02] MySQL Verification Team
// 5.6.10

(gdb) b fil_space_extend
Breakpoint 1 at 0x1b14f92: file /export/umesh/server/source/bugs/79751/mysql-5.7.10/storage/innobase/fil/fil0fil.cc, line 4851.
(gdb) run
Starting program: /export/umesh/server/source/bugs/79751/mysql-5.7.10/bin/mysqld --basedir=/export/umesh/server/source/bugs/79751/mysql-5.7.10 --datadir=/export/umesh/server/source/bugs/79751/mysql-5.7.10/data --socket=/tmp/mysql_ushastry.sock --port=15000 --log-error=/export/umesh/server/source/bugs/79751/mysql-5.7.10/data/log.err
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
.

Breakpoint 1, fil_space_extend (space=0x7fff8401bc28, size=6) at /export/umesh/server/source/bugs/79751/mysql-5.7.10/storage/innobase/fil/fil0fil.cc:4851
4851            ut_ad(!srv_read_only_mode || fsp_is_system_temporary(space->id));

5000                    os_has_said_disk_full = FALSE;

(gdb)  p space->name
$5 = 0x7fff84010988 "test/t2"
(gdb) p space->size
$6 = 4
(gdb) p node->size
$7 = 4
(gdb) p n_node_physical_pages
$8 = 32
(gdb)

// Session 2

[umshastr@hod03]/export/umesh/server/source/bugs/79751/mysql-5.7.10: bin/mysql -uroot -S /tmp/mysql_ushastry.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.10-debug Source distribution

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> create  table t2 (a int) row_format=compressed key_block_size=2;