diff options
| author | chrislu <chris.lu@gmail.com> | 2022-06-05 18:15:06 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2022-06-05 18:15:06 -0700 |
| commit | d65bb2c6df1a21ff2833717a16e549de971316b7 (patch) | |
| tree | f9a75a805021af5c5cc54fb5605c7ed25d1151fb /weed/mount/filehandle.go | |
| parent | 746092a60b3cefbe9617fe5f7e5a9a8d61fb8d13 (diff) | |
| download | seaweedfs-d65bb2c6df1a21ff2833717a16e549de971316b7.tar.xz seaweedfs-d65bb2c6df1a21ff2833717a16e549de971316b7.zip | |
mount: file handle locks entry better
related to https://github.com/chrislusf/seaweedfs/issues/2952
Diffstat (limited to 'weed/mount/filehandle.go')
| -rw-r--r-- | weed/mount/filehandle.go | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/weed/mount/filehandle.go b/weed/mount/filehandle.go index 8ce31a078..49918c104 100644 --- a/weed/mount/filehandle.go +++ b/weed/mount/filehandle.go @@ -13,12 +13,12 @@ import ( type FileHandleId uint64 type FileHandle struct { - fh FileHandleId - counter int64 - entry *filer_pb.Entry - chunkAddLock sync.Mutex - inode uint64 - wfs *WFS + fh FileHandleId + counter int64 + entry *filer_pb.Entry + entryLock sync.Mutex + inode uint64 + wfs *WFS // cache file has been written to dirtyMetadata bool @@ -53,7 +53,20 @@ func (fh *FileHandle) FullPath() util.FullPath { return fp } -func (fh *FileHandle) addChunks(chunks []*filer_pb.FileChunk) { +func (fh *FileHandle) GetEntry() *filer_pb.Entry { + fh.entryLock.Lock() + defer fh.entryLock.Unlock() + return fh.entry +} +func (fh *FileHandle) SetEntry(entry *filer_pb.Entry) { + fh.entryLock.Lock() + defer fh.entryLock.Unlock() + fh.entry = entry +} + +func (fh *FileHandle) AddChunks(chunks []*filer_pb.FileChunk) { + fh.entryLock.Lock() + defer fh.entryLock.Unlock() // find the earliest incoming chunk newChunks := chunks @@ -82,10 +95,8 @@ func (fh *FileHandle) addChunks(chunks []*filer_pb.FileChunk) { glog.V(4).Infof("%s existing %d chunks adds %d more", fh.FullPath(), len(fh.entry.Chunks), len(chunks)) - fh.chunkAddLock.Lock() fh.entry.Chunks = append(fh.entry.Chunks, newChunks...) fh.entryViewCache = nil - fh.chunkAddLock.Unlock() } func (fh *FileHandle) Release() { |
