diff options
| author | chrislu <chris.lu@gmail.com> | 2022-01-15 05:45:29 -0800 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2022-01-15 05:45:29 -0800 |
| commit | 1bd6d289d48ea3ae3c1461bf090ce0ffa6f2505f (patch) | |
| tree | 50983443038b5c4f0fab037febd136037d54f7a3 | |
| parent | 2bfeb5d1c81744c7aafacee84e15f25f87c50614 (diff) | |
| download | seaweedfs-1bd6d289d48ea3ae3c1461bf090ce0ffa6f2505f.tar.xz seaweedfs-1bd6d289d48ea3ae3c1461bf090ce0ffa6f2505f.zip | |
better locking on file handle
| -rw-r--r-- | weed/filesys/filehandle.go | 12 | ||||
| -rw-r--r-- | weed/filesys/wfs.go | 10 |
2 files changed, 5 insertions, 17 deletions
diff --git a/weed/filesys/filehandle.go b/weed/filesys/filehandle.go index 64da38bcf..738423b6a 100644 --- a/weed/filesys/filehandle.go +++ b/weed/filesys/filehandle.go @@ -26,7 +26,6 @@ type FileHandle struct { contentType string handle uint64 sync.Mutex - sync.WaitGroup f *File RequestId fuse.RequestID // unique ID for request @@ -63,9 +62,6 @@ var _ = fs.HandleReleaser(&FileHandle{}) func (fh *FileHandle) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { - fh.Add(1) - defer fh.Done() - fh.Lock() defer fh.Unlock() @@ -173,9 +169,6 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, error) { // Write to the file handle func (fh *FileHandle) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error { - fh.Add(1) - defer fh.Done() - fh.dirtyPages.writerPattern.MonitorWriteAt(req.Offset, len(req.Data)) fh.Lock() @@ -217,8 +210,6 @@ func (fh *FileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) err glog.V(4).Infof("Release %v fh %d open=%d", fh.f.fullpath(), fh.handle, fh.f.isOpen) - fh.Wait() - fh.f.wfs.handlesLock.Lock() fh.f.isOpen-- fh.f.wfs.handlesLock.Unlock() @@ -250,9 +241,6 @@ func (fh *FileHandle) Flush(ctx context.Context, req *fuse.FlushRequest) error { return nil } - fh.Add(1) - defer fh.Done() - fh.Lock() defer fh.Unlock() diff --git a/weed/filesys/wfs.go b/weed/filesys/wfs.go index f6a6031d2..54eb9064b 100644 --- a/weed/filesys/wfs.go +++ b/weed/filesys/wfs.go @@ -187,15 +187,15 @@ func (wfs *WFS) Fsync(file *File, header fuse.Header) error { existingHandle, found := wfs.handles[inodeId] wfs.handlesLock.Unlock() - if found && existingHandle != nil && existingHandle.f.isOpen > 0 { - - existingHandle.Add(1) - defer existingHandle.Done() + if found && existingHandle != nil { existingHandle.Lock() defer existingHandle.Unlock() - return existingHandle.doFlush(context.Background(), header) + if existingHandle.f.isOpen > 0 { + return existingHandle.doFlush(context.Background(), header) + } + } return nil |
