mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-04 02:57:44 +01:00
Fix a few data races when reading files in mount (#3527)
This commit is contained in:
1 parent
f5156cf3a8
commit
5df105b1f9
6 files changed
+70
-37
No files matched your search
@@ -1,5 +1,9 @@
|
||||
package filer
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
type ReaderPattern struct {
|
||||
isSequentialCounter int64
|
||||
lastReadStopOffset int64
|
||||
@@ -18,18 +22,20 @@ func NewReaderPattern() *ReaderPattern {
|
||||
}
|
||||
|
||||
func (rp *ReaderPattern) MonitorReadAt(offset int64, size int) {
|
||||
if rp.lastReadStopOffset == offset {
|
||||
if rp.isSequentialCounter < ModeChangeLimit {
|
||||
rp.isSequentialCounter++
|
||||
lastOffset := atomic.SwapInt64(&rp.lastReadStopOffset, offset+int64(size))
|
||||
counter := atomic.LoadInt64(&rp.isSequentialCounter)
|
||||
|
||||
if lastOffset == offset {
|
||||
if counter < ModeChangeLimit {
|
||||
atomic.AddInt64(&rp.isSequentialCounter, 1)
|
||||
}
|
||||
} else {
|
||||
if rp.isSequentialCounter > -ModeChangeLimit {
|
||||
rp.isSequentialCounter--
|
||||
if counter > -ModeChangeLimit {
|
||||
atomic.AddInt64(&rp.isSequentialCounter, -1)
|
||||
}
|
||||
}
|
||||
rp.lastReadStopOffset = offset + int64(size)
|
||||
}
|
||||
|
||||
func (rp *ReaderPattern) IsRandomMode() bool {
|
||||
return rp.isSequentialCounter < 0
|
||||
return atomic.LoadInt64(&rp.isSequentialCounter) < 0
|
||||
}
|
||||
Reference in new issue
Block a user