diff options
Diffstat (limited to 'weed/filesys/page_writer_pattern.go')
| -rw-r--r-- | weed/filesys/page_writer_pattern.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/weed/filesys/page_writer_pattern.go b/weed/filesys/page_writer_pattern.go new file mode 100644 index 000000000..fdd796215 --- /dev/null +++ b/weed/filesys/page_writer_pattern.go @@ -0,0 +1,44 @@ +package filesys + +import "fmt" + +type WriterPattern struct { + isStreaming bool + lastWriteOffset int64 + chunkSize int64 + fileName string +} + +// 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(fileName string, chunkSize int64) *WriterPattern { + return &WriterPattern{ + isStreaming: true, + lastWriteOffset: 0, + chunkSize: chunkSize, + fileName: fileName, + } +} + +func (rp *WriterPattern) MonitorWriteAt(offset int64, size int) { + if rp.lastWriteOffset == 0 { + } + if rp.lastWriteOffset > offset { + if rp.isStreaming { + fmt.Printf("file %s ==> non streaming at [%d,%d)\n", rp.fileName, offset, offset+int64(size)) + } + fmt.Printf("write %s [%d,%d)\n", rp.fileName, offset, offset+int64(size)) + rp.isStreaming = false + } + rp.lastWriteOffset = offset +} + +func (rp *WriterPattern) IsStreamingMode() bool { + return rp.isStreaming +} + +func (rp *WriterPattern) IsRandomMode() bool { + return !rp.isStreaming +} |
