From b1b450bb50810deecdc1271637ccccd89380af90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Sat, 20 Apr 2024 18:59:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=99=E5=88=86=E5=8C=BA=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=97=B6=EF=BC=8C=E9=81=BF=E5=85=8D=E5=8D=95?= =?UTF-8?q?=E6=AC=A1=E6=8B=93=E5=B1=95=E7=9A=84=E6=96=87=E4=BB=B6=E5=B0=BA?= =?UTF-8?q?=E5=AF=B8=E5=A4=AA=E5=A4=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/writer_partial_file.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/internal/caches/writer_partial_file.go b/internal/caches/writer_partial_file.go index 64a1bfd..e9617d2 100644 --- a/internal/caches/writer_partial_file.go +++ b/internal/caches/writer_partial_file.go @@ -127,6 +127,32 @@ func (this *PartialFileWriter) WriteAt(offset int64, data []byte) error { return nil } + // prevent extending too much space in a single writing + var maxOffset = this.ranges.Max() + if offset-maxOffset > 16<<20 { + var maxExtendSize int64 = 32 << 20 + if fsutils.DiskIsExtremelyFast() { + maxExtendSize = 128 << 20 + } else if fsutils.DiskIsFast() { + maxExtendSize = 64 << 20 + } + if offset-maxOffset > maxExtendSize { + stat, err := this.rawWriter.Stat() + if err != nil { + return nil + } + + // extend min size to prepare for file tail + const extendSizePerStep = 8 << 20 + if stat.Size()+extendSizePerStep <= this.bodyOffset+offset+int64(len(data)) { + fsutils.WriteBegin() + _ = this.rawWriter.Truncate(stat.Size() + extendSizePerStep) + fsutils.WriteEnd() + return nil + } + } + } + if this.bodyOffset == 0 { var keyLength = 0 if this.ranges.Version == 0 { // 以往的版本包含有Key