From cdfc37ac14d9bdfa4f205c548c82533b220e6ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Sun, 6 Aug 2023 18:08:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=E7=AD=96=E7=95=A5=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E2=80=9C=E7=BC=93=E5=AD=98=E7=A3=81=E7=9B=98=E6=9C=80?= =?UTF-8?q?=E5=B0=8F=E7=A9=BA=E4=BD=99=E7=A9=BA=E9=97=B4=E2=80=9D=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/storage_file.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/internal/caches/storage_file.go b/internal/caches/storage_file.go index 99b6f77..33998c4 100644 --- a/internal/caches/storage_file.go +++ b/internal/caches/storage_file.go @@ -55,7 +55,7 @@ const ( HotItemLifeSeconds int64 = 3600 // 热点数据生命周期 FileToMemoryMaxSize = 32 * sizes.M // 可以从文件写入到内存的最大文件尺寸 FileTmpSuffix = ".tmp" - MinDiskSpace uint64 = 5 << 30 // 当前磁盘最小剩余空间 + DefaultMinDiskFreeSpace uint64 = 5 << 30 // 当前磁盘最小剩余空间 ) var sharedWritingFileKeyMap = map[string]zero.Zero{} // key => bool @@ -1398,17 +1398,24 @@ func (this *FileStorage) runMemoryStorageSafety(f func(memoryStorage *MemoryStor // 检查磁盘剩余空间 func (this *FileStorage) checkDiskSpace() { - if this.options != nil && len(this.options.Dir) > 0 { - stat, err := fsutils.Stat(this.options.Dir) + var minFreeSize = DefaultMinDiskFreeSpace + + var options = this.options // copy + if options != nil && options.MinFreeSize != nil && options.MinFreeSize.Bytes() > 0 { + minFreeSize = uint64(options.MinFreeSize.Bytes()) + } + + if options != nil && len(options.Dir) > 0 { + stat, err := fsutils.Stat(options.Dir) if err == nil { - this.mainDiskIsFull = stat.FreeSize() < MinDiskSpace + this.mainDiskIsFull = stat.FreeSize() < minFreeSize } } var subDirs = this.subDirs // copy slice for _, subDir := range subDirs { stat, err := fsutils.Stat(subDir.Path) if err == nil { - subDir.IsFull = stat.FreeSize() < MinDiskSpace + subDir.IsFull = stat.FreeSize() < minFreeSize } } }