mount: different write strategy for streaming write and random write

This commit is contained in:
chrislu
2021-12-21 17:28:55 -08:00
parent 4b8dcff448
commit 9a73319b45
4 changed files with 95 additions and 3 deletions

View File

@@ -0,0 +1 @@
package page_writer

View File

@@ -1,31 +0,0 @@
package page_writer
type WriterPattern struct {
isStreaming bool
lastWriteOffset int64
}
// For streaming write: only cache the first chunk
// For random write: fall back to temp file approach
func NewWriterPattern() *WriterPattern {
return &WriterPattern{
isStreaming: true,
lastWriteOffset: 0,
}
}
func (rp *WriterPattern) MonitorWriteAt(offset int64, size int) {
if rp.lastWriteOffset > offset {
rp.isStreaming = false
}
rp.lastWriteOffset = offset
}
func (rp *WriterPattern) IsStreamingMode() bool {
return rp.isStreaming
}
func (rp *WriterPattern) IsRandomMode() bool {
return !rp.isStreaming
}