Skip to content

Commit 1166834

Browse files
reverting some changes to the failvoer endpoint for this PR
Signed-off-by: David Porter <[email protected]>
1 parent 428fc5f commit 1166834

File tree

1 file changed

+119
-118
lines changed

1 file changed

+119
-118
lines changed

common/domain/handler.go

Lines changed: 119 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,7 @@ func (d *handlerImpl) updateGlobalDomainConfiguration(ctx context.Context,
827827
return response, nil
828828
}
829829

830+
830831
func (d *handlerImpl) updateLocalDomain(ctx context.Context,
831832
updateRequest *types.UpdateDomainRequest,
832833
currentState *persistence.GetDomainResponse,
@@ -959,15 +960,14 @@ func (d *handlerImpl) FailoverDomain(
959960
wasActiveActive := replicationConfig.IsActiveActive()
960961
configVersion := getResponse.ConfigVersion
961962
failoverVersion := getResponse.FailoverVersion
963+
failoverNotificationVersion := getResponse.FailoverNotificationVersion
964+
isGlobalDomain := getResponse.IsGlobalDomain
962965
gracefulFailoverEndTime := getResponse.FailoverEndTime
963966
currentActiveCluster := replicationConfig.ActiveClusterName
964967
currentActiveClusters := replicationConfig.ActiveClusters.DeepCopy()
965968
previousFailoverVersion := getResponse.PreviousFailoverVersion
966969
lastUpdatedTime := time.Unix(0, getResponse.LastUpdatedTime)
967970

968-
// will be set to the notification version of the domain after the update
969-
var failoverNotificationVersion int64 = -1
970-
971971
updateRequest := &types.UpdateDomainRequest{
972972
Name: failoverRequest.DomainName,
973973
ActiveClusterName: failoverRequest.DomainActiveClusterName,
@@ -983,10 +983,6 @@ func (d *handlerImpl) FailoverDomain(
983983
return nil, err
984984
}
985985

986-
if !activeClusterChanged && !replicationConfigChanged {
987-
return nil, errInvalidFailoverNoChangeDetected
988-
}
989-
990986
// Handle graceful failover request
991987
if updateRequest.FailoverTimeoutInSeconds != nil {
992988
gracefulFailoverEndTime, previousFailoverVersion, err = d.handleGracefulFailover(
@@ -996,14 +992,14 @@ func (d *handlerImpl) FailoverDomain(
996992
gracefulFailoverEndTime,
997993
failoverVersion,
998994
activeClusterChanged,
999-
true,
995+
isGlobalDomain,
1000996
)
1001997
if err != nil {
1002998
return nil, err
1003999
}
10041000
}
10051001

1006-
err = d.validateDomainReplicationConfigForFailover(replicationConfig, replicationConfigChanged, activeClusterChanged)
1002+
err = d.validateGlobalDomainReplicationConfigForUpdateDomain(replicationConfig, replicationConfigChanged, activeClusterChanged)
10071003
if err != nil {
10081004
return nil, err
10091005
}
@@ -1020,110 +1016,112 @@ func (d *handlerImpl) FailoverDomain(
10201016
configVersion++
10211017
}
10221018

1023-
var failoverType constants.FailoverType = constants.FailoverTypeGrace
1024-
1025-
// Force failover cleans graceful failover state
1026-
if updateRequest.FailoverTimeoutInSeconds == nil {
1027-
failoverType = constants.FailoverTypeForce
1028-
gracefulFailoverEndTime = nil
1029-
previousFailoverVersion = constants.InitialPreviousFailoverVersion
1030-
}
1019+
if activeClusterChanged && isGlobalDomain {
1020+
var failoverType constants.FailoverType = constants.FailoverTypeGrace
10311021

1032-
// Cases:
1033-
// 1. active-passive domain's ActiveClusterName is changed
1034-
// 2. active-passive domain is being migrated to active-active
1035-
// 3. active-active domain's ActiveClusters is changed
1036-
isActiveActive := replicationConfig.IsActiveActive()
1037-
1038-
// case 1. active-passive domain's ActiveClusterName is changed
1039-
if !wasActiveActive && !isActiveActive {
1040-
failoverVersion = d.clusterMetadata.GetNextFailoverVersion(
1041-
replicationConfig.ActiveClusterName,
1042-
failoverVersion,
1043-
updateRequest.Name,
1044-
)
1045-
1046-
d.logger.Debug("active-passive domain failover",
1047-
tag.WorkflowDomainName(info.Name),
1048-
tag.Dynamic("failover-version", failoverVersion),
1049-
tag.Dynamic("failover-type", failoverType),
1050-
)
1051-
1052-
err = updateFailoverHistoryInDomainData(info, d.config, NewFailoverEvent(
1053-
now,
1054-
failoverType,
1055-
&currentActiveCluster,
1056-
updateRequest.ActiveClusterName,
1057-
nil,
1058-
nil,
1059-
))
1060-
if err != nil {
1061-
d.logger.Warn("failed to update failover history", tag.Error(err))
1022+
// Force failover cleans graceful failover state
1023+
if updateRequest.FailoverTimeoutInSeconds == nil {
1024+
failoverType = constants.FailoverTypeForce
1025+
gracefulFailoverEndTime = nil
1026+
previousFailoverVersion = constants.InitialPreviousFailoverVersion
10621027
}
1063-
}
1064-
1065-
// case 2. active-passive domain is being migrated to active-active
1066-
if !wasActiveActive && isActiveActive {
1067-
// for active-passive to active-active migration,
1068-
// we increment failover version so top level failoverVersion is updated and domain data is replicated.
10691028

1070-
failoverVersion = d.clusterMetadata.GetNextFailoverVersion(
1071-
replicationConfig.ActiveClusterName,
1072-
failoverVersion+1, //todo: (active-active): Let's review if we need to increment
1073-
// this for cluster-attr failover changes. It may not be necessary to increment
1074-
updateRequest.Name,
1075-
)
1076-
1077-
d.logger.Debug("active-passive domain is being migrated to active-active",
1078-
tag.WorkflowDomainName(info.Name),
1079-
tag.Dynamic("failover-version", failoverVersion),
1080-
tag.Dynamic("failover-type", failoverType),
1081-
)
1082-
1083-
err = updateFailoverHistoryInDomainData(info, d.config, NewFailoverEvent(
1084-
now,
1085-
failoverType,
1086-
&currentActiveCluster,
1087-
updateRequest.ActiveClusterName,
1088-
nil,
1089-
replicationConfig.ActiveClusters,
1090-
))
1091-
if err != nil {
1092-
d.logger.Warn("failed to update failover history", tag.Error(err))
1029+
// Cases:
1030+
// 1. active-passive domain's ActiveClusterName is changed
1031+
// 2. active-passive domain is being migrated to active-active
1032+
// 3. active-active domain's ActiveClusters is changed
1033+
isActiveActive := replicationConfig.IsActiveActive()
1034+
1035+
// case 1. active-passive domain's ActiveClusterName is changed
1036+
if !wasActiveActive && !isActiveActive {
1037+
failoverVersion = d.clusterMetadata.GetNextFailoverVersion(
1038+
replicationConfig.ActiveClusterName,
1039+
failoverVersion,
1040+
updateRequest.Name,
1041+
)
1042+
1043+
d.logger.Debug("active-passive domain failover",
1044+
tag.WorkflowDomainName(info.Name),
1045+
tag.Dynamic("failover-version", failoverVersion),
1046+
tag.Dynamic("failover-type", failoverType),
1047+
)
1048+
1049+
err = updateFailoverHistoryInDomainData(info, d.config, NewFailoverEvent(
1050+
now,
1051+
failoverType,
1052+
&currentActiveCluster,
1053+
updateRequest.ActiveClusterName,
1054+
nil,
1055+
nil,
1056+
))
1057+
if err != nil {
1058+
d.logger.Warn("failed to update failover history", tag.Error(err))
1059+
}
10931060
}
1094-
}
10951061

1096-
// case 3. active-active domain's ActiveClusters is changed
1097-
if wasActiveActive && isActiveActive {
1098-
// top level failover version is not used for task versions for active-active domains but we still increment it
1099-
// to indicate there was a change in replication config
1100-
failoverVersion = d.clusterMetadata.GetNextFailoverVersion(
1101-
replicationConfig.ActiveClusterName,
1102-
failoverVersion+1, //todo: (active-active): Let's review if we need to increment
1103-
// this for cluster-attr failover changes. It may not be necessary to increment
1104-
updateRequest.Name,
1105-
)
1106-
1107-
d.logger.Debug("active-active domain failover",
1108-
tag.WorkflowDomainName(info.Name),
1109-
tag.Dynamic("failover-version", failoverVersion),
1110-
tag.Dynamic("failover-type", failoverType),
1111-
)
1062+
// case 2. active-passive domain is being migrated to active-active
1063+
if !wasActiveActive && isActiveActive {
1064+
// for active-passive to active-active migration,
1065+
// we increment failover version so top level failoverVersion is updated and domain data is replicated.
1066+
1067+
failoverVersion = d.clusterMetadata.GetNextFailoverVersion(
1068+
replicationConfig.ActiveClusterName,
1069+
failoverVersion+1, //todo: (active-active): Let's review if we need to increment
1070+
// this for cluster-attr failover changes. It may not be necessary to increment
1071+
updateRequest.Name,
1072+
)
1073+
1074+
d.logger.Debug("active-passive domain is being migrated to active-active",
1075+
tag.WorkflowDomainName(info.Name),
1076+
tag.Dynamic("failover-version", failoverVersion),
1077+
tag.Dynamic("failover-type", failoverType),
1078+
)
1079+
1080+
err = updateFailoverHistoryInDomainData(info, d.config, NewFailoverEvent(
1081+
now,
1082+
failoverType,
1083+
&currentActiveCluster,
1084+
updateRequest.ActiveClusterName,
1085+
nil,
1086+
replicationConfig.ActiveClusters,
1087+
))
1088+
if err != nil {
1089+
d.logger.Warn("failed to update failover history", tag.Error(err))
1090+
}
1091+
}
11121092

1113-
err = updateFailoverHistoryInDomainData(info, d.config, NewFailoverEvent(
1114-
now,
1115-
failoverType,
1116-
&currentActiveCluster,
1117-
nil,
1118-
currentActiveClusters,
1119-
replicationConfig.ActiveClusters,
1120-
))
1121-
if err != nil {
1122-
d.logger.Warn("failed to update failover history", tag.Error(err))
1093+
// case 3. active-active domain's ActiveClusters is changed
1094+
if wasActiveActive && isActiveActive {
1095+
// top level failover version is not used for task versions for active-active domains but we still increment it
1096+
// to indicate there was a change in replication config
1097+
failoverVersion = d.clusterMetadata.GetNextFailoverVersion(
1098+
replicationConfig.ActiveClusterName,
1099+
failoverVersion+1, //todo: (active-active): Let's review if we need to increment
1100+
// this for cluster-attr failover changes. It may not be necessary to increment
1101+
updateRequest.Name,
1102+
)
1103+
1104+
d.logger.Debug("active-active domain failover",
1105+
tag.WorkflowDomainName(info.Name),
1106+
tag.Dynamic("failover-version", failoverVersion),
1107+
tag.Dynamic("failover-type", failoverType),
1108+
)
1109+
1110+
err = updateFailoverHistoryInDomainData(info, d.config, NewFailoverEvent(
1111+
now,
1112+
failoverType,
1113+
&currentActiveCluster,
1114+
nil,
1115+
currentActiveClusters,
1116+
replicationConfig.ActiveClusters,
1117+
))
1118+
if err != nil {
1119+
d.logger.Warn("failed to update failover history", tag.Error(err))
1120+
}
11231121
}
1124-
}
11251122

1126-
failoverNotificationVersion = notificationVersion
1123+
failoverNotificationVersion = notificationVersion
1124+
}
11271125

11281126
lastUpdatedTime = now
11291127

@@ -1149,18 +1147,20 @@ func (d *handlerImpl) FailoverDomain(
11491147
return nil, err
11501148
}
11511149

1152-
if err = d.domainReplicator.HandleTransmissionTask(
1153-
ctx,
1154-
types.DomainOperationUpdate,
1155-
info,
1156-
config,
1157-
replicationConfig,
1158-
configVersion,
1159-
failoverVersion,
1160-
previousFailoverVersion,
1161-
true,
1162-
); err != nil {
1163-
return nil, err
1150+
if isGlobalDomain {
1151+
if err = d.domainReplicator.HandleTransmissionTask(
1152+
ctx,
1153+
types.DomainOperationUpdate,
1154+
info,
1155+
config,
1156+
replicationConfig,
1157+
configVersion,
1158+
failoverVersion,
1159+
previousFailoverVersion,
1160+
isGlobalDomain,
1161+
); err != nil {
1162+
return nil, err
1163+
}
11641164
}
11651165

11661166
domainInfo, configuration, replicationConfiguration := d.createResponse(info, config, replicationConfig)
@@ -1174,10 +1174,11 @@ func (d *handlerImpl) FailoverDomain(
11741174
Configuration: configuration,
11751175
ReplicationConfiguration: replicationConfiguration,
11761176
FailoverVersion: failoverVersion,
1177-
IsGlobalDomain: true,
1177+
IsGlobalDomain: isGlobalDomain,
11781178
}, nil
11791179
}
11801180

1181+
11811182
// DeleteDomain deletes a domain
11821183
func (d *handlerImpl) DeleteDomain(
11831184
ctx context.Context,

0 commit comments

Comments
 (0)