aboutsummaryrefslogtreecommitdiff
path: root/weed/mount/filehandle.go
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2022-12-04 23:33:05 -0800
committerchrislu <chris.lu@gmail.com>2022-12-04 23:33:05 -0800
commit94bc9afd9d3f8e049219c1cdc9f0d6e0eb4cf456 (patch)
tree2dec30792acbe4600279d9df607d4d61677222fe /weed/mount/filehandle.go
parent2b783738d6d3b4b2810b4a3b3516d59a1b9edc46 (diff)
downloadseaweedfs-94bc9afd9d3f8e049219c1cdc9f0d6e0eb4cf456.tar.xz
seaweedfs-94bc9afd9d3f8e049219c1cdc9f0d6e0eb4cf456.zip
refactor: moved to locked entry
Diffstat (limited to 'weed/mount/filehandle.go')
-rw-r--r--weed/mount/filehandle.go40
1 files changed, 15 insertions, 25 deletions
diff --git a/weed/mount/filehandle.go b/weed/mount/filehandle.go
index c2a197da7..7281ede66 100644
--- a/weed/mount/filehandle.go
+++ b/weed/mount/filehandle.go
@@ -1,27 +1,23 @@
package mount
import (
- "golang.org/x/sync/semaphore"
- "math"
- "sync"
-
- "golang.org/x/exp/slices"
-
"github.com/seaweedfs/seaweedfs/weed/filer"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/seaweedfs/weed/util"
+ "golang.org/x/exp/slices"
+ "golang.org/x/sync/semaphore"
+ "math"
)
type FileHandleId uint64
type FileHandle struct {
- fh FileHandleId
- counter int64
- entry *filer_pb.Entry
- entryLock sync.Mutex
- inode uint64
- wfs *WFS
+ fh FileHandleId
+ counter int64
+ entry *LockedEntry
+ inode uint64
+ wfs *WFS
// cache file has been written to
dirtyMetadata bool
@@ -48,6 +44,9 @@ func newFileHandle(wfs *WFS, handleId FileHandleId, inode uint64, entry *filer_p
if entry != nil {
entry.Attributes.FileSize = filer.FileSize(entry)
}
+ fh.entry = &LockedEntry{
+ Entry: entry,
+ }
return fh
}
@@ -58,27 +57,18 @@ func (fh *FileHandle) FullPath() util.FullPath {
}
func (fh *FileHandle) GetEntry() *filer_pb.Entry {
- fh.entryLock.Lock()
- defer fh.entryLock.Unlock()
- return fh.entry
+ return fh.entry.GetEntry()
}
func (fh *FileHandle) SetEntry(entry *filer_pb.Entry) {
- fh.entryLock.Lock()
- defer fh.entryLock.Unlock()
- fh.entry = entry
+ fh.entry.SetEntry(entry)
}
func (fh *FileHandle) UpdateEntry(fn func(entry *filer_pb.Entry)) *filer_pb.Entry {
- fh.entryLock.Lock()
- defer fh.entryLock.Unlock()
- fn(fh.entry)
- return fh.entry
+ return fh.entry.UpdateEntry(fn)
}
func (fh *FileHandle) AddChunks(chunks []*filer_pb.FileChunk) {
- fh.entryLock.Lock()
- defer fh.entryLock.Unlock()
if fh.entry == nil {
return
@@ -107,7 +97,7 @@ func (fh *FileHandle) AddChunks(chunks []*filer_pb.FileChunk) {
glog.V(4).Infof("%s existing %d chunks adds %d more", fh.FullPath(), len(fh.entry.GetChunks()), len(chunks))
- fh.entry.Chunks = append(fh.entry.GetChunks(), newChunks...)
+ fh.entry.AppendChunks(newChunks)
fh.entryViewCache = nil
}