From 55d6761e24edfc067b2aa21a602b58b97671ebde Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sat, 14 Oct 2023 22:05:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E8=AE=BE=E7=BD=AE=E7=9A=84?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E5=AE=B9=E9=87=8F=E6=AF=94=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E7=A3=81=E7=9B=98=E6=80=BB=E5=AE=B9=E9=87=8F=E5=A4=A7=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=EF=BC=8C=E8=87=AA=E5=8A=A8=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E4=B8=BA95%=E7=A3=81=E7=9B=98=E6=80=BB=E5=AE=B9=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/storage_file.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/caches/storage_file.go b/internal/caches/storage_file.go index 14374f2..3e8cfc8 100644 --- a/internal/caches/storage_file.go +++ b/internal/caches/storage_file.go @@ -89,7 +89,8 @@ type FileStorage struct { openFileCache *OpenFileCache - mainDiskIsFull bool + mainDiskIsFull bool + mainDiskTotalSize uint64 subDirs []*FileDir } @@ -1301,9 +1302,17 @@ func (this *FileStorage) diskCapacityBytes() int64 { if nodeCapacity != nil { var c2 = nodeCapacity.Bytes() if c2 > 0 { + if this.mainDiskTotalSize > 0 && c2 >= int64(this.mainDiskTotalSize) { + c2 = int64(this.mainDiskTotalSize) * 95 / 100 // keep 5% free + } return c2 } } + + if c1 <= 0 || (this.mainDiskTotalSize > 0 && c1 >= int64(this.mainDiskTotalSize)) { + c1 = int64(this.mainDiskTotalSize) * 95 / 100 // keep 5% free + } + return c1 } @@ -1511,6 +1520,7 @@ func (this *FileStorage) checkDiskSpace() { stat, err := fsutils.StatDevice(options.Dir) if err == nil { this.mainDiskIsFull = stat.FreeSize() < minFreeSize + this.mainDiskTotalSize = stat.TotalSize() // check capacity (only on main directory) when node capacity had not been set if !this.mainDiskIsFull {