Skip to content

Commit 47a515f

Browse files
committed
Fix cache
1 parent 1589646 commit 47a515f

File tree

4 files changed

+55
-27
lines changed

4 files changed

+55
-27
lines changed

common/cache/domainCache.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,6 @@ func (entry *DomainCacheEntry) duplicate() *DomainCacheEntry {
771771
result.failoverEndTime = entry.failoverEndTime
772772
result.notificationVersion = entry.notificationVersion
773773
result.initialized = entry.initialized
774-
result.activeClusters = entry.activeClusters
775774
return result
776775
}
777776

@@ -904,9 +903,11 @@ func (entry *DomainCacheEntry) IsActiveIn(currentCluster string) bool {
904903
}
905904

906905
if entry.GetReplicationConfig().IsActiveActive() {
907-
for _, cl := range entry.GetReplicationConfig().ActiveClusters.ActiveClustersByRegion {
908-
if cl.ActiveClusterName == currentCluster {
909-
return true
906+
for _, scope := range entry.GetReplicationConfig().ActiveClusters.AttributeScopes {
907+
for _, cl := range scope.ClusterAttributes {
908+
if cl.ActiveClusterName == currentCluster {
909+
return true
910+
}
910911
}
911912
}
912913

@@ -1064,9 +1065,11 @@ func getActiveClusters(replicationConfig *persistence.DomainReplicationConfig) [
10641065
if !replicationConfig.IsActiveActive() {
10651066
return nil
10661067
}
1067-
activeClusters := make([]string, 0, len(replicationConfig.ActiveClusters.ActiveClustersByRegion))
1068-
for _, cl := range replicationConfig.ActiveClusters.ActiveClustersByRegion {
1069-
activeClusters = append(activeClusters, cl.ActiveClusterName)
1068+
activeClusters := make([]string, 0, len(replicationConfig.ActiveClusters.AttributeScopes))
1069+
for _, scope := range replicationConfig.ActiveClusters.AttributeScopes {
1070+
for _, cl := range scope.ClusterAttributes {
1071+
activeClusters = append(activeClusters, cl.ActiveClusterName)
1072+
}
10701073
}
10711074
sort.Strings(activeClusters)
10721075
return activeClusters

common/cache/domainCache_test.go

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,13 @@ func Test_IsActiveIn(t *testing.T) {
330330
isGlobalDomain: true,
331331
currentCluster: "A",
332332
activeClusters: &types.ActiveClusters{
333-
ActiveClustersByRegion: map[string]types.ActiveClusterInfo{
334-
"region0": {ActiveClusterName: "A"},
335-
"region1": {ActiveClusterName: "B"},
333+
AttributeScopes: map[string]types.ClusterAttributeScope{
334+
"region": {
335+
ClusterAttributes: map[string]types.ActiveClusterInfo{
336+
"region0": {ActiveClusterName: "A"},
337+
"region1": {ActiveClusterName: "B"},
338+
},
339+
},
336340
},
337341
},
338342
expectIsActive: true,
@@ -342,9 +346,13 @@ func Test_IsActiveIn(t *testing.T) {
342346
isGlobalDomain: true,
343347
currentCluster: "C",
344348
activeClusters: &types.ActiveClusters{
345-
ActiveClustersByRegion: map[string]types.ActiveClusterInfo{
346-
"region0": {ActiveClusterName: "A"},
347-
"region1": {ActiveClusterName: "B"},
349+
AttributeScopes: map[string]types.ClusterAttributeScope{
350+
"region": {
351+
ClusterAttributes: map[string]types.ActiveClusterInfo{
352+
"region0": {ActiveClusterName: "A"},
353+
"region1": {ActiveClusterName: "B"},
354+
},
355+
},
348356
},
349357
},
350358
expectIsActive: false,
@@ -1223,14 +1231,16 @@ func Test_NewDomainNotActiveError(t *testing.T) {
12231231
nil,
12241232
true,
12251233
&persistence.DomainReplicationConfig{
1226-
ActiveClusters: &types.ActiveClusters{ActiveClustersByRegion: map[string]types.ActiveClusterInfo{
1227-
"region1": {
1228-
ActiveClusterName: "cluster1",
1229-
},
1230-
"region2": {
1231-
ActiveClusterName: "cluster2",
1234+
ActiveClusters: &types.ActiveClusters{
1235+
AttributeScopes: map[string]types.ClusterAttributeScope{
1236+
"region": {
1237+
ClusterAttributes: map[string]types.ActiveClusterInfo{
1238+
"region1": {ActiveClusterName: "cluster1"},
1239+
"region2": {ActiveClusterName: "cluster2"},
1240+
},
1241+
},
12321242
},
1233-
}},
1243+
},
12341244
},
12351245
0,
12361246
nil,
@@ -1273,14 +1283,16 @@ func Test_getActiveClusters(t *testing.T) {
12731283
msg: "active-active domain",
12741284
replicationConfig: &persistence.DomainReplicationConfig{
12751285
ActiveClusterName: "active",
1276-
ActiveClusters: &types.ActiveClusters{ActiveClustersByRegion: map[string]types.ActiveClusterInfo{
1277-
"region1": {
1278-
ActiveClusterName: "cluster1",
1279-
},
1280-
"region2": {
1281-
ActiveClusterName: "cluster2",
1286+
ActiveClusters: &types.ActiveClusters{
1287+
AttributeScopes: map[string]types.ClusterAttributeScope{
1288+
"region": {
1289+
ClusterAttributes: map[string]types.ActiveClusterInfo{
1290+
"region1": {ActiveClusterName: "cluster1"},
1291+
"region2": {ActiveClusterName: "cluster2"},
1292+
},
1293+
},
12821294
},
1283-
}},
1295+
},
12841296
},
12851297
expectedActiveClusters: []string{"cluster1", "cluster2"},
12861298
},

common/types/shared.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,8 +2600,13 @@ func (v *ActiveClusters) DeepCopy() *ActiveClusters {
26002600
for region, activeClusterInfo := range v.ActiveClustersByRegion {
26012601
activeClustersByRegion[region] = activeClusterInfo
26022602
}
2603+
attributeScopes := make(map[string]ClusterAttributeScope)
2604+
for scopeType, scope := range v.AttributeScopes {
2605+
attributeScopes[scopeType] = scope
2606+
}
26032607
return &ActiveClusters{
26042608
ActiveClustersByRegion: activeClustersByRegion,
2609+
AttributeScopes: attributeScopes,
26052610
}
26062611
}
26072612

common/types/shared_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ func TestActiveClustersConfigDeepCopy(t *testing.T) {
8484
FailoverVersion: 2,
8585
},
8686
},
87+
AttributeScopes: map[string]ClusterAttributeScope{
88+
"region": {
89+
ClusterAttributes: map[string]ActiveClusterInfo{
90+
"us-east-1": {ActiveClusterName: "us-east-1-cluster", FailoverVersion: 1},
91+
},
92+
},
93+
},
8794
}
8895

8996
tests := []struct {
@@ -101,6 +108,7 @@ func TestActiveClustersConfigDeepCopy(t *testing.T) {
101108
input: &ActiveClusters{},
102109
expect: &ActiveClusters{
103110
ActiveClustersByRegion: map[string]ActiveClusterInfo{},
111+
AttributeScopes: map[string]ClusterAttributeScope{},
104112
},
105113
},
106114
{

0 commit comments

Comments
 (0)