Fixed critical race condition in CompactMap where Set(), Delete(), and
Get() methods had issues with concurrent map access.
Root cause: segmentForKey() can create new map segments, which modifies
the cm.segments map. Calling this under a read lock caused concurrent
map write panics when multiple goroutines accessed the map simultaneously
(e.g., during VolumeNeedleStatus gRPC calls).
Changes:
- Set() method: Changed RLock/RUnlock to Lock/Unlock
- Delete() method: Changed RLock/RUnlock to Lock/Unlock, optimized to
avoid creating empty segments when key doesn't exist
- Get() method: Removed segmentForKey() call to avoid race condition,
now checks segment existence directly and returns early if segment
doesn't exist (optimization: avoids unnecessary segment creation)
This fix resolves the runtime/maps.fatal panic that occurred under
concurrent load.
Tested with race detector: go test -v -race ./weed/storage/needle_map/...