aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2021-03-22 16:22:19 -0700
committerChris Lu <chris.lu@gmail.com>2021-03-22 16:22:19 -0700
commit288369cfc78b2e8d9d2f64a6769c9ce3f5e8ecc9 (patch)
treef82639a4fa29330f03746be020f13a30c5deb520
parent5d931eff2727be10ad01cd2920f8e47cf034e895 (diff)
downloadseaweedfs-288369cfc78b2e8d9d2f64a6769c9ce3f5e8ecc9.tar.xz
seaweedfs-288369cfc78b2e8d9d2f64a6769c9ce3f5e8ecc9.zip
mount: release resources when Forget() is called
address https://github.com/chrislusf/seaweedfs/issues/1929
-rw-r--r--weed/filesys/file.go23
-rw-r--r--weed/filesys/filehandle.go11
2 files changed, 19 insertions, 15 deletions
diff --git a/weed/filesys/file.go b/weed/filesys/file.go
index da93e0fae..58605f2f1 100644
--- a/weed/filesys/file.go
+++ b/weed/filesys/file.go
@@ -151,7 +151,7 @@ func (file *File) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *f
}
entry.Chunks = chunks
file.entryViewCache, _ = filer.NonOverlappingVisibleIntervals(file.wfs.LookupFn(), chunks)
- file.reader = nil
+ file.setReader(nil)
}
entry.Attributes.FileSize = req.Size
file.dirtyMetadata = true
@@ -261,6 +261,8 @@ func (file *File) Forget() {
t := util.NewFullPath(file.dir.FullPath(), file.Name)
glog.V(4).Infof("Forget file %s", t)
file.wfs.fsNodeCache.DeleteFsNode(t)
+ file.wfs.ReleaseHandle(t, 0)
+ file.setReader(nil)
}
func (file *File) maybeLoadEntry(ctx context.Context) (entry *filer_pb.Entry, err error) {
@@ -280,9 +282,6 @@ func (file *File) maybeLoadEntry(ctx context.Context) (entry *filer_pb.Entry, er
return entry, err
}
if entry != nil {
- if entry.Attributes == nil {
- entry.Attributes = &filer_pb.FuseAttributes{}
- }
file.setEntry(entry)
} else {
glog.Warningf("maybeLoadEntry not found entry %s/%s: %v", file.dir.FullPath(), file.Name, err)
@@ -330,19 +329,29 @@ func (file *File) addChunks(chunks []*filer_pb.FileChunk) {
file.entryViewCache = filer.MergeIntoVisibles(file.entryViewCache, chunk)
}
- file.reader = nil
+ file.setReader(nil)
glog.V(4).Infof("%s existing %d chunks adds %d more", file.fullpath(), len(entry.Chunks), len(chunks))
entry.Chunks = append(entry.Chunks, newChunks...)
}
+func (file *File) setReader(reader io.ReaderAt) {
+ r := file.reader
+ if r != nil {
+ if closer, ok := r.(io.Closer); ok {
+ closer.Close()
+ }
+ }
+ file.reader = reader
+}
+
func (file *File) setEntry(entry *filer_pb.Entry) {
file.entryLock.Lock()
defer file.entryLock.Unlock()
file.entry = entry
file.entryViewCache, _ = filer.NonOverlappingVisibleIntervals(file.wfs.LookupFn(), entry.Chunks)
- file.reader = nil
+ file.setReader(nil)
}
func (file *File) clearEntry() {
@@ -350,7 +359,7 @@ func (file *File) clearEntry() {
defer file.entryLock.Unlock()
file.entry = nil
file.entryViewCache = nil
- file.reader = nil
+ file.setReader(nil)
}
func (file *File) saveEntry(entry *filer_pb.Entry) error {
diff --git a/weed/filesys/filehandle.go b/weed/filesys/filehandle.go
index 25eaf7033..53c1c23d5 100644
--- a/weed/filesys/filehandle.go
+++ b/weed/filesys/filehandle.go
@@ -130,7 +130,7 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, error) {
if chunkResolveErr != nil {
return 0, fmt.Errorf("fail to resolve chunk manifest: %v", chunkResolveErr)
}
- fh.f.reader = nil
+ fh.f.setReader(nil)
}
reader := fh.f.reader
@@ -138,7 +138,7 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, error) {
chunkViews := filer.ViewFromVisibleIntervals(fh.f.entryViewCache, 0, math.MaxInt64)
reader = filer.NewChunkReaderAtFromClient(fh.f.wfs.LookupFn(), chunkViews, fh.f.wfs.chunkCache, fileSize)
}
- fh.f.reader = reader
+ fh.f.setReader(reader)
totalRead, err := reader.ReadAt(buff, offset)
@@ -207,12 +207,7 @@ func (fh *FileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) err
fh.f.isOpen--
fh.f.wfs.ReleaseHandle(fh.f.fullpath(), fuse.HandleID(fh.handle))
- if closer, ok := fh.f.reader.(io.Closer); ok {
- if closer != nil {
- closer.Close()
- }
- }
- fh.f.reader = nil
+ fh.f.setReader(nil)
}
return nil