Skip to content

Commit

Permalink
fixed concurrent map
Browse files Browse the repository at this point in the history
Signed-off-by: Viktor Kramarenko <viktor.kramarenko@flant.com>
  • Loading branch information
ViktorKram committed Mar 22, 2024
1 parent ee980aa commit c8075da
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ func filterNodes(
return nil, err
}
log.Trace(fmt.Sprintf("[filterNodes] LVGs Thick FreeSpace: %+v", lvgsThickFree))

scLVGs, err := getSortedLVGsFromStorageClasses(scs)
if err != nil {
return nil, err
Expand All @@ -208,6 +207,7 @@ func filterNodes(
FailedNodes: FailedNodesMap{},
}

mutex := &sync.RWMutex{}
wg := &sync.WaitGroup{}
wg.Add(len(nodes.Items))
errs := make(chan error, len(nodes.Items)*len(pvcs))
Expand Down Expand Up @@ -242,15 +242,19 @@ func filterNodes(
switch pvcReq.DeviceType {
case thick:
lvg := lvgs[matchedLVG.Name]
mutex.RLock()
freeSpace := lvgsThickFree[lvg.Name]
mutex.RUnlock()

log.Trace(fmt.Sprintf("[filterNodes] Thick free space: %d, PVC requested space: %d", freeSpace, pvcReq.RequestedSize))
if freeSpace < pvcReq.RequestedSize {
hasEnoughSpace = false
break
}

mutex.Lock()
lvgsThickFree[lvg.Name] -= pvcReq.RequestedSize
mutex.Unlock()
case thin:
lvg := lvgs[matchedLVG.Name]
targetThinPool := findMatchedThinPool(lvg.Status.ThinPools, matchedLVG.Thin.PoolName)
Expand Down

0 comments on commit c8075da

Please sign in to comment.