mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-01-18 06:30:07 +08:00
writer pattern: similar changes to reader pattern
This commit is contained in:
parent
6e90f7bdd0
commit
289402a741
@ -1,8 +1,8 @@
|
|||||||
package mount
|
package mount
|
||||||
|
|
||||||
type WriterPattern struct {
|
type WriterPattern struct {
|
||||||
isStreaming bool
|
isSequentialCounter int64
|
||||||
lastWriteOffset int64
|
lastWriteStopOffset int64
|
||||||
chunkSize int64
|
chunkSize int64
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -12,33 +12,21 @@ type WriterPattern struct {
|
|||||||
|
|
||||||
func NewWriterPattern(chunkSize int64) *WriterPattern {
|
func NewWriterPattern(chunkSize int64) *WriterPattern {
|
||||||
return &WriterPattern{
|
return &WriterPattern{
|
||||||
isStreaming: true,
|
isSequentialCounter: 0,
|
||||||
lastWriteOffset: -1,
|
lastWriteStopOffset: 0,
|
||||||
chunkSize: chunkSize,
|
chunkSize: chunkSize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rp *WriterPattern) MonitorWriteAt(offset int64, size int) {
|
func (rp *WriterPattern) MonitorWriteAt(offset int64, size int) {
|
||||||
if rp.lastWriteOffset > offset {
|
if rp.lastWriteStopOffset == offset {
|
||||||
rp.isStreaming = false
|
rp.isSequentialCounter++
|
||||||
|
} else {
|
||||||
|
rp.isSequentialCounter--
|
||||||
}
|
}
|
||||||
if rp.lastWriteOffset == -1 {
|
rp.lastWriteStopOffset = offset + int64(size)
|
||||||
if offset != 0 {
|
|
||||||
rp.isStreaming = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rp.lastWriteOffset = offset
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rp *WriterPattern) IsStreamingMode() bool {
|
func (rp *WriterPattern) IsSequentialMode() bool {
|
||||||
return rp.isStreaming
|
return rp.isSequentialCounter >= 0
|
||||||
}
|
|
||||||
|
|
||||||
func (rp *WriterPattern) IsRandomMode() bool {
|
|
||||||
return !rp.isStreaming
|
|
||||||
}
|
|
||||||
|
|
||||||
func (rp *WriterPattern) Reset() {
|
|
||||||
rp.isStreaming = true
|
|
||||||
rp.lastWriteOffset = -1
|
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ func (wfs *WFS) Write(cancel <-chan struct{}, in *fuse.WriteIn, data []byte) (wr
|
|||||||
entry.Attributes.FileSize = uint64(max(offset+int64(len(data)), int64(entry.Attributes.FileSize)))
|
entry.Attributes.FileSize = uint64(max(offset+int64(len(data)), int64(entry.Attributes.FileSize)))
|
||||||
// glog.V(4).Infof("%v write [%d,%d) %d", fh.f.fullpath(), req.Offset, req.Offset+int64(len(req.Data)), len(req.Data))
|
// glog.V(4).Infof("%v write [%d,%d) %d", fh.f.fullpath(), req.Offset, req.Offset+int64(len(req.Data)), len(req.Data))
|
||||||
|
|
||||||
fh.dirtyPages.AddPage(offset, data, fh.dirtyPages.writerPattern.IsStreamingMode())
|
fh.dirtyPages.AddPage(offset, data, fh.dirtyPages.writerPattern.IsSequentialMode())
|
||||||
|
|
||||||
written = uint32(len(data))
|
written = uint32(len(data))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user