mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
36 lines
790 B
Go
36 lines
790 B
Go
package filer
|
|
|
|
type ReaderPattern struct {
|
|
isSequentialCounter int64
|
|
lastReadStopOffset int64
|
|
}
|
|
|
|
const ModeChangeLimit = 3
|
|
|
|
// For streaming read: only cache the first chunk
|
|
// For random read: only fetch the requested range, instead of the whole chunk
|
|
|
|
func NewReaderPattern() *ReaderPattern {
|
|
return &ReaderPattern{
|
|
isSequentialCounter: 0,
|
|
lastReadStopOffset: 0,
|
|
}
|
|
}
|
|
|
|
func (rp *ReaderPattern) MonitorReadAt(offset int64, size int) {
|
|
if rp.lastReadStopOffset == offset {
|
|
if rp.isSequentialCounter < ModeChangeLimit {
|
|
rp.isSequentialCounter++
|
|
}
|
|
} else {
|
|
if rp.isSequentialCounter > -ModeChangeLimit {
|
|
rp.isSequentialCounter--
|
|
}
|
|
}
|
|
rp.lastReadStopOffset = offset + int64(size)
|
|
}
|
|
|
|
func (rp *ReaderPattern) IsRandomMode() bool {
|
|
return rp.isSequentialCounter < 0
|
|
}
|