Skip to content

Commit

Permalink
fixes the cold cache issue
Browse files Browse the repository at this point in the history
Signed-off-by: Viktor Kramarenko <[email protected]>
  • Loading branch information
ViktorKram committed Aug 21, 2024
1 parent c21bef3 commit e054db2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
18 changes: 15 additions & 3 deletions images/agent/src/pkg/cache/cache.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cache

import (
"bytes"
"fmt"

"agent/internal"
"agent/pkg/logger"
"bytes"
"fmt"
"slices"
)

type Cache struct {
Expand Down Expand Up @@ -81,6 +81,18 @@ func (c *Cache) FindLV(vgName, lvName string) *internal.LVData {
return nil
}

func (c *Cache) AddLV(vgName, lvName string) {
c.lvs = append(c.lvs, internal.LVData{VGName: vgName, LVName: lvName})
}

func (c *Cache) RemoveLV(vgName, lvName string) {
for i, lv := range c.lvs {
if lv.VGName == vgName && lv.LVName == lvName {
slices.Delete(c.lvs, i, i+1)
}
}
}

func (c *Cache) FindVG(vgName string) *internal.VGData {
for _, vg := range c.vgs {
if vg.VGName == vgName {
Expand Down
7 changes: 4 additions & 3 deletions images/agent/src/pkg/controller/lvm_logical_volume_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ func reconcileLLVCreateFunc(

log.Info(fmt.Sprintf("[reconcileLLVCreateFunc] successfully created LV %s in VG %s for LVMLogicalVolume resource with name: %s", llv.Spec.ActualLVNameOnTheNode, lvg.Spec.ActualVGNameOnTheNode, llv.Name))

log.Debug(fmt.Sprintf("[reconcileLLVCreateFunc] adds the LV %s to the cache", llv.Spec.ActualLVNameOnTheNode))
sdsCache.AddLV(lvg.Spec.ActualVGNameOnTheNode, llv.Spec.ActualLVNameOnTheNode)
log.Debug(fmt.Sprintf("[reconcileLLVCreateFunc] tries to get the LV %s actual size", llv.Spec.ActualLVNameOnTheNode))
actualSize := getLVActualSize(sdsCache, lvg.Spec.ActualVGNameOnTheNode, llv.Spec.ActualLVNameOnTheNode)
if actualSize.Value() == 0 {
Expand Down Expand Up @@ -327,9 +329,8 @@ func reconcileLLVUpdateFunc(
log.Debug(fmt.Sprintf("[reconcileLLVUpdateFunc] tries to get LVMLogicalVolume %s actual size before the extension", llv.Name))
actualSize := getLVActualSize(sdsCache, lvg.Spec.ActualVGNameOnTheNode, llv.Spec.ActualLVNameOnTheNode)
if actualSize.Value() == 0 {
err := fmt.Errorf("LV %s has zero size (likely LV was not found in the cache)", llv.Spec.ActualLVNameOnTheNode)
log.Error(err, fmt.Sprintf("[reconcileLLVUpdateFunc] unable to get actual LV %s size of the LVMLogicalVolume %s", llv.Spec.ActualLVNameOnTheNode, llv.Name))
return true, err
log.Warning(fmt.Sprintf("[reconcileLLVUpdateFunc] LV %s of the LVMLogicalVolume %s has zero size (likely LV was not updated in the cache) ", llv.Spec.ActualLVNameOnTheNode, llv.Name))
return true, nil
}
log.Debug(fmt.Sprintf("[reconcileLLVUpdateFunc] successfully got LVMLogicalVolume %s actual size %s before the extension", llv.Name, actualSize.String()))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ 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.LVName))
sdsCache.RemoveLV(lv.VGName, lv.LVName)

return nil
}

Expand Down

0 comments on commit e054db2

Please sign in to comment.