@@ -97,15 +97,16 @@ type (
97
97
}
98
98
99
99
DefaultDomainCache struct {
100
- status int32
101
- shutdownChan chan struct {}
102
- clusterGroup string
103
- cacheNameToID * atomic.Value
104
- cacheByID * atomic.Value
105
- domainManager persistence.DomainManager
106
- timeSource clock.TimeSource
107
- scope metrics.Scope
108
- logger log.Logger
100
+ status int32
101
+ shutdownChan chan struct {}
102
+ clusterGroup string
103
+ clusterMetadata cluster.Metadata
104
+ cacheNameToID * atomic.Value
105
+ cacheByID * atomic.Value
106
+ domainManager persistence.DomainManager
107
+ timeSource clock.TimeSource
108
+ scope metrics.Scope
109
+ logger log.Logger
109
110
110
111
// refresh lock is used to guarantee at most one
111
112
// coroutine is doing domain refreshment
@@ -126,11 +127,12 @@ type (
126
127
127
128
// DomainCacheEntry contains the info and config for a domain
128
129
DomainCacheEntry struct {
129
- mu sync.RWMutex
130
- info * persistence.DomainInfo
131
- config * persistence.DomainConfig
132
- replicationConfig * persistence.DomainReplicationConfig
133
- configVersion int64
130
+ mu sync.RWMutex
131
+ info * persistence.DomainInfo
132
+ config * persistence.DomainConfig
133
+ replicationConfig * persistence.DomainReplicationConfig
134
+ configVersion int64
135
+ // failoverVersion is the failover version of domain's active cluster
134
136
failoverVersion int64
135
137
isGlobalDomain bool
136
138
failoverNotificationVersion int64
@@ -169,6 +171,7 @@ func NewDomainCache(
169
171
status : domainCacheInitialized ,
170
172
shutdownChan : make (chan struct {}),
171
173
clusterGroup : getClusterGroupIdentifier (metadata ),
174
+ clusterMetadata : metadata ,
172
175
cacheNameToID : & atomic.Value {},
173
176
cacheByID : & atomic.Value {},
174
177
domainManager : domainManager ,
@@ -459,6 +462,8 @@ func (c *DefaultDomainCache) refreshDomainsLocked() error {
459
462
for continuePage {
460
463
ctx , cancel := context .WithTimeout (context .Background (), domainCachePersistenceTimeout )
461
464
request .NextPageToken = token
465
+ // TODO: update DB layer to support ActiveClusterNames
466
+ // Also think about how to support failover overrides and rebalance.
462
467
response , err := c .domainManager .ListDomains (ctx , request )
463
468
cancel ()
464
469
if err != nil {
@@ -496,6 +501,7 @@ UpdateLoop:
496
501
c .logger .Info ("Domain notification is not less than than metadata notification version" , tag .WorkflowDomainName (domain .GetInfo ().Name ))
497
502
break UpdateLoop
498
503
}
504
+
499
505
triggerCallback , nextEntry , err := c .updateIDToDomainCache (newCacheByID , domain .info .ID , domain )
500
506
if err != nil {
501
507
return err
@@ -506,6 +512,7 @@ UpdateLoop:
506
512
metrics .DomainTypeTag (nextEntry .isGlobalDomain ),
507
513
metrics .ClusterGroupTag (c .clusterGroup ),
508
514
metrics .ActiveClusterTag (nextEntry .replicationConfig .ActiveClusterName ),
515
+ metrics .IsActiveActiveDomainTag (nextEntry .replicationConfig .IsActiveActive ()),
509
516
).UpdateGauge (metrics .ActiveClusterGauge , 1 )
510
517
511
518
c .updateNameToIDCache (newCacheNameToID , nextEntry .info .Name , nextEntry .info .ID )
@@ -625,6 +632,11 @@ func (c *DefaultDomainCache) getDomainByID(
625
632
) (* DomainCacheEntry , error ) {
626
633
627
634
var result * DomainCacheEntry
635
+ defer func () {
636
+ if result != nil {
637
+ c .logger .Debugf ("GetDomainByID returning domain %s, failoverVersion: %d" , result .info .Name , result .failoverVersion )
638
+ }
639
+ }()
628
640
entry , cacheHit := c .cacheByID .Load ().(Cache ).Get (id ).(* DomainCacheEntry )
629
641
if cacheHit {
630
642
entry .mu .RLock ()
@@ -695,7 +707,7 @@ func (c *DefaultDomainCache) buildEntryFromRecord(
695
707
696
708
// this is a shallow copy, but since the record is generated by persistence
697
709
// and only accessible here, it would be fine
698
- return & DomainCacheEntry {
710
+ entry := & DomainCacheEntry {
699
711
info : record .Info ,
700
712
config : record .Config ,
701
713
replicationConfig : record .ReplicationConfig ,
@@ -708,6 +720,8 @@ func (c *DefaultDomainCache) buildEntryFromRecord(
708
720
notificationVersion : record .NotificationVersion ,
709
721
initialized : true ,
710
722
}
723
+
724
+ return entry
711
725
}
712
726
713
727
func copyResetBinary (bins types.BadBinaries ) types.BadBinaries {
@@ -749,7 +763,12 @@ func (entry *DomainCacheEntry) duplicate() *DomainCacheEntry {
749
763
ActiveClusterName : entry .replicationConfig .ActiveClusterName ,
750
764
}
751
765
for _ , clusterCfg := range entry .replicationConfig .Clusters {
752
- result .replicationConfig .Clusters = append (result .replicationConfig .Clusters , & * clusterCfg )
766
+ c := * clusterCfg
767
+ result .replicationConfig .Clusters = append (result .replicationConfig .Clusters , & c )
768
+ }
769
+ for _ , clusterCfg := range entry .replicationConfig .ActiveClusters {
770
+ c := * clusterCfg
771
+ result .replicationConfig .ActiveClusters = append (result .replicationConfig .ActiveClusters , & c )
753
772
}
754
773
result .configVersion = entry .configVersion
755
774
result .failoverVersion = entry .failoverVersion
@@ -821,12 +840,24 @@ func (entry *DomainCacheEntry) IsActiveIn(currentCluster string) (bool, error) {
821
840
}
822
841
823
842
domainName := entry .GetInfo ().Name
824
- activeCluster := entry .GetReplicationConfig ().ActiveClusterName
825
-
826
843
if entry .IsDomainPendingActive () {
827
844
return false , errors .NewDomainPendingActiveError (domainName , currentCluster )
828
845
}
829
846
847
+ if len (entry .GetReplicationConfig ().ActiveClusters ) > 0 {
848
+ // TODO: optimize this loop by using a map
849
+ var activeClusters []string
850
+ for _ , cl := range entry .GetReplicationConfig ().ActiveClusters {
851
+ if cl .ClusterName == currentCluster {
852
+ return true , nil
853
+ }
854
+ activeClusters = append (activeClusters , cl .ClusterName )
855
+ }
856
+
857
+ return false , errors .NewDomainNotActiveError (domainName , currentCluster , activeClusters ... )
858
+ }
859
+
860
+ activeCluster := entry .GetReplicationConfig ().ActiveClusterName
830
861
if currentCluster != activeCluster {
831
862
return false , errors .NewDomainNotActiveError (domainName , currentCluster , activeCluster )
832
863
}
0 commit comments