Skip to content

Commit

Permalink
Merge pull request #803 from andyzhangx/reduce-cache-refresh
Browse files Browse the repository at this point in the history
feat: reduce vmss cache refresh in parallel disk attach/detach
  • Loading branch information
k8s-ci-robot committed Sep 13, 2021
2 parents 1af27c8 + 7f18487 commit 47c4f2e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/provider/azure_vmss.go
Expand Up @@ -76,6 +76,8 @@ type ScaleSet struct {
vmssCache *azcache.TimedCache
vmssVMCache *sync.Map // [resourcegroup/vmssname]*azcache.TimedCache
availabilitySetNodesCache *azcache.TimedCache
// lockMap in cache refresh
lockMap *lockMap
}

// newScaleSet creates a new ScaleSet.
Expand All @@ -93,6 +95,7 @@ func newScaleSet(az *Cloud) (VMSet, error) {
Cloud: az,
availabilitySet: as,
vmssVMCache: &sync.Map{},
lockMap: newLockMap(),
}

if !ss.DisableAvailabilitySetNodes {
Expand Down Expand Up @@ -183,6 +186,15 @@ func (ss *ScaleSet) getVmssVMByNodeIdentity(node *nodeIdentity, crt azcache.Azur
}

if !found {
// lock and try find nodeName from cache again, refresh cache if still not found
ss.lockMap.LockEntry(cacheKey)
defer ss.lockMap.UnlockEntry(cacheKey)
vmssName, instanceID, vm, found, err = getter(node.nodeName, crt)
if err == nil && found && vm != nil {
klog.V(2).Infof("found VMSS VM with nodeName %s after retry", node.nodeName)
return vmssName, instanceID, vm, nil
}

klog.V(2).Infof("Couldn't find VMSS VM with nodeName %s, refreshing the cache", node.nodeName)
vmssName, instanceID, vm, found, err = getter(node.nodeName, azcache.CacheReadTypeForceRefresh)
if err != nil {
Expand Down

0 comments on commit 47c4f2e

Please sign in to comment.