Skip to content

Commit

Permalink
Merge pull request #2242 from andyzhangx/refine-check-disk-lun-collis…
Browse files Browse the repository at this point in the history
…ion-1.29

[release-1.29] fix: refine check disk lun collision logic
  • Loading branch information
andyzhangx committed Mar 27, 2024
2 parents 0c3df46 + cdd304b commit 8b5a05b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
13 changes: 8 additions & 5 deletions pkg/azuredisk/azuredisk.go
Expand Up @@ -138,6 +138,8 @@ type Driver struct {
volumeLocks *volumehelper.VolumeLocks
// a timed cache for throttling
throttlingCache azcache.Resource
// a timed cache for disk lun collision check throttling
checkDiskLunThrottlingCache azcache.Resource
}

// newDriverV1 Creates a NewCSIDriver object. Assumes vendor version is equal to driver version &
Expand Down Expand Up @@ -180,13 +182,14 @@ func newDriverV1(options *DriverOptions) *Driver {

topologyKey = fmt.Sprintf("topology.%s/zone", driver.Name)

cache, err := azcache.NewTimedCache(5*time.Minute, func(key string) (interface{}, error) {
return nil, nil
}, false)
if err != nil {
getter := func(key string) (interface{}, error) { return nil, nil }
var err error
if driver.throttlingCache, err = azcache.NewTimedCache(5*time.Minute, getter, false); err != nil {
klog.Fatalf("%v", err)
}
if driver.checkDiskLunThrottlingCache, err = azcache.NewTimedCache(30*time.Minute, getter, false); err != nil {
klog.Fatalf("%v", err)
}
driver.throttlingCache = cache
return &driver
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/azuredisk/controllerserver.go
Expand Up @@ -563,6 +563,10 @@ func (d *Driver) ValidateVolumeCapabilities(ctx context.Context, req *csi.Valida
func (d *Driver) getOccupiedLunsFromNode(ctx context.Context, nodeName types.NodeName, diskURI string) []int {
var occupiedLuns []int
if d.checkDiskLUNCollision && !d.isCheckDiskLunThrottled() {
timer := time.AfterFunc(checkDiskLunThrottleLatency, func() {
klog.Warningf("checkDiskLun(%s) on node %s took longer than %v, disable disk lun check temporarily", diskURI, nodeName, checkDiskLunThrottleLatency)
d.checkDiskLunThrottlingCache.Set(consts.CheckDiskLunThrottlingKey, "")
})
now := time.Now()
if usedLunsFromVA, err := d.getUsedLunsFromVolumeAttachments(ctx, string(nodeName)); err == nil {
if len(usedLunsFromVA) > 0 {
Expand All @@ -582,9 +586,9 @@ func (d *Driver) getOccupiedLunsFromNode(ctx context.Context, nodeName types.Nod
}
latency := time.Since(now)
if latency > checkDiskLunThrottleLatency {
klog.Warningf("checkDiskLun(%s) on node %s took %v (limit: %v), disable disk lun check temporarily", diskURI, nodeName, latency, checkDiskLunThrottleLatency)
d.throttlingCache.Set(consts.CheckDiskLunThrottlingKey, "")
klog.Warningf("checkDiskLun(%s) on node %s took %v (limit: %v)", diskURI, nodeName, latency, checkDiskLunThrottleLatency)
} else {
timer.Stop() // cancel the timer
klog.V(6).Infof("checkDiskLun(%s) on node %s took %v", diskURI, nodeName, latency)
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/azuredisk/fake_azuredisk.go
Expand Up @@ -135,6 +135,7 @@ func newFakeDriverV1(t *testing.T) (*fakeDriverV1, error) {
return nil, err
}
driver.throttlingCache = cache
driver.checkDiskLunThrottlingCache = cache
driver.deviceHelper = mockoptimization.NewMockInterface(ctrl)

driver.AddControllerServiceCapabilities(
Expand Down

0 comments on commit 8b5a05b

Please sign in to comment.