volume: avoid deadlock when deleting volumes

fix https://github.com/chrislusf/seaweedfs/issues/1501
This commit is contained in:
Chris Lu 2020-10-01 07:10:03 -07:00
parent a34bad2cee
commit a1c01d716b
2 changed files with 3 additions and 4 deletions

View file

@ -174,9 +174,6 @@ func (l *DiskLocation) DeleteCollectionFromDiskLocation(collection string) (e er
} }
func (l *DiskLocation) deleteVolumeById(vid needle.VolumeId) (found bool, e error) { func (l *DiskLocation) deleteVolumeById(vid needle.VolumeId) (found bool, e error) {
l.volumesLock.Lock()
defer l.volumesLock.Unlock()
v, ok := l.volumes[vid] v, ok := l.volumes[vid]
if !ok { if !ok {
return return

View file

@ -380,10 +380,12 @@ func (s *Store) DeleteVolume(i needle.VolumeId) error {
Ttl: v.Ttl.ToUint32(), Ttl: v.Ttl.ToUint32(),
} }
for _, location := range s.Locations { for _, location := range s.Locations {
if found, err := location.deleteVolumeById(i); found && err == nil { if err := location.DeleteVolume(i); err == nil {
glog.V(0).Infof("DeleteVolume %d", i) glog.V(0).Infof("DeleteVolume %d", i)
s.DeletedVolumesChan <- message s.DeletedVolumesChan <- message
return nil return nil
} else {
glog.Errorf("DeleteVolume %d: %v", i, err)
} }
} }