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.

31 lines
629 B

  1. package page_writer
  2. type WriterPattern struct {
  3. isStreaming bool
  4. lastWriteOffset int64
  5. }
  6. // For streaming write: only cache the first chunk
  7. // For random write: fall back to temp file approach
  8. func NewWriterPattern() *WriterPattern {
  9. return &WriterPattern{
  10. isStreaming: true,
  11. lastWriteOffset: 0,
  12. }
  13. }
  14. func (rp *WriterPattern) MonitorWriteAt(offset int64, size int) {
  15. if rp.lastWriteOffset > offset {
  16. rp.isStreaming = false
  17. }
  18. rp.lastWriteOffset = offset
  19. }
  20. func (rp *WriterPattern) IsStreamingMode() bool {
  21. return rp.isStreaming
  22. }
  23. func (rp *WriterPattern) IsRandomMode() bool {
  24. return !rp.isStreaming
  25. }