2022-03-14 09:17:35 +08:00
|
|
|
package mount
|
|
|
|
|
|
|
|
type WriterPattern struct {
|
2022-07-13 17:30:44 +08:00
|
|
|
isSequentialCounter int64
|
|
|
|
lastWriteStopOffset int64
|
|
|
|
chunkSize int64
|
2022-03-14 09:17:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// For streaming write: only cache the first chunk
|
|
|
|
// For random write: fall back to temp file approach
|
|
|
|
// writes can only change from streaming mode to non-streaming mode
|
|
|
|
|
|
|
|
func NewWriterPattern(chunkSize int64) *WriterPattern {
|
|
|
|
return &WriterPattern{
|
2022-07-13 17:30:44 +08:00
|
|
|
isSequentialCounter: 0,
|
|
|
|
lastWriteStopOffset: 0,
|
|
|
|
chunkSize: chunkSize,
|
2022-03-14 09:17:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rp *WriterPattern) MonitorWriteAt(offset int64, size int) {
|
2022-07-13 17:30:44 +08:00
|
|
|
if rp.lastWriteStopOffset == offset {
|
|
|
|
rp.isSequentialCounter++
|
|
|
|
} else {
|
|
|
|
rp.isSequentialCounter--
|
2022-03-14 09:17:35 +08:00
|
|
|
}
|
2022-07-13 17:30:44 +08:00
|
|
|
rp.lastWriteStopOffset = offset + int64(size)
|
2022-03-14 09:17:35 +08:00
|
|
|
}
|
|
|
|
|
2022-07-13 17:30:44 +08:00
|
|
|
func (rp *WriterPattern) IsSequentialMode() bool {
|
|
|
|
return rp.isSequentialCounter >= 0
|
2022-03-14 09:17:35 +08:00
|
|
|
}
|