@@ -33,6 +33,7 @@ import (
33
33
"k8s.io/klog/v2"
34
34
35
35
"sigs.k8s.io/blob-csi-driver/pkg/util"
36
+ azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
36
37
"sigs.k8s.io/cloud-provider-azure/pkg/metrics"
37
38
azure "sigs.k8s.io/cloud-provider-azure/pkg/provider"
38
39
)
@@ -45,18 +46,18 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
45
46
}
46
47
47
48
volumeCapabilities := req .GetVolumeCapabilities ()
48
- name := req .GetName ()
49
- if len (name ) == 0 {
49
+ volName := req .GetName ()
50
+ if len (volName ) == 0 {
50
51
return nil , status .Error (codes .InvalidArgument , "CreateVolume Name must be provided" )
51
52
}
52
53
if len (volumeCapabilities ) == 0 {
53
54
return nil , status .Error (codes .InvalidArgument , "CreateVolume Volume capabilities must be provided" )
54
55
}
55
56
56
- if acquired := d .volumeLocks .TryAcquire (name ); ! acquired {
57
- return nil , status .Errorf (codes .Aborted , volumeOperationAlreadyExistsFmt , name )
57
+ if acquired := d .volumeLocks .TryAcquire (volName ); ! acquired {
58
+ return nil , status .Errorf (codes .Aborted , volumeOperationAlreadyExistsFmt , volName )
58
59
}
59
- defer d .volumeLocks .Release (name )
60
+ defer d .volumeLocks .Release (volName )
60
61
61
62
volSizeBytes := int64 (req .GetCapacityRange ().GetRequiredBytes ())
62
63
requestGiB := int (util .RoundUpGiB (volSizeBytes ))
@@ -189,20 +190,35 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
189
190
var accountKey string
190
191
accountName := account
191
192
if len (req .GetSecrets ()) == 0 && accountName == "" {
192
- lockKey := storageAccountType + accountKind + resourceGroup + location
193
- d .volLockMap .LockEntry (lockKey )
194
- err = wait .ExponentialBackoff (d .cloud .RequestBackoff (), func () (bool , error ) {
195
- var retErr error
196
- accountName , accountKey , retErr = d .cloud .EnsureStorageAccount (ctx , accountOptions , protocol )
197
- if isRetriableError (retErr ) {
198
- klog .Warningf ("EnsureStorageAccount(%s) failed with error(%v), waiting for retrying" , account , retErr )
199
- return false , nil
193
+ if v , ok := d .volMap .Load (volName ); ok {
194
+ accountName = v .(string )
195
+ } else {
196
+ lockKey := fmt .Sprintf ("%s%s%s%s%s" , storageAccountType , accountKind , resourceGroup , location , protocol )
197
+ // search in cache first
198
+ cache , err := d .accountSearchCache .Get (lockKey , azcache .CacheReadTypeDefault )
199
+ if err != nil {
200
+ return nil , err
201
+ }
202
+ if cache != nil {
203
+ accountName = cache .(string )
204
+ } else {
205
+ d .volLockMap .LockEntry (lockKey )
206
+ err = wait .ExponentialBackoff (d .cloud .RequestBackoff (), func () (bool , error ) {
207
+ var retErr error
208
+ accountName , accountKey , retErr = d .cloud .EnsureStorageAccount (ctx , accountOptions , protocol )
209
+ if isRetriableError (retErr ) {
210
+ klog .Warningf ("EnsureStorageAccount(%s) failed with error(%v), waiting for retrying" , account , retErr )
211
+ return false , nil
212
+ }
213
+ return true , retErr
214
+ })
215
+ d .volLockMap .UnlockEntry (lockKey )
216
+ if err != nil {
217
+ return nil , status .Errorf (codes .Internal , "failed to ensure storage account: %v" , err )
218
+ }
219
+ d .accountSearchCache .Set (lockKey , accountName )
220
+ d .volMap .Store (volName , accountName )
200
221
}
201
- return true , retErr
202
- })
203
- d .volLockMap .UnlockEntry (lockKey )
204
- if err != nil {
205
- return nil , status .Errorf (codes .Internal , "failed to ensure storage account: %v" , err )
206
222
}
207
223
}
208
224
accountOptions .Name = accountName
@@ -215,7 +231,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
215
231
216
232
validContainerName := containerName
217
233
if validContainerName == "" {
218
- validContainerName = getValidContainerName (name , protocol )
234
+ validContainerName = getValidContainerName (volName , protocol )
219
235
parameters [containerNameField ] = validContainerName
220
236
}
221
237
@@ -251,7 +267,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
251
267
if containerName != "" {
252
268
// add volume name as suffix to differentiate volumeID since "containerName" is specified
253
269
// not necessary for dynamic container name creation since volumeID already contains volume name
254
- volumeID = volumeID + "#" + name
270
+ volumeID = volumeID + "#" + volName
255
271
}
256
272
klog .V (2 ).Infof ("create container %s on storage account %s successfully" , validContainerName , accountName )
257
273
0 commit comments