Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[release-1.31] fix: GetFileShare throttling in CreateSnapshot #2236

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/azurefile/azurefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ type Driver struct {
azcopySasTokenCache azcache.Resource
// a timed cache storing subnet operations
subnetCache azcache.Resource
// a timed cache storing file share size <accountName-fileShareName, size(int32)>
getFileShareSizeCache azcache.Resource
// sas expiry time for azcopy in volume clone and snapshot restore
sasTokenExpirationMinutes int
// azcopy timeout for volume clone and snapshot restore
Expand Down Expand Up @@ -370,6 +372,10 @@ func NewDriver(options *DriverOptions) *Driver {
klog.Fatalf("%v", err)
}

if driver.getFileShareSizeCache, err = azcache.NewTimedCache(10*time.Minute, getter, false); err != nil {
klog.Fatalf("%v", err)
}

return &driver
}

Expand Down
18 changes: 15 additions & 3 deletions pkg/azurefile/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,11 +932,23 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ

klog.V(2).Infof("created share snapshot: %s, time: %v, quota: %dGiB", itemSnapshot, itemSnapshotTime, itemSnapshotQuota)
if itemSnapshotQuota == 0 {
fileshare, err := d.cloud.FileClient.WithSubscriptionID(subsID).GetFileShare(ctx, rgName, accountName, fileShareName, "")
key := fmt.Sprintf("%s-%s", accountName, fileShareName)
cache, err := d.getFileShareSizeCache.Get(key, azcache.CacheReadTypeDefault)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get file share(%s) quota: %v", fileShareName, err)
return nil, status.Errorf(codes.Internal, "failed to get file share size cache(%s): %v", key, err)
}
if cache != nil {
klog.V(2).Infof("get file share(%s) account(%s) quota from cache", fileShareName, accountName)
itemSnapshotQuota = cache.(int32)
} else {
klog.V(2).Infof("get file share(%s) account(%s) quota from cloud", fileShareName, accountName)
fileshare, err := d.cloud.FileClient.WithSubscriptionID(subsID).GetFileShare(ctx, rgName, accountName, fileShareName, "")
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get file share(%s) quota: %v", fileShareName, err)
}
itemSnapshotQuota = ptr.Deref(fileshare.ShareQuota, defaultAzureFileQuota)
d.getFileShareSizeCache.Set(key, itemSnapshotQuota)
}
itemSnapshotQuota = ptr.Deref(fileshare.ShareQuota, defaultAzureFileQuota)
}
createResp := &csi.CreateSnapshotResponse{
Snapshot: &csi.Snapshot{
Expand Down
Loading