2021-12-20 06:43:14 +00:00
|
|
|
package filer
|
|
|
|
|
|
|
|
type ReaderPattern struct {
|
2022-07-13 09:20:03 +00:00
|
|
|
isSequentialCounter int64
|
|
|
|
lastReadStopOffset int64
|
2021-12-20 06:43:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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{
|
2022-07-13 09:20:03 +00:00
|
|
|
isSequentialCounter: 0,
|
|
|
|
lastReadStopOffset: 0,
|
2021-12-20 06:43:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rp *ReaderPattern) MonitorReadAt(offset int64, size int) {
|
2022-07-13 09:20:03 +00:00
|
|
|
if rp.lastReadStopOffset == offset {
|
|
|
|
rp.isSequentialCounter++
|
|
|
|
} else {
|
|
|
|
rp.isSequentialCounter--
|
2021-12-20 06:43:14 +00:00
|
|
|
}
|
2022-07-13 09:20:03 +00:00
|
|
|
rp.lastReadStopOffset = offset + int64(size)
|
2021-12-20 06:43:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (rp *ReaderPattern) IsRandomMode() bool {
|
2022-07-13 09:20:03 +00:00
|
|
|
return rp.isSequentialCounter >= 0
|
2021-12-20 06:43:14 +00:00
|
|
|
}
|