SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
atomic operation
chrislu301b49b63f52
diff --git a/weed/mount/page_writer_pattern.go b/weed/mount/page_writer_pattern.goindex 4b4a816ce2..d0c3c417ca 100644--- a/weed/mount/page_writer_pattern.go+++ b/weed/mount/page_writer_pattern.go@@ -1,5 +1,7 @@package mount+import "sync/atomic"+type WriterPattern struct {isSequentialCounter int64lastWriteStopOffset int64@@ -20,18 +22,19 @@ func NewWriterPattern(chunkSize int64) *WriterPattern {}func (rp *WriterPattern) MonitorWriteAt(offset int64, size int) {- if rp.lastWriteStopOffset == offset {- if rp.isSequentialCounter < ModeChangeLimit {- rp.isSequentialCounter+++ lastOffset := atomic.SwapInt64(&rp.lastWriteStopOffset, offset+int64(size))+ counter := atomic.LoadInt64(&rp.isSequentialCounter)+ if lastOffset == offset {+ if counter < ModeChangeLimit {+ atomic.AddInt64(&rp.isSequentialCounter, 1)}} else {- if rp.isSequentialCounter > -ModeChangeLimit {- rp.isSequentialCounter--+ if counter > -ModeChangeLimit {+ atomic.AddInt64(&rp.isSequentialCounter, -1)}}- rp.lastWriteStopOffset = offset + int64(size)}func (rp *WriterPattern) IsSequentialMode() bool {- return rp.isSequentialCounter >= 0+ return atomic.LoadInt64(&rp.isSequentialCounter) >= 0}