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
refactoring to use atomic bool
chrislu3e9c32a3f0e2
diff --git a/weed/util/log_buffer/log_buffer.go b/weed/util/log_buffer/log_buffer.goindex 2d12a5bf29..bd124908eb 100644--- a/weed/util/log_buffer/log_buffer.go+++ b/weed/util/log_buffer/log_buffer.go@@ -3,6 +3,7 @@ package log_bufferimport ("bytes""sync"+ "sync/atomic""time""google.golang.org/protobuf/proto"@@ -34,7 +35,7 @@ type LogBuffer struct {flushInterval time.DurationflushFn func(startTime, stopTime time.Time, buf []byte)notifyFn func()- isStopping bool+ isStopping *atomic.BoolflushChan chan *dataToFlushlastTsNs int64sync.RWMutex@@ -50,6 +51,7 @@ func NewLogBuffer(name string, flushInterval time.Duration, flushFn func(startTiflushFn: flushFn,notifyFn: notifyFn,flushChan: make(chan *dataToFlush, 256),+ isStopping: new(atomic.Bool),}go lb.loopFlush()go lb.loopInterval()@@ -119,20 +121,14 @@ func (m *LogBuffer) AddToBuffer(partitionKey, data []byte, processingTsNs int64)}func (m *LogBuffer) IsStopping() bool {- m.RLock()- defer m.RUnlock()-- return m.isStopping+ return m.isStopping.Load()}func (m *LogBuffer) Shutdown() {- m.Lock()- defer m.Unlock()-- if m.isStopping {+ isAlreadyStopped := m.isStopping.Swap(true)+ if isAlreadyStopped {return}- m.isStopping = truetoFlush := m.copyToFlush()m.flushChan <- toFlushclose(m.flushChan)