Skip to content

Commit 741f7e7

Browse files
authored
Update pools during concurrent UpsertBackend
1 parent 23e4d3d commit 741f7e7

File tree

5 files changed

+243
-188
lines changed

5 files changed

+243
-188
lines changed

core/concurrent_cache/backend.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ func UpsertBackend(id, name, newName string) Subquery {
121121

122122
backends.lock()
123123

124+
// Update circular references
125+
b.StoragePools().Range(func(k, v interface{}) bool {
126+
if pool, poolOK := v.(storage.Pool); poolOK {
127+
pool.SetBackend(b)
128+
}
129+
return true
130+
})
131+
124132
// This is the canonical method for upserting with a unique key.
125133
// There are 4 cases: key and newKey are equal, key is empty, newKey is empty,
126134
// and key and newKey are different. In all cases expect #3,

core/concurrent_cache/backend_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package concurrent_cache
22

33
import (
4+
"sync"
45
"testing"
56

67
"github.com/prometheus/client_golang/prometheus/testutil"
78
"github.com/stretchr/testify/assert"
89
"go.uber.org/mock/gomock"
910

1011
"github.com/netapp/trident/core/metrics"
12+
mockstorage "github.com/netapp/trident/mocks/mock_storage"
1113
"github.com/netapp/trident/storage"
1214
)
1315

@@ -44,6 +46,7 @@ func TestUpsertBackend_Metrics(t *testing.T) {
4446
"state": string(storage.Online),
4547
"uuid": "test-backend-uuid",
4648
})
49+
4750
backends.lock()
4851
backends.data["test-backend-uuid"] = tt.initialBackend
4952
backends.unlock()
@@ -56,13 +59,21 @@ func TestUpsertBackend_Metrics(t *testing.T) {
5659
initialTridentBackendInfo := testutil.ToFloat64(metrics.TridentBackendInfo.WithLabelValues("test-driver", "existing-backend", "test-backend-uuid"))
5760

5861
// Create upsert backend
59-
tt.upsertBackend = getMockBackendWithMap(mockCtrl, map[string]string{
62+
mockUpsertBackend := getMockBackendWithMap(mockCtrl, map[string]string{
6063
"name": "updated-backend",
6164
"driverName": "test-driver",
6265
"state": string(storage.Online),
6366
"uuid": "test-backend-uuid",
6467
})
6568

69+
mockPool := mockstorage.NewMockPool(mockCtrl)
70+
mockPool.EXPECT().SetBackend(mockUpsertBackend).Times(1)
71+
mockPoolMap := sync.Map{}
72+
mockPoolMap.Store("mock-pool", mockPool)
73+
74+
mockUpsertBackend.EXPECT().StoragePools().Return(&mockPoolMap).AnyTimes()
75+
tt.upsertBackend = mockUpsertBackend
76+
6677
// Execute upsert operation
6778
subquery := UpsertBackend("test-backend-uuid", "test-backend", "updated-backend")
6879
result := &Result{}

core/concurrent_cache/concurrent_cache_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/stretchr/testify/assert"
1313
"go.uber.org/mock/gomock"
1414

15+
mockstorage "github.com/netapp/trident/mocks/mock_storage"
1516
"github.com/netapp/trident/storage"
1617
storageclass "github.com/netapp/trident/storage_class"
1718
"github.com/netapp/trident/utils/models"
@@ -677,21 +678,30 @@ func setupTestData(t *testing.T, numIds int) {
677678

678679
for i := 0; i < numIds; i++ {
679680
backendName := fmt.Sprintf("backend%d", i+1)
681+
poolName := fmt.Sprintf("pool%d", i+1)
680682
volumeName := fmt.Sprintf("volume%d", i+1)
681683
snapshotName := fmt.Sprintf("snapshot%d", i+1)
682684
nodeName := fmt.Sprintf("node%d", i+1)
683685
storageClassName := fmt.Sprintf("sc%d", i+1)
684686
subordinateVolumeName := fmt.Sprintf("subvol%d", i+1)
685687

686688
// Add some test data to avoid nil pointer dereferences
687-
backends.lock()
688-
backends.data[backendName] = getMockBackendWithMap(mockCtrl, map[string]string{
689+
mockBackend := getMockBackendWithMap(mockCtrl, map[string]string{
689690
"name": backendName,
690691
"driverName": "test-driver",
691692
"uuid": backendName,
692693
"uniqueKey": backendName,
693694
"state": "online",
694695
})
696+
697+
mockPool := mockstorage.NewMockPool(mockCtrl)
698+
mockPool.EXPECT().SetBackend(mockBackend).AnyTimes()
699+
mockPoolMap := sync.Map{}
700+
mockPoolMap.Store(poolName, mockPool)
701+
mockBackend.EXPECT().StoragePools().Return(&mockPoolMap).AnyTimes()
702+
703+
backends.lock()
704+
backends.data[backendName] = mockBackend
695705
backends.key.data[backendName] = backendName
696706
backends.unlock()
697707

core/concurrent_core.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
"github.com/netapp/trident/config"
2121
db "github.com/netapp/trident/core/concurrent_cache"
22+
"github.com/netapp/trident/core/metrics"
2223
"github.com/netapp/trident/frontend"
2324
controllerhelpers "github.com/netapp/trident/frontend/csi/controller_helpers"
2425
. "github.com/netapp/trident/logging"
@@ -248,6 +249,9 @@ func (o *ConcurrentTridentOrchestrator) bootstrap(ctx context.Context) error {
248249

249250
o.RebuildStorageClassPoolMap(ctx)
250251

252+
metrics.TridentBuildInfo.WithLabelValues(config.BuildHash,
253+
config.OrchestratorVersion.ShortString(), config.BuildType).Set(float64(1))
254+
251255
return nil
252256
}
253257

0 commit comments

Comments
 (0)