You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
783 B

  1. package mount
  2. type WriterPattern struct {
  3. isSequentialCounter int64
  4. lastWriteStopOffset int64
  5. chunkSize int64
  6. }
  7. // For streaming write: only cache the first chunk
  8. // For random write: fall back to temp file approach
  9. // writes can only change from streaming mode to non-streaming mode
  10. func NewWriterPattern(chunkSize int64) *WriterPattern {
  11. return &WriterPattern{
  12. isSequentialCounter: 0,
  13. lastWriteStopOffset: 0,
  14. chunkSize: chunkSize,
  15. }
  16. }
  17. func (rp *WriterPattern) MonitorWriteAt(offset int64, size int) {
  18. if rp.lastWriteStopOffset == offset {
  19. rp.isSequentialCounter++
  20. } else {
  21. rp.isSequentialCounter--
  22. }
  23. rp.lastWriteStopOffset = offset + int64(size)
  24. }
  25. func (rp *WriterPattern) IsSequentialMode() bool {
  26. return rp.isSequentialCounter >= 0
  27. }