aboutsummaryrefslogtreecommitdiff
path: root/weed/filer/reader_pattern.go
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2022-08-26 16:49:51 -0700
committerchrislu <chris.lu@gmail.com>2022-08-26 16:49:51 -0700
commit8dae81c5edaea2b25a79d49c4a08ffadfdc6fddc (patch)
treece1ef0be521398d06255a97eb531d97b7f940b47 /weed/filer/reader_pattern.go
parente0f4366f4ca3259bfe582fb1dd8951f2005160ab (diff)
parent5df105b1f94b8776d18159ae213da39299e2ea37 (diff)
downloadseaweedfs-8dae81c5edaea2b25a79d49c4a08ffadfdc6fddc.tar.xz
seaweedfs-8dae81c5edaea2b25a79d49c4a08ffadfdc6fddc.zip
Merge branch 'master' of https://github.com/seaweedfs/seaweedfs
Diffstat (limited to 'weed/filer/reader_pattern.go')
-rw-r--r--weed/filer/reader_pattern.go20
1 files changed, 13 insertions, 7 deletions
diff --git a/weed/filer/reader_pattern.go b/weed/filer/reader_pattern.go
index e32f7fc2d..b0906e99f 100644
--- a/weed/filer/reader_pattern.go
+++ b/weed/filer/reader_pattern.go
@@ -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
}