Skip to content

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.

refactor

Chris Lu735e65be17c7
diff --git a/weed/filesys/dirty_page.go b/weed/filesys/dirty_page.go
index 0332629adc..ab191a07a6 100644
--- a/weed/filesys/dirty_page.go
+++ b/weed/filesys/dirty_page.go
@@ -14,7 +14,7 @@ import (
type ContinuousDirtyPages struct {
intervals *ContinuousIntervals
f *File
- fh *FileHandle
+ writeOnly bool
writeWaitGroup sync.WaitGroup
chunkAddLock sync.Mutex
lastErr error
@@ -22,10 +22,11 @@ type ContinuousDirtyPages struct {
replication string
}
-func newDirtyPages(file *File) *ContinuousDirtyPages {
+func newDirtyPages(file *File, writeOnly bool) *ContinuousDirtyPages {
dirtyPages := &ContinuousDirtyPages{
intervals: &ContinuousIntervals{},
f: file,
+ writeOnly: writeOnly,
}
return dirtyPages
}
@@ -106,7 +107,7 @@ func (pages *ContinuousDirtyPages) saveToStorage(reader io.Reader, offset int64,
defer pages.writeWaitGroup.Done()
reader = io.LimitReader(reader, size)
- chunk, collection, replication, err := pages.f.wfs.saveDataAsChunk(pages.f.fullpath(), pages.fh.writeOnly)(reader, pages.f.Name, offset)
+ chunk, collection, replication, err := pages.f.wfs.saveDataAsChunk(pages.f.fullpath(), pages.writeOnly)(reader, pages.f.Name, offset)
if err != nil {
glog.V(0).Infof("%s saveToStorage [%d,%d): %v", pages.f.fullpath(), offset, offset+size, err)
pages.lastErr = err
diff --git a/weed/filesys/filehandle.go b/weed/filesys/filehandle.go
index e66e340b3f..3e0567dee6 100644
--- a/weed/filesys/filehandle.go
+++ b/weed/filesys/filehandle.go
@@ -35,14 +35,13 @@ type FileHandle struct {
writeOnly bool
}
-func newFileHandle(file *File, uid, gid uint32) *FileHandle {
+func newFileHandle(file *File, uid, gid uint32, writeOnly bool) *FileHandle {
fh := &FileHandle{
f: file,
- dirtyPages: newDirtyPages(file),
+ dirtyPages: newDirtyPages(file, writeOnly),
Uid: uid,
Gid: gid,
}
- fh.dirtyPages.fh = fh
entry := fh.f.getEntry()
if entry != nil {
entry.Attributes.FileSize = filer.FileSize(entry)
diff --git a/weed/filesys/wfs.go b/weed/filesys/wfs.go
index fcce7d9ccd..c71931b022 100644
--- a/weed/filesys/wfs.go
+++ b/weed/filesys/wfs.go
@@ -159,8 +159,7 @@ func (wfs *WFS) AcquireHandle(file *File, uid, gid uint32, writeOnly bool) (file
entry, _ := file.maybeLoadEntry(context.Background())
file.entry = entry
- fileHandle = newFileHandle(file, uid, gid)
- fileHandle.writeOnly = writeOnly
+ fileHandle = newFileHandle(file, uid, gid, writeOnly)
file.isOpen++
wfs.handlesLock.Lock()