From 82bd50eddefdc8009c95301267cdf84fb4de11ad Mon Sep 17 00:00:00 2001 From: Viktor Kramarenko Date: Thu, 29 Aug 2024 12:09:12 +0300 Subject: [PATCH] little refactoring Signed-off-by: Viktor Kramarenko --- images/agent/src/pkg/cache/cache.go | 9 ++++----- .../pkg/controller/lvm_logical_volume_watcher_func.go | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/images/agent/src/pkg/cache/cache.go b/images/agent/src/pkg/cache/cache.go index ffff5e61..a4b0c89c 100644 --- a/images/agent/src/pkg/cache/cache.go +++ b/images/agent/src/pkg/cache/cache.go @@ -131,7 +131,7 @@ func (c *Cache) AddLV(vgName, lvName string) { } } -func (c *Cache) RemoveLV(vgName, lvName string) { +func (c *Cache) MarkLVAsRemoved(vgName, lvName string) { c.m.Lock() defer c.m.Unlock() @@ -172,11 +172,10 @@ func (c *Cache) PrintTheCache(log logger.Logger) { log.Cache(c.vgsErrs.String()) log.Cache("[VGs ENDS]") log.Cache("[LVs BEGIN]") - c.m.RLock() - for _, lv := range c.lvs { - log.Cache(fmt.Sprintf(" Data Name: %s, VG name: %s, size: %s, tags: %s, attr: %s, pool: %s", lv.Data.LVName, lv.Data.VGName, lv.Data.LVSize.String(), lv.Data.LvTags, lv.Data.LVAttr, lv.Data.PoolName)) + lvs, _ := c.GetLVs() + for _, lv := range lvs { + log.Cache(fmt.Sprintf(" Data Name: %s, VG name: %s, size: %s, tags: %s, attr: %s, pool: %s", lv.LVName, lv.VGName, lv.LVSize.String(), lv.LvTags, lv.LVAttr, lv.PoolName)) } - c.m.RUnlock() log.Cache("[ERRS]") log.Cache(c.lvsErrs.String()) log.Cache("[LVs ENDS]") diff --git a/images/agent/src/pkg/controller/lvm_logical_volume_watcher_func.go b/images/agent/src/pkg/controller/lvm_logical_volume_watcher_func.go index c2849828..4ceb4301 100644 --- a/images/agent/src/pkg/controller/lvm_logical_volume_watcher_func.go +++ b/images/agent/src/pkg/controller/lvm_logical_volume_watcher_func.go @@ -170,8 +170,8 @@ func deleteLVIfNeeded(log logger.Logger, sdsCache *cache.Cache, vgName string, l return err } - log.Debug(fmt.Sprintf("[deleteLVIfNeeded] removes LV %s from the cache", lv.Data.LVName)) - sdsCache.RemoveLV(lv.Data.VGName, lv.Data.LVName) + log.Debug(fmt.Sprintf("[deleteLVIfNeeded] mark LV %s in the cache as removed", lv.Data.LVName)) + sdsCache.MarkLVAsRemoved(lv.Data.VGName, lv.Data.LVName) return nil }