aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2021-12-20 11:53:48 -0800
committerchrislu <chris.lu@gmail.com>2021-12-20 11:53:48 -0800
commitb21a67bbe67ba479d09ae74206c00ced16272449 (patch)
tree813c0c9cf8f85cdec56e778e6c02da79daee1727
parent4fd29dad868916d39d27b6d4a5184e73cc254ebb (diff)
downloadseaweedfs-b21a67bbe67ba479d09ae74206c00ced16272449.tar.xz
seaweedfs-b21a67bbe67ba479d09ae74206c00ced16272449.zip
add writer pattern object for later use
-rw-r--r--weed/filesys/page_writer/writer_pattern.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/weed/filesys/page_writer/writer_pattern.go b/weed/filesys/page_writer/writer_pattern.go
new file mode 100644
index 000000000..c7641c37f
--- /dev/null
+++ b/weed/filesys/page_writer/writer_pattern.go
@@ -0,0 +1,31 @@
+package page_writer
+
+type WriterPattern struct {
+ isStreaming bool
+ lastWriteOffset int64
+}
+
+// For streaming write: only cache the first chunk
+// For random write: fall back to temp file approach
+
+func NewWriterPattern() *WriterPattern {
+ return &WriterPattern{
+ isStreaming: true,
+ lastWriteOffset: 0,
+ }
+}
+
+func (rp *WriterPattern) MonitorWriteAt(offset int64, size int) {
+ if rp.lastWriteOffset > offset {
+ rp.isStreaming = false
+ }
+ rp.lastWriteOffset = offset
+}
+
+func (rp *WriterPattern) IsStreamingMode() bool {
+ return rp.isStreaming
+}
+
+func (rp *WriterPattern) IsRandomMode() bool {
+ return !rp.isStreaming
+}