chrislu
3 years ago
8 changed files with 82 additions and 25 deletions
-
4weed/mount/dirty_pages_chunked.go
-
10weed/mount/page_writer.go
-
2weed/mount/page_writer/dirty_pages.go
-
8weed/mount/page_writer/page_chunk_swapfile.go
-
17weed/mount/page_writer/upload_pipeline.go
-
2weed/mount/page_writer/upload_pipeline_test.go
-
44weed/mount/page_writer_pattern.go
-
4weed/mount/weedfs_file_write.go
@ -0,0 +1,44 @@ |
|||||
|
package mount |
||||
|
|
||||
|
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 |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue