Fix concurrent map access in EC shards info (#8222)

* fix concurrent map access in EC shards info #8219

* refactor: simplify Disk.ToDiskInfo to use ecShards snapshot and avoid redundant locking

* refactor: improve GetEcShards with pre-allocation and defer
This commit is contained in:
Chris Lu
2026-02-05 10:24:18 -08:00
committed by GitHub
parent e39a4c2041
commit 82d9d8687b
3 changed files with 91 additions and 2 deletions

View File

@@ -7,11 +7,12 @@ import (
)
func (d *Disk) GetEcShards() (ret []*erasure_coding.EcVolumeInfo) {
d.RLock()
d.ecShardsLock.RLock()
defer d.ecShardsLock.RUnlock()
ret = make([]*erasure_coding.EcVolumeInfo, 0, len(d.ecShards))
for _, ecVolumeInfo := range d.ecShards {
ret = append(ret, ecVolumeInfo)
}
d.RUnlock()
return ret
}