[MDEV-26782] InnoDB temporary tablespace: reclaiming of free space does not work Created: 2021-10-07 Updated: 2023-10-25 Resolved: 2023-04-21 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Server, Storage Engine - InnoDB |
| Affects Version/s: | None |
| Fix Version/s: | 11.1.1, 10.11.3, 11.0.2, 10.6.13, 10.8.8, 10.9.6, 10.10.4 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Jan Volf | Assignee: | Marko Mäkelä |
| Resolution: | Fixed | Votes: | 8 |
| Labels: | None | ||
| Attachments: |
|
||||||||||||||||||||||||||||||||||||||||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||
| Description |
|
When using InnoDB engine for temporary tables, reclaiming of free table space does not seem to work. Periodically performing statements that force the server to write into InnoDB temporary tablespace eventually results in the reaching of maximum size of temporary table space or even a full disk. I was able to reproduce this behaviour by execution of following statements more times even when the connection between the executions is dropped:
After each execution grow the file /var/lib/mysql/ibtmp1 in size Expected behaviour: Last version where the expected behaviour was observed: 10.5.11 Workarround: explicitly setting engine for temporary tables to MyISAM |
| Comments |
| Comment by Marko Mäkelä [ 2021-10-07 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
I tested the following in mtr (just one round of your test):
While the test was sleeping. I executed the following:
The file was filled with NUL bytes, so thanks to After attaching GDB to the server I noticed that the pages belonging to the temporary table are still marked as dirty in the buffer pool, and they could unnecessarily be written to ibtmp1 if we ran out of buffer pool:
The buffer pool contained 131 dirty-marked blocks belonging to the temporary tablespace (0xfffffffe) and 7 belonging to persistent pages.
| |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2021-10-07 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
I did not verify the growth of the ibtmp1 file, but I can easily believe it. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jan Volf [ 2021-10-08 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
I don`t know if it helps, but as I already stated in the description of the problem - the version 10.5.11 seems to be not affected. We observed this problem first after upgrading to version 10.6.4 when we suddenly run out of disk space due to the file ibtmp1 growing in size beyond any expectations effectively filling the free disk space. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jon Wagoner [ 2022-02-03 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
I think I'm hitting this issue in production as well. The ibtmp1 file continues to grow until it runs out of space. If I set a max size in innodb_temp_data_file_path I start getting Error 135: "No more room in record file" once the tmp file is full. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oli Sennhauser [ 2022-02-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
We can easily reproduce Jan example on 10.7.1. See graph
root@localhost [(none)]> show global status like '%tmp%';
------------------------
------------------------ root@localhost [(none)]> show global status like '%temp%';
------------------------------------------
------------------------------------------ | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2022-02-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
jwagoner, can you reproduce this on a newer 10.5 server than 10.5.11? Can anyone provide something easily executable for reproducing this? Is this only repeatable with the Docker image? If yes, danblack is our resident Docker expert and could have some ideas. I can’t think of anything that should significantly differ between 10.5 and 10.6 in this respect, except maybe io_uring ( Would this be helped if you set innodb_immediate_scrub_data_uncompressed=ON to enable the | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jon Wagoner [ 2022-02-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
I am seeing this with 10.6.5 on a Gentoo system. My kernel version is 5.10.76. I don't see my mariadb binary linked against liburing or libaio, although I do have the latter on my system. I ended up setting default_tmp_storage_engine to MyISAM to work around it for now. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oli Sennhauser [ 2022-02-20 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
@Marco: We do NOT see it on 10.5, only 10.6 and newer and NO Docker just plain multi-instance set-up. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2022-02-21 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
oli, thank you. With the following test case, I end up with an ibtmp1 file whose size is 140MiB. The setting innodb_immediate_scrub_data_uncompressed=1 has no impact on this.
Note: Assigning random values to a non-indexed fixed-length column should not make any difference.
In my test, I used a very small buffer pool size, so that buf_pool.LRU eviction would take place, causing data to be written to the temporary tablespace. I checked what the pages are being used for:
The nonzero part of the summary said the following:
My attempt of disabling row-level undo logging by SET unique_checks=0,foreign_key_checks=0; ( If I split the insert into two transactions:
then the summary will look different, but the file size is still the same:
I tried to reduce the transaction sizes even further:
I monitored the file size growth. I think that the file growed from 77MiB to 140MiB during the execution of the last statement. The summary from innochecksum was as follows:
Note: Because the temporary tablespace pages are being written out from the 8MiB buffer pool when we are running out of space (LRU eviction), there is some fluctuation in the page type statistics. It should not matter much, because 8MiB is much smaller than the total file size 140MiB. As it was already noted in Also, it should be possible to shrink the temporary tablespace once all tables have been dropped. For persistent tablespaces, this is more tricky due to recovery considerations. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oli Sennhauser [ 2022-02-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Customer just gave feedback: The problem does NOT happen in 10.5.15 and start occurring in 10.6.5 and 10.7.x He is running on Windows. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Thirunarayanan Balathandayuthapani [ 2022-07-11 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
In 10.6.9 version: Ran the marko's test case with --innodb_buffer_pool_size=1G. There was no LRU eviction or page flushing of temporary
file size is :
fil_space_extend_must_retry() has been called twice and it is being extended to 8960 pages. Trying the same test case in 10.5.15: 10.5.15 also behaves like 10.6.9. No changes. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2022-08-01 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
I think that this needs to be tested and reevaluated after | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Thirunarayanan Balathandayuthapani [ 2022-08-24 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Testing after
I don't see any improvement after | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2022-09-21 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
I filed | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Hartmut Holzgraefe [ 2022-12-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Looks as if this is no longer reproducible in >= 10.6.10 | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2022-12-30 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
hholzgra, could it be that you are confusing this bug with the 10.6 regression | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2023-01-10 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
I believe that the most pressing issue was the bug | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2023-03-24 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
In
| |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2023-03-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
I ran a simple benchmark before and after this fix:
The patch allows the space that was occupied by the row-level undo log from the INSERT…SELECT to be reused by the UPDATE operation. The real time reported for each connection was as follows:
The storage was in /dev/shm and nproc reports 40 on this dual-socket system. During the test, top reported close to 1300% CPU usage for the mariadbd process, corresponding to the number of concurrent client connections. |