mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
add locking on possible concurrent map access
fix https://github.com/chrislusf/seaweedfs/issues/328
This commit is contained in:
parent
356b8048c5
commit
101e784577
|
@ -190,18 +190,22 @@ func (cm *CompactMap) binarySearchCompactSection(key Key) int {
|
||||||
// Visit visits all entries or stop if any error when visiting
|
// Visit visits all entries or stop if any error when visiting
|
||||||
func (cm *CompactMap) Visit(visit func(NeedleValue) error) error {
|
func (cm *CompactMap) Visit(visit func(NeedleValue) error) error {
|
||||||
for _, cs := range cm.list {
|
for _, cs := range cm.list {
|
||||||
|
cs.RLock()
|
||||||
for _, v := range cs.overflow {
|
for _, v := range cs.overflow {
|
||||||
if err := visit(v); err != nil {
|
if err := visit(v); err != nil {
|
||||||
|
cs.RUnlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, v := range cs.values {
|
for _, v := range cs.values {
|
||||||
if _, found := cs.overflow[v.Key]; !found {
|
if _, found := cs.overflow[v.Key]; !found {
|
||||||
if err := visit(v); err != nil {
|
if err := visit(v); err != nil {
|
||||||
|
cs.RUnlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cs.RUnlock()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue