Skip to content

Commit baae454

Browse files
authored
Merge pull request #751 from andyzhangx/dataplane-issue
fix: delete volume failure when management api is throttled
2 parents 939ef16 + 8005641 commit baae454

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

pkg/blob/blob.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ type Driver struct {
173173
subnetLockMap *util.LockMap
174174
// a map storing all volumes created by this driver <volumeName, accountName>
175175
volMap sync.Map
176-
// a map storing all volumes using data plane API <volumeID, "">, <accountName, "">
177-
dataPlaneAPIVolMap sync.Map
176+
// a timed cache storing all volumeIDs and storage accounts that are using data plane API
177+
dataPlaneAPIVolCache *azcache.TimedCache
178178
// a timed cache storing account search history (solve account list throttling issue)
179179
accountSearchCache *azcache.TimedCache
180180
}
@@ -208,6 +208,9 @@ func NewDriver(options *DriverOptions) *Driver {
208208
if d.accountSearchCache, err = azcache.NewTimedcache(time.Minute, getter); err != nil {
209209
klog.Fatalf("%v", err)
210210
}
211+
if d.dataPlaneAPIVolCache, err = azcache.NewTimedcache(10*time.Minute, getter); err != nil {
212+
klog.Fatalf("%v", err)
213+
}
211214
return &d
212215
}
213216

@@ -746,11 +749,21 @@ func (d *Driver) getSubnetResourceID() string {
746749
}
747750

748751
func (d *Driver) useDataPlaneAPI(volumeID, accountName string) bool {
749-
_, useDataPlaneAPI := d.dataPlaneAPIVolMap.Load(volumeID)
750-
if !useDataPlaneAPI {
751-
_, useDataPlaneAPI = d.dataPlaneAPIVolMap.Load(accountName)
752+
cache, err := d.dataPlaneAPIVolCache.Get(volumeID, azcache.CacheReadTypeDefault)
753+
if err != nil {
754+
klog.Errorf("get(%s) from dataPlaneAPIVolCache failed with error: %v", volumeID, err)
755+
}
756+
if cache != nil {
757+
return true
752758
}
753-
return useDataPlaneAPI
759+
cache, err = d.dataPlaneAPIVolCache.Get(accountName, azcache.CacheReadTypeDefault)
760+
if err != nil {
761+
klog.Errorf("get(%s) from dataPlaneAPIVolCache failed with error: %v", accountName, err)
762+
}
763+
if cache != nil {
764+
return true
765+
}
766+
return false
754767
}
755768

756769
// appendDefaultMountOptions return mount options combined with mountOptions and defaultMountOptions

pkg/blob/blob_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func TestNewDriver(t *testing.T) {
9191
fakedriver.Name = DefaultDriverName
9292
fakedriver.Version = driverVersion
9393
fakedriver.accountSearchCache = driver.accountSearchCache
94+
fakedriver.dataPlaneAPIVolCache = driver.dataPlaneAPIVolCache
9495
assert.Equal(t, driver, fakedriver)
9596
}
9697

@@ -1184,7 +1185,7 @@ func TestUseDataPlaneAPI(t *testing.T) {
11841185
name: "volumeID loads correctly",
11851186
testFunc: func(t *testing.T) {
11861187
d := NewFakeDriver()
1187-
d.dataPlaneAPIVolMap.LoadOrStore(fakeVolumeID, "foo")
1188+
d.dataPlaneAPIVolCache.Set(fakeVolumeID, "foo")
11881189
output := d.useDataPlaneAPI(fakeVolumeID, "")
11891190
if !output {
11901191
t.Errorf("Actual Output: %t, Expected Output: %t", output, true)
@@ -1195,7 +1196,7 @@ func TestUseDataPlaneAPI(t *testing.T) {
11951196
name: "account loads correctly",
11961197
testFunc: func(t *testing.T) {
11971198
d := NewFakeDriver()
1198-
d.dataPlaneAPIVolMap.LoadOrStore(fakeAccountName, "foo")
1199+
d.dataPlaneAPIVolCache.Set(fakeAccountName, "foo")
11991200
output := d.useDataPlaneAPI(fakeAccountName, "")
12001201
if !output {
12011202
t.Errorf("Actual Output: %t, Expected Output: %t", output, true)

pkg/blob/controllerserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
347347
klog.V(2).Infof("create container %s on storage account %s successfully", validContainerName, accountName)
348348

349349
if useDataPlaneAPI {
350-
d.dataPlaneAPIVolMap.Store(volumeID, "")
351-
d.dataPlaneAPIVolMap.Store(accountName, "")
350+
d.dataPlaneAPIVolCache.Set(volumeID, "")
351+
d.dataPlaneAPIVolCache.Set(accountName, "")
352352
}
353353

354354
isOperationSucceeded = true

pkg/blob/controllerserver_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ func TestDeleteVolume(t *testing.T) {
792792
req := &csi.DeleteVolumeRequest{
793793
VolumeId: "rg#accountName#containerName",
794794
}
795-
d.dataPlaneAPIVolMap.Store("rg#accountName#containerName", "accountName")
795+
d.dataPlaneAPIVolCache.Set("rg#accountName#containerName", "accountName")
796796
_, err := d.DeleteVolume(context.Background(), req)
797797
expectedErr := status.Errorf(codes.Internal, "GetAuthEnv(%s) failed with %v", "rg#accountName#containerName", fmt.Errorf("no key for storage account(%s) under resource group(%s), err %w", "accountName", "rg", fmt.Errorf("StorageAccountClient is nil")))
798798
if !reflect.DeepEqual(err, expectedErr) {

0 commit comments

Comments
 (0)