diff options
| author | zemul <zemul@foxmail.com> | 2023-04-14 13:32:45 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-13 22:32:45 -0700 |
| commit | 0122e022eac2fea92b68af89dbbe175325359771 (patch) | |
| tree | 8a0182a14d12a339dca7df2924ac92f1024e7738 /weed/filer | |
| parent | 5614ad0000e443f891d9c58706d6b7ce1d305afa (diff) | |
| download | seaweedfs-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/filer')
| -rw-r--r-- | weed/filer/filechunk_section.go | 30 | ||||
| -rw-r--r-- | weed/filer/interval_list.go | 6 | ||||
| -rw-r--r-- | weed/filer/reader_at.go | 8 |
3 files changed, 30 insertions, 14 deletions
diff --git a/weed/filer/filechunk_section.go b/weed/filer/filechunk_section.go index 11d6e631a..ba591d9ac 100644 --- a/weed/filer/filechunk_section.go +++ b/weed/filer/filechunk_section.go @@ -13,7 +13,8 @@ type FileChunkSection struct { visibleIntervals *IntervalList[*VisibleInterval] chunkViews *IntervalList[*ChunkView] reader *ChunkReadAt - lock sync.Mutex + lock sync.RWMutex + isPrepared bool } func NewFileChunkSection(si SectionIndex) *FileChunkSection { @@ -61,6 +62,19 @@ func removeGarbageChunks(section *FileChunkSection, garbageFileIds map[string]st } func (section *FileChunkSection) setupForRead(group *ChunkGroup, fileSize int64) { + if section.isPrepared { + section.reader.fileSize = fileSize + return + } + + section.lock.Lock() + defer section.lock.Unlock() + + if section.isPrepared { + section.reader.fileSize = fileSize + return + } + if section.visibleIntervals == nil { section.visibleIntervals = readResolvedChunks(section.chunks, int64(section.sectionIndex)*SectionSize, (int64(section.sectionIndex)+1)*SectionSize) section.chunks, _ = SeparateGarbageChunks(section.visibleIntervals, section.chunks) @@ -76,23 +90,25 @@ func (section *FileChunkSection) setupForRead(group *ChunkGroup, fileSize int64) if section.reader == nil { section.reader = NewChunkReaderAtFromClient(group.readerCache, section.chunkViews, min(int64(section.sectionIndex+1)*SectionSize, fileSize)) } + + section.isPrepared = true section.reader.fileSize = fileSize } func (section *FileChunkSection) readDataAt(group *ChunkGroup, fileSize int64, buff []byte, offset int64) (n int, tsNs int64, err error) { - section.lock.Lock() - defer section.lock.Unlock() section.setupForRead(group, fileSize) + section.lock.RLock() + defer section.lock.RUnlock() return section.reader.ReadAtWithTime(buff, offset) } func (section *FileChunkSection) DataStartOffset(group *ChunkGroup, offset int64, fileSize int64) int64 { - section.lock.Lock() - defer section.lock.Unlock() section.setupForRead(group, fileSize) + section.lock.RLock() + defer section.lock.RUnlock() for x := section.visibleIntervals.Front(); x != nil; x = x.Next { visible := x.Value @@ -108,10 +124,10 @@ func (section *FileChunkSection) DataStartOffset(group *ChunkGroup, offset int64 } func (section *FileChunkSection) NextStopOffset(group *ChunkGroup, offset int64, fileSize int64) int64 { - section.lock.Lock() - defer section.lock.Unlock() section.setupForRead(group, fileSize) + section.lock.RLock() + defer section.lock.RUnlock() isAfterOffset := false for x := section.visibleIntervals.Front(); x != nil; x = x.Next { diff --git a/weed/filer/interval_list.go b/weed/filer/interval_list.go index b3d2a76b9..27720231d 100644 --- a/weed/filer/interval_list.go +++ b/weed/filer/interval_list.go @@ -27,7 +27,7 @@ func (interval *Interval[T]) Size() int64 { type IntervalList[T IntervalValue] struct { head *Interval[T] tail *Interval[T] - Lock sync.Mutex + Lock sync.RWMutex } func NewIntervalList[T IntervalValue]() *IntervalList[T] { @@ -248,8 +248,8 @@ func (list *IntervalList[T]) overlayInterval(interval *Interval[T]) { } func (list *IntervalList[T]) Len() int { - list.Lock.Lock() - defer list.Lock.Unlock() + list.Lock.RLock() + defer list.Lock.RUnlock() var count int for t := list.head; t != nil; t = t.Next { diff --git a/weed/filer/reader_at.go b/weed/filer/reader_at.go index 3f32f2a3c..d475e6e11 100644 --- a/weed/filer/reader_at.go +++ b/weed/filer/reader_at.go @@ -106,8 +106,8 @@ func (c *ChunkReadAt) ReadAt(p []byte, offset int64) (n int, err error) { c.readerPattern.MonitorReadAt(offset, len(p)) - c.chunkViews.Lock.Lock() - defer c.chunkViews.Lock.Unlock() + c.chunkViews.Lock.RLock() + defer c.chunkViews.Lock.RUnlock() // glog.V(4).Infof("ReadAt [%d,%d) of total file size %d bytes %d chunk views", offset, offset+int64(len(p)), c.fileSize, len(c.chunkViews)) n, _, err = c.doReadAt(p, offset) @@ -118,8 +118,8 @@ func (c *ChunkReadAt) ReadAtWithTime(p []byte, offset int64) (n int, ts int64, e c.readerPattern.MonitorReadAt(offset, len(p)) - c.chunkViews.Lock.Lock() - defer c.chunkViews.Lock.Unlock() + c.chunkViews.Lock.RLock() + defer c.chunkViews.Lock.RUnlock() // glog.V(4).Infof("ReadAt [%d,%d) of total file size %d bytes %d chunk views", offset, offset+int64(len(p)), c.fileSize, len(c.chunkViews)) return c.doReadAt(p, offset) |
