SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
get bytes from sync pool
Chris Luffb5d3f93a69
diff --git a/weed/filesys/dirty_page.go b/weed/filesys/dirty_page.goindex 871905fd5c..c69851071b 100644--- a/weed/filesys/dirty_page.go+++ b/weed/filesys/dirty_page.go@@ -4,6 +4,7 @@ import ("bytes""context""fmt"+ "sync/atomic""time""github.com/chrislusf/seaweedfs/weed/glog"@@ -21,12 +22,6 @@ type ContinuousDirtyPages struct {lock sync.Mutex}-var bufPool = sync.Pool{- New: func() interface{} {- return new(bytes.Buffer)- },-}-func newDirtyPages(file *File) *ContinuousDirtyPages {return &ContinuousDirtyPages{Data: nil,@@ -37,9 +32,14 @@ func newDirtyPages(file *File) *ContinuousDirtyPages {func (pages *ContinuousDirtyPages) releaseResource() {if pages.Data != nil {pages.f.wfs.bufPool.Put(pages.Data)+ pages.Data = nil+ atomic.AddInt32(&counter, -1)+ glog.V(3).Infof("%s/%s releasing resource", pages.f.dir.Path, pages.f.Name, counter)}}+var counter = int32(0)+func (pages *ContinuousDirtyPages) AddPage(ctx context.Context, offset int64, data []byte) (chunks []*filer_pb.FileChunk, err error) {pages.lock.Lock()@@ -47,15 +47,17 @@ func (pages *ContinuousDirtyPages) AddPage(ctx context.Context, offset int64, davar chunk *filer_pb.FileChunk- if pages.Data == nil {- pages.Data = pages.f.wfs.bufPool.Get().([]byte)- }-- if len(data) > len(pages.Data) {+ if len(data) > int(pages.f.wfs.option.ChunkSizeLimit) {// this is more than what buffer can hold.return pages.flushAndSave(ctx, offset, data)}+ if pages.Data == nil {+ pages.Data = pages.f.wfs.bufPool.Get().([]byte)+ atomic.AddInt32(&counter, 1)+ glog.V(3).Infof("%s/%s acquire resource", pages.f.dir.Path, pages.f.Name, counter)+ }+if offset < pages.Offset || offset >= pages.Offset+int64(len(pages.Data)) ||pages.Offset+int64(len(pages.Data)) < offset+int64(len(data)) {// if the data is out of range,