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
fix(filersink): return lock-free snapshot from ActiveTransfers (#9604)
Chris Lueae8f33db5b8
diff --git a/weed/replication/sink/filersink/fetch_write.go b/weed/replication/sink/filersink/fetch_write.goindex 0399542f13..dd1c3ffb53 100644--- a/weed/replication/sink/filersink/fetch_write.go+++ b/weed/replication/sink/filersink/fetch_write.go@@ -242,9 +242,11 @@ func (fs *FilerSink) fetchAndWrite(sourceChunk *filer_pb.FileChunk, path string,}transferStatus := &ChunkTransferStatus{- ChunkFileId: sourceChunk.GetFileIdString(),- Path: path,- Status: "downloading",+ ChunkTransferSnapshot: ChunkTransferSnapshot{+ ChunkFileId: sourceChunk.GetFileIdString(),+ Path: path,+ Status: "downloading",+ },}fs.activeTransfers.Store(sourceChunk.GetFileIdString(), transferStatus)defer fs.activeTransfers.Delete(sourceChunk.GetFileIdString())diff --git a/weed/replication/sink/filersink/filer_sink.go b/weed/replication/sink/filersink/filer_sink.goindex 50aaab4499..c93942fe91 100644--- a/weed/replication/sink/filersink/filer_sink.go+++ b/weed/replication/sink/filersink/filer_sink.go@@ -22,12 +22,9 @@ import ("github.com/seaweedfs/seaweedfs/weed/util")-// ChunkTransferStatus tracks the progress of a single chunk being replicated.-// Fields are guarded by mu: ChunkFileId and Path are immutable after creation,-// while BytesReceived, Status, and LastErr are updated by fetchAndWrite and-// read by ActiveTransfers.-type ChunkTransferStatus struct {- mu sync.RWMutex+// ChunkTransferSnapshot is a lock-free, copyable view of a chunk transfer's+// progress, returned by ActiveTransfers.+type ChunkTransferSnapshot struct {ChunkFileId stringPath stringBytesReceived int64@@ -35,6 +32,15 @@ type ChunkTransferStatus struct {LastErr string}+// ChunkTransferStatus tracks the progress of a single chunk being replicated.+// Fields are guarded by mu: ChunkFileId and Path are immutable after creation,+// while BytesReceived, Status, and LastErr are updated by fetchAndWrite and+// read by ActiveTransfers.+type ChunkTransferStatus struct {+ mu sync.RWMutex+ ChunkTransferSnapshot+}+type FilerSink struct {filerSource *source.FilerSourcegrpcAddress string@@ -134,18 +140,12 @@ func (fs *FilerSink) SetChunkConcurrency(concurrency int) {}// ActiveTransfers returns an immutable snapshot of all in-progress chunk transfers.-func (fs *FilerSink) ActiveTransfers() []ChunkTransferStatus {- var transfers []ChunkTransferStatus+func (fs *FilerSink) ActiveTransfers() []ChunkTransferSnapshot {+ var transfers []ChunkTransferSnapshotfs.activeTransfers.Range(func(key, value any) bool {t := value.(*ChunkTransferStatus)t.mu.RLock()- transfers = append(transfers, ChunkTransferStatus{- ChunkFileId: t.ChunkFileId,- Path: t.Path,- BytesReceived: t.BytesReceived,- Status: t.Status,- LastErr: t.LastErr,- })+ transfers = append(transfers, t.ChunkTransferSnapshot)t.mu.RUnlock()return true})