diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2019-11-08 11:34:28 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-08 11:34:28 -0800 |
| commit | 926abf9115681cdc56076871b8778e778693e601 (patch) | |
| tree | 0f4ea0439559b558d798c055fa1c4422593f0369 | |
| parent | 08c83b1a594f9270c75b1d42bc3bb583b38b2916 (diff) | |
| parent | 1dd101f78286c43d57a6a7732aee143b4ce6af6a (diff) | |
| download | seaweedfs-926abf9115681cdc56076871b8778e778693e601.tar.xz seaweedfs-926abf9115681cdc56076871b8778e778693e601.zip | |
Merge pull request #1107 from song-zhang/master
use read lock to avoid io hang during heartbeat
| -rw-r--r-- | weed/storage/store.go | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/weed/storage/store.go b/weed/storage/store.go index 66dd021ff..f115721cb 100644 --- a/weed/storage/store.go +++ b/weed/storage/store.go @@ -165,8 +165,9 @@ func (s *Store) CollectHeartbeat() *master_pb.Heartbeat { var maxFileKey NeedleId collectionVolumeSize := make(map[string]uint64) for _, location := range s.Locations { + var deleteVids []needle.VolumeId maxVolumeCount = maxVolumeCount + location.MaxVolumeCount - location.Lock() + location.RLock() for _, v := range location.volumes { if maxFileKey < v.MaxFileKey() { maxFileKey = v.MaxFileKey() @@ -175,8 +176,7 @@ func (s *Store) CollectHeartbeat() *master_pb.Heartbeat { volumeMessages = append(volumeMessages, v.ToVolumeInformationMessage()) } else { if v.expiredLongEnough(MAX_TTL_VOLUME_REMOVAL_DELAY) { - location.deleteVolumeById(v.Id) - glog.V(0).Infoln("volume", v.Id, "is deleted.") + deleteVids = append(deleteVids, v.Id) } else { glog.V(0).Infoln("volume", v.Id, "is expired.") } @@ -184,7 +184,17 @@ func (s *Store) CollectHeartbeat() *master_pb.Heartbeat { fileSize, _, _ := v.FileStat() collectionVolumeSize[v.Collection] += fileSize } - location.Unlock() + location.RUnlock() + + if len(deleteVids) > 0 { + // delete expired volumes. + location.Lock() + for _, vid := range deleteVids { + location.deleteVolumeById(vid) + glog.V(0).Infoln("volume", vid, "is deleted.") + } + location.Unlock() + } } for col, size := range collectionVolumeSize { |
