mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-11-29 14:31:30 +08:00
083d8e9ece
this should improve streaming write performance, which is common in many cases, e.g., copying large files.
This is additional to improved random read write operations: 3e69d19380...19084d8791
45 lines
931 B
Go
45 lines
931 B
Go
package filesys
|
|
|
|
type WriterPattern struct {
|
|
isStreaming bool
|
|
lastWriteOffset 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{
|
|
isStreaming: true,
|
|
lastWriteOffset: -1,
|
|
chunkSize: chunkSize,
|
|
}
|
|
}
|
|
|
|
func (rp *WriterPattern) MonitorWriteAt(offset int64, size int) {
|
|
if rp.lastWriteOffset > offset {
|
|
rp.isStreaming = false
|
|
}
|
|
if rp.lastWriteOffset == -1 {
|
|
if offset != 0 {
|
|
rp.isStreaming = false
|
|
}
|
|
}
|
|
rp.lastWriteOffset = offset
|
|
}
|
|
|
|
func (rp *WriterPattern) IsStreamingMode() bool {
|
|
return rp.isStreaming
|
|
}
|
|
|
|
func (rp *WriterPattern) IsRandomMode() bool {
|
|
return !rp.isStreaming
|
|
}
|
|
|
|
func (rp *WriterPattern) Reset() {
|
|
rp.isStreaming = true
|
|
rp.lastWriteOffset = -1
|
|
}
|