tokudb磁盘满问题 & tokudb_fs_reserve_percent 参数

时间:2022-05-31 00:29:46

当你使用tokudb引擎的时候,你会发现在磁盘还没有完全使用完的时候,就无法继续插入数据了,会报存储空间满相关错误。

这个时候你发现数据目录可能还没有满,让人会感觉很奇怪。 其实这个和tokudb这个引擎相关了,这个是因为tokudb会预留

tokudb_fs_reserve_percent比例的存储空间给数据目录。

这个变量控制可以写入文件系统的百分比。默认为5,意思是磁盘剩余可用空间低于5%的时候,拒绝写入,直到释放出更多的空间(每五秒去检测磁盘空间大小)。一旦停用,插入将被重新启用,有2倍的储备可用。如果磁盘完全满TokuDB将完全冻结。建议大小为物理内存至少有一半的大小。


更多的关于 tokudb_fs_reserve_percent变量,看下面从官方文档上找的资料(关于遇到TOKUDB引擎磁盘满错误的解决方法,在下面也有,同色字体有标注):


官方文档关于tokudb_fs_reserve_percent参数

This variable controls the percentage of the file system that must be available for inserts to be allowed. By

default, this is set to 5. We recommend that this reserve be at least half the size of your physical memory.

See Full Disks for more information.


Full Disks
What happens when the disk system fills up?
The disk system may fill up during bulk load operations, such as LOAD DATA IN FILE or CREATE INDEX, or
during incremental operations like INSERT.
In the bulk case, running out of disk space will cause the statement to fail with ERROR 1030 (HY000): Got
error 1 from storage engine. The temporary space used by the bulk loader will be released. If this happens,
you can use a separate physical disk for the temporary files (for more information, see tokudb_tmp_dir).
Otherwise, disk space can run low during non-bulk operations. When available space is below a user- configurable
reserve (5% by default) inserts are prevented and transactions that perform inserts are aborted. If the disk becomes
completely full then TokuDB will freeze until some disk space is made available.
Details about the disk system:
• There is a free-space reserve requirement, which is a user-configurable parameter given as a percentage of the
total space in the file system. The default reserve is five percent. This value is available in the global variable
tokudb_fs_reserve_percent. We recommend that this reserve be at least half the size of your physical
memory.
TokuDB polls the file system every five seconds to determine how much free space is available. If the free space
dips below the reserve, then further table inserts are prohibited. Any transaction that attempts to insert rows
will be aborted. Inserts are re-enabled when twice the reserve is available in the file system (so freeing a small
amount of disk storage will not be sufficient to resume inserts). Warning messages are sent to the system error
log when free space dips below twice the reserve and again when free space dips below the reserve.
Even with inserts prohibited it is still possible for the file system to become completely full. For example this
can happen because another storage engine or another application consumes disk space.
• If the file system becomes completely full, then TokuDB will freeze. It will not crash, but it will not respond to
most SQL commands until some disk space is made available. When TokuDB is frozen in this state, it will still
respond to the following command:
SHOW ENGINE TokuDB STATUS;
Make disk space available will allow the storage engine to continue running, but inserts will still be
prohibited until twice the reserve is free.
Note: Engine status displays a field indicating if disk free space is above twice the reserve, below twice
the reserve, or below the reserve. It will also display a special warning if the disk is completely full.
• In order to make space available on this system you can:
– Add some disk space to the filesystem.
– Delete some non-TokuDB files manually.
– If the disk is not completely full, you may be able to reclaim space by aborting any transactions that are
very old. Old transactions can consume large volumes of disk space in the recovery log.
– If the disk is not completely full, you can drop indexes or drop tables from your TokuDB databases.

– Deleting large numbers of rows from an existing table and then closing the table may free some space, but
it may not. Deleting rows may simply leave unused space (available for new inserts) inside TokuDB data
files rather than shrink the files (internal fragmentation).
The fine print:
• The TokuDB storage engine can use up to three separate file systems simultaneously, one each for the data, the
recovery log, and the error log. All three are monitored, and if any one of the three falls below the relevant
threshold then a warning message will be issued and inserts may be prohibited.
• Warning messages to the error log are not repeated unless available disk space has been above the relevant
threshold for at least one minute. This prevents excess messages in the error log if the disk free space is
fluctuating around the limit.
• Even if there are no other storage engines or other applications running, it is still possible for TokuDB to
consume more disk space when operations such as row delete and query are performed, or when checkpoints
are taken. This can happen because TokuDB can write cached information when it is time-efficient rather than
when inserts are issued by the application, because operations in addition to insert (such as delete) create log
entries, and also because of internal fragmentation of TokuDB data files.
• The tokudb_fs_reserve_percent variablecan not be changed once the system has started. It can only
be set in my.cnf or on the mysqld command line.