@@ -113,9 +113,9 @@ type (
113
113
// FailoverEvent is the failover information to be stored for each failover event in domain data
114
114
FailoverEvent struct {
115
115
EventTime time.Time `json:"eventTime"`
116
- FromCluster string `json:"fromCluster"`
117
- ToCluster string `json:"toCluster"`
118
- FailoverType string `json:"failoverType"`
116
+ FromCluster string `json:"fromCluster,omitempty "`
117
+ ToCluster string `json:"toCluster,omitempty "`
118
+ FailoverType string `json:"failoverType,omitempty "`
119
119
}
120
120
121
121
// FailoverHistory is the history of failovers for a domain limited by the FailoverHistoryMaxSize config
@@ -257,6 +257,7 @@ func (d *handlerImpl) RegisterDomain(
257
257
if err != nil {
258
258
return err
259
259
}
260
+
260
261
replicationConfig := & persistence.DomainReplicationConfig {
261
262
ActiveClusterName : activeClusterName ,
262
263
Clusters : clusters ,
@@ -476,6 +477,7 @@ func (d *handlerImpl) UpdateDomain(
476
477
477
478
// Update replication config
478
479
replicationConfig , replicationConfigChanged , activeClusterChanged , err := d .updateReplicationConfig (
480
+ getResponse .Info .Name ,
479
481
replicationConfig ,
480
482
updateRequest ,
481
483
)
@@ -535,14 +537,18 @@ func (d *handlerImpl) UpdateDomain(
535
537
gracefulFailoverEndTime = nil
536
538
previousFailoverVersion = constants .InitialPreviousFailoverVersion
537
539
}
538
- failoverVersion = d .clusterMetadata .GetNextFailoverVersion (
539
- replicationConfig .ActiveClusterName ,
540
- failoverVersion ,
541
- updateRequest .Name ,
542
- )
543
- err = updateFailoverHistory (info , d .config , now , currentActiveCluster , * updateRequest .ActiveClusterName , failoverType )
544
- if err != nil {
545
- d .logger .Warn ("failed to update failover history" , tag .Error (err ))
540
+
541
+ if ! replicationConfig .IsActiveActive () {
542
+ failoverVersion = d .clusterMetadata .GetNextFailoverVersion (
543
+ replicationConfig .ActiveClusterName ,
544
+ failoverVersion ,
545
+ updateRequest .Name ,
546
+ )
547
+
548
+ err = updateFailoverHistory (info , d .config , now , currentActiveCluster , * updateRequest .ActiveClusterName , failoverType )
549
+ if err != nil {
550
+ d .logger .Warn ("failed to update failover history" , tag .Error (err ))
551
+ }
546
552
}
547
553
548
554
failoverNotificationVersion = notificationVersion
@@ -950,6 +956,7 @@ func (d *handlerImpl) createResponse(
950
956
replicationConfigResult := & types.DomainReplicationConfiguration {
951
957
ActiveClusterName : replicationConfig .ActiveClusterName ,
952
958
Clusters : clusters ,
959
+ ActiveClusters : replicationConfig .ActiveClusters ,
953
960
}
954
961
955
962
return infoResult , configResult , replicationConfigResult
@@ -1207,6 +1214,7 @@ func (d *handlerImpl) updateDeleteBadBinary(
1207
1214
}
1208
1215
1209
1216
func (d * handlerImpl ) updateReplicationConfig (
1217
+ domainName string ,
1210
1218
config * persistence.DomainReplicationConfig ,
1211
1219
updateRequest * types.UpdateDomainRequest ,
1212
1220
) (* persistence.DomainReplicationConfig , bool , bool , error ) {
@@ -1236,7 +1244,44 @@ func (d *handlerImpl) updateReplicationConfig(
1236
1244
config .ActiveClusterName = * updateRequest .ActiveClusterName
1237
1245
}
1238
1246
1239
- // TODO(active-active): handle active-active case here which would be updateRequest.ActiveClusters != nil.
1247
+ if updateRequest .ActiveClusters != nil && updateRequest .ActiveClusters .ActiveClustersByRegion != nil {
1248
+ existingActiveClusters := config .ActiveClusters
1249
+ finalActiveClusters := make (map [string ]types.ActiveClusterInfo )
1250
+
1251
+ // first add the ones that are not touched
1252
+ for region , activeCluster := range existingActiveClusters .ActiveClustersByRegion {
1253
+ if _ , ok := updateRequest .ActiveClusters .ActiveClustersByRegion [region ]; ! ok {
1254
+ finalActiveClusters [region ] = activeCluster
1255
+ }
1256
+ }
1257
+
1258
+ // then add the ones that are modified
1259
+ for region , activeCluster := range updateRequest .ActiveClusters .ActiveClustersByRegion {
1260
+ existingActiveCluster , ok := existingActiveClusters .ActiveClustersByRegion [region ]
1261
+ if ! ok {
1262
+ // a cluster is being activated on a region that didn't have any active cluster before
1263
+ // initialize failover version to the initial failover version of the cluster
1264
+ activeCluster .FailoverVersion = d .clusterMetadata .GetNextFailoverVersion (activeCluster .ActiveClusterName , 0 , domainName )
1265
+ finalActiveClusters [region ] = activeCluster
1266
+ continue
1267
+ }
1268
+
1269
+ // handle modification of an active cluster change on a region that had an active cluster before
1270
+ if existingActiveCluster .ActiveClusterName != activeCluster .ActiveClusterName {
1271
+ // a cluster is being deactivated on a region that had an active cluster before
1272
+ // set failover version to the next failover version of the newcluster
1273
+ activeCluster .FailoverVersion = d .clusterMetadata .GetNextFailoverVersion (activeCluster .ActiveClusterName , existingActiveCluster .FailoverVersion , domainName )
1274
+ finalActiveClusters [region ] = activeCluster
1275
+ } else {
1276
+ // no update case, just copy the existing active cluster
1277
+ finalActiveClusters [region ] = activeCluster
1278
+ }
1279
+ }
1280
+ config .ActiveClusters = & types.ActiveClusters {
1281
+ ActiveClustersByRegion : finalActiveClusters ,
1282
+ }
1283
+ activeClusterUpdated = true
1284
+ }
1240
1285
1241
1286
return config , clusterUpdated , activeClusterUpdated , nil
1242
1287
}
@@ -1251,7 +1296,7 @@ func (d *handlerImpl) handleGracefulFailover(
1251
1296
isGlobalDomain bool ,
1252
1297
) (* int64 , int64 , error ) {
1253
1298
// must update active cluster on a global domain
1254
- if ! activeClusterChanged || ! isGlobalDomain {
1299
+ if ! activeClusterChanged || ! isGlobalDomain || replicationConfig . IsActiveActive () {
1255
1300
return nil , 0 , errInvalidGracefulFailover
1256
1301
}
1257
1302
// must start with the passive -> active cluster
0 commit comments