aboutsummaryrefslogtreecommitdiff
path: root/weed/mount
diff options
context:
space:
mode:
authorzemul <zemul@foxmail.com>2023-04-14 13:32:45 +0800
committerGitHub <noreply@github.com>2023-04-13 22:32:45 -0700
commit0122e022eac2fea92b68af89dbbe175325359771 (patch)
tree8a0182a14d12a339dca7df2924ac92f1024e7738 /weed/mount
parent5614ad0000e443f891d9c58706d6b7ce1d305afa (diff)
downloadseaweedfs-0122e022eac2fea92b68af89dbbe175325359771.tar.xz
seaweedfs-0122e022eac2fea92b68af89dbbe175325359771.zip
Mount concurrent read (#4400)
* fix:mount deadlock * feat: concurrent read * fix * Remove useless code * fix --------- Co-authored-by: zemul <zhouzemiao@ihuman.com>
Diffstat (limited to 'weed/mount')
-rw-r--r--weed/mount/filehandle.go7
-rw-r--r--weed/mount/filehandle_read.go4
-rw-r--r--weed/mount/weedfs_dir_lookup.go4
-rw-r--r--weed/mount/weedfs_file_lseek.go8
-rw-r--r--weed/mount/weedfs_file_read.go4
5 files changed, 15 insertions, 12 deletions
diff --git a/weed/mount/filehandle.go b/weed/mount/filehandle.go
index 67298b047..fe038a258 100644
--- a/weed/mount/filehandle.go
+++ b/weed/mount/filehandle.go
@@ -17,7 +17,7 @@ type FileHandle struct {
fh FileHandleId
counter int64
entry *LockedEntry
- entryLock sync.Mutex
+ entryLock sync.RWMutex
entryChunkGroup *filer.ChunkGroup
inode uint64
wfs *WFS
@@ -28,7 +28,7 @@ type FileHandle struct {
reader *filer.ChunkReadAt
contentType string
handle uint64
- sync.Mutex
+ sync.RWMutex
isDeleted bool
@@ -103,6 +103,9 @@ func (fh *FileHandle) AddChunks(chunks []*filer_pb.FileChunk) {
}
func (fh *FileHandle) ReleaseHandle() {
+ fh.Lock()
+ defer fh.Unlock()
+
fh.entryLock.Lock()
defer fh.entryLock.Unlock()
diff --git a/weed/mount/filehandle_read.go b/weed/mount/filehandle_read.go
index 0684d0ba4..7b2629c13 100644
--- a/weed/mount/filehandle_read.go
+++ b/weed/mount/filehandle_read.go
@@ -23,8 +23,8 @@ func (fh *FileHandle) readFromDirtyPages(buff []byte, startOffset int64, tsNs in
}
func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, int64, error) {
- fh.entryLock.Lock()
- defer fh.entryLock.Unlock()
+ fh.entryLock.RLock()
+ defer fh.entryLock.RUnlock()
fileFullPath := fh.FullPath()
diff --git a/weed/mount/weedfs_dir_lookup.go b/weed/mount/weedfs_dir_lookup.go
index 2d3ea8ae5..e646b06a9 100644
--- a/weed/mount/weedfs_dir_lookup.go
+++ b/weed/mount/weedfs_dir_lookup.go
@@ -58,12 +58,12 @@ func (wfs *WFS) Lookup(cancel <-chan struct{}, header *fuse.InHeader, name strin
inode := wfs.inodeToPath.Lookup(fullFilePath, localEntry.Crtime.Unix(), localEntry.IsDirectory(), len(localEntry.HardLinkId) > 0, localEntry.Inode, true)
if fh, found := wfs.fhmap.FindFileHandle(inode); found {
- fh.entryLock.Lock()
+ fh.entryLock.RLock()
if entry := fh.GetEntry(); entry != nil {
glog.V(4).Infof("lookup opened file %s size %d", dirPath.Child(localEntry.Name()), filer.FileSize(entry))
localEntry = filer.FromPbEntry(string(dirPath), entry)
}
- fh.entryLock.Unlock()
+ fh.entryLock.RUnlock()
}
wfs.outputFilerEntry(out, inode, localEntry)
diff --git a/weed/mount/weedfs_file_lseek.go b/weed/mount/weedfs_file_lseek.go
index 93fc65247..9dfc4d4f1 100644
--- a/weed/mount/weedfs_file_lseek.go
+++ b/weed/mount/weedfs_file_lseek.go
@@ -35,10 +35,10 @@ func (wfs *WFS) Lseek(cancel <-chan struct{}, in *fuse.LseekIn, out *fuse.LseekO
}
// lock the file until the proper offset was calculated
- fh.Lock()
- defer fh.Unlock()
- fh.entryLock.Lock()
- defer fh.entryLock.Unlock()
+ fh.RLock()
+ defer fh.RUnlock()
+ fh.entryLock.RLock()
+ defer fh.entryLock.RUnlock()
fileSize := int64(filer.FileSize(fh.GetEntry()))
offset := max(int64(in.Offset), 0)
diff --git a/weed/mount/weedfs_file_read.go b/weed/mount/weedfs_file_read.go
index cedece137..95377d9e9 100644
--- a/weed/mount/weedfs_file_read.go
+++ b/weed/mount/weedfs_file_read.go
@@ -41,8 +41,8 @@ func (wfs *WFS) Read(cancel <-chan struct{}, in *fuse.ReadIn, buff []byte) (fuse
return nil, fuse.ENOENT
}
- fh.Lock()
- defer fh.Unlock()
+ fh.RLock()
+ defer fh.RUnlock()
offset := int64(in.Offset)
totalRead, err := readDataByFileHandle(buff, fh, offset)