1
0
Fork 0
mirror of https://github.com/chrislusf/seaweedfs synced 2024-05-30 15:20:10 +02:00
seaweedfs/weed/mount/page_writer_pattern.go

33 lines
783 B
Go

package mount
type WriterPattern struct {
isSequentialCounter int64
lastWriteStopOffset int64
chunkSize int64
}
// 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{
isSequentialCounter: 0,
lastWriteStopOffset: 0,
chunkSize: chunkSize,
}
}
func (rp *WriterPattern) MonitorWriteAt(offset int64, size int) {
if rp.lastWriteStopOffset == offset {
rp.isSequentialCounter++
} else {
rp.isSequentialCounter--
}
rp.lastWriteStopOffset = offset + int64(size)
}
func (rp *WriterPattern) IsSequentialMode() bool {
return rp.isSequentialCounter >= 0
}