Skip to content

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.

add locking on possible concurrent map access

Chris Lu101e784577f9
diff --git a/weed/storage/compact_map.go b/weed/storage/compact_map.go
index d4438d0440..6afaf7df8a 100644
--- a/weed/storage/compact_map.go
+++ b/weed/storage/compact_map.go
@@ -190,18 +190,22 @@ func (cm *CompactMap) binarySearchCompactSection(key Key) int {
// Visit visits all entries or stop if any error when visiting
func (cm *CompactMap) Visit(visit func(NeedleValue) error) error {
for _, cs := range cm.list {
+ cs.RLock()
for _, v := range cs.overflow {
if err := visit(v); err != nil {
+ cs.RUnlock()
return err
}
}
for _, v := range cs.values {
if _, found := cs.overflow[v.Key]; !found {
if err := visit(v); err != nil {
+ cs.RUnlock()
return err
}
}
}
+ cs.RUnlock()
}
return nil
}