From 12581d099d305f8715297bb2a4237fe051a23c25 Mon Sep 17 00:00:00 2001 From: xuwenfeng Date: Fri, 30 Aug 2024 11:29:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BB=E9=94=81=E5=86=85=E7=9A=84=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=AD=98=E6=B4=BBvolume=E9=80=BB=E8=BE=91=E6=94=BE?= =?UTF-8?q?=E5=88=B0=E5=A4=96=E9=9D=A2=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- weed/storage/store.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/weed/storage/store.go b/weed/storage/store.go index f7f2e5ebe57..e2e65d92d8d 100644 --- a/weed/storage/store.go +++ b/weed/storage/store.go @@ -388,8 +388,8 @@ func (s *Store) CollectHeartbeat() *master_pb.Heartbeat { func (s *Store) deleteExpiredEcVolumes() (ecShards, deleted []*master_pb.VolumeEcShardInformationMessage) { for _, location := range s.Locations { - toDeleteEcVolume := s.prepareDeleteExpiredEcVolumesInLocation(location, ecShards) - for _, ev := range toDeleteEcVolume { + toDeleteEcVolumes, aliveEcVolumes := s.prepareDiffExpiredEcVolumesInLocation(location) + for _, ev := range toDeleteEcVolumes { err := location.deleteEcVolumeById(ev.VolumeId) if err != nil { ecShards = append(ecShards, ev.ToVolumeEcShardInformationMessage()...) @@ -398,23 +398,25 @@ func (s *Store) deleteExpiredEcVolumes() (ecShards, deleted []*master_pb.VolumeE } deleted = append(deleted, ev.ToVolumeEcShardInformationMessage()...) } + for _, v := range aliveEcVolumes { + ecShards = append(ecShards, v.ToVolumeEcShardInformationMessage()...) + } } return } -// prepareDeleteExpiredEcVolumesInLocation 计算ec volume是否达到删除时间,然后返回需要删除的ec volume列表,不需要删除的添加到ecShards中 -func (s *Store) prepareDeleteExpiredEcVolumesInLocation(location *DiskLocation, ecShards []*master_pb.VolumeEcShardInformationMessage) []*erasure_coding.EcVolume { - var toDeleteEcVolume []*erasure_coding.EcVolume +// prepareDiffExpiredEcVolumesInLocation 遍历location下所有的ec volumes,区分是否到了删除时间 +func (s *Store) prepareDiffExpiredEcVolumesInLocation(location *DiskLocation) (toDeleteEcVolumes, aliveEcVolumes []*erasure_coding.EcVolume) { location.ecVolumesLock.RLock() defer location.ecVolumesLock.RUnlock() for _, ev := range location.ecVolumes { if ev.IsTimeToDestroy() { - toDeleteEcVolume = append(toDeleteEcVolume, ev) + toDeleteEcVolumes = append(toDeleteEcVolumes, ev) } else { - ecShards = append(ecShards, ev.ToVolumeEcShardInformationMessage()...) + aliveEcVolumes = append(aliveEcVolumes, ev) } } - return toDeleteEcVolume + return } func (s *Store) SetStopping() {