delete disk_size metrics when collection deleted

This commit is contained in:
Evgeny Kuzhelev 2022-07-27 13:55:09 +05:00
parent f401b996eb
commit 709c83716c

View file

@ -101,6 +101,7 @@ func (s *Store) DeleteCollection(collection string) (e error) {
if e != nil { if e != nil {
return return
} }
stats.VolumeServerDiskSizeGauge.DeleteLabelValues(collection, "normal")
// let the heartbeat send the list of volumes, instead of sending the deleted volume ids to DeletedVolumesChan // let the heartbeat send the list of volumes, instead of sending the deleted volume ids to DeletedVolumesChan
} }
return return
@ -240,19 +241,19 @@ func (s *Store) CollectHeartbeat() *master_pb.Heartbeat {
if maxFileKey < curMaxFileKey { if maxFileKey < curMaxFileKey {
maxFileKey = curMaxFileKey maxFileKey = curMaxFileKey
} }
deleteVolume := false shouldDeleteVolume := false
if !v.expired(volumeMessage.Size, s.GetVolumeSizeLimit()) { if !v.expired(volumeMessage.Size, s.GetVolumeSizeLimit()) {
volumeMessages = append(volumeMessages, volumeMessage) volumeMessages = append(volumeMessages, volumeMessage)
} else { } else {
if v.expiredLongEnough(MAX_TTL_VOLUME_REMOVAL_DELAY) { if v.expiredLongEnough(MAX_TTL_VOLUME_REMOVAL_DELAY) {
deleteVids = append(deleteVids, v.Id) deleteVids = append(deleteVids, v.Id)
deleteVolume = true shouldDeleteVolume = true
} else { } else {
glog.V(0).Infof("volume %d is expired", v.Id) glog.V(0).Infof("volume %d is expired", v.Id)
} }
if v.lastIoError != nil { if v.lastIoError != nil {
deleteVids = append(deleteVids, v.Id) deleteVids = append(deleteVids, v.Id)
deleteVolume = true shouldDeleteVolume = true
glog.Warningf("volume %d has IO error: %v", v.Id, v.lastIoError) glog.Warningf("volume %d has IO error: %v", v.Id, v.lastIoError)
} }
} }
@ -260,12 +261,12 @@ func (s *Store) CollectHeartbeat() *master_pb.Heartbeat {
if _, exist := collectionVolumeSize[v.Collection]; !exist { if _, exist := collectionVolumeSize[v.Collection]; !exist {
collectionVolumeSize[v.Collection] = 0 collectionVolumeSize[v.Collection] = 0
} }
if !deleteVolume { if !shouldDeleteVolume {
collectionVolumeSize[v.Collection] += volumeMessage.Size collectionVolumeSize[v.Collection] += volumeMessage.Size
} else { } else {
collectionVolumeSize[v.Collection] -= volumeMessage.Size collectionVolumeSize[v.Collection] -= volumeMessage.Size
if collectionVolumeSize[v.Collection] <= 0 { if collectionVolumeSize[v.Collection] < 0 {
delete(collectionVolumeSize, v.Collection) collectionVolumeSize[v.Collection] = 0
} }
} }
@ -277,7 +278,7 @@ func (s *Store) CollectHeartbeat() *master_pb.Heartbeat {
"isDiskSpaceLow": 0, "isDiskSpaceLow": 0,
} }
} }
if !deleteVolume && v.IsReadOnly() { if !shouldDeleteVolume && v.IsReadOnly() {
collectionVolumeReadOnlyCount[v.Collection]["IsReadOnly"] += 1 collectionVolumeReadOnlyCount[v.Collection]["IsReadOnly"] += 1
if v.noWriteOrDelete { if v.noWriteOrDelete {
collectionVolumeReadOnlyCount[v.Collection]["noWriteOrDelete"] += 1 collectionVolumeReadOnlyCount[v.Collection]["noWriteOrDelete"] += 1