Skip to content

Commit 53d9b92

Browse files
authored
fix: Revert "chore(active-active): remove deprecated fields (#7388)" (#7397)
This reverts commit d09cb44. <!-- Describe what has changed in this PR --> **What changed?** <!-- Tell your future self why have you made these changes --> **Why?** <!-- How have you verified this change? Tested locally? Added a unit test? Checked in staging env? --> **How did you test it?** <!-- Assuming the worst case, what can be broken when deploying this change to production? --> **Potential risks** <!-- Is it notable for release? e.g. schema updates, configuration or data migration required? If so, please mention it, and also update CHANGELOG.md --> **Release notes** <!-- Is there any documentation updates should be made for config, https://cadenceworkflow.io/docs/operation-guide/setup/ ? If so, please open an PR in https://github.com/cadence-workflow/cadence-docs --> **Documentation Changes**
1 parent a443a93 commit 53d9b92

File tree

13 files changed

+201
-50
lines changed

13 files changed

+201
-50
lines changed

common/persistence/execution_manager_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,10 +1652,8 @@ func sampleActiveClusterSelectionPolicyData() *DataBlob {
16521652

16531653
func sampleActiveClusterSelectionPolicy() *types.ActiveClusterSelectionPolicy {
16541654
return &types.ActiveClusterSelectionPolicy{
1655-
ClusterAttribute: &types.ClusterAttribute{
1656-
Scope: "region",
1657-
Name: "us-west-1",
1658-
},
1655+
ActiveClusterSelectionStrategy: types.ActiveClusterSelectionStrategyRegionSticky.Ptr(),
1656+
StickyRegion: "region-1",
16591657
}
16601658
}
16611659

common/persistence/persistence-tests/executionManagerTest.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,10 +1498,8 @@ func (s *ExecutionManagerSuite) TestGetWorkflow() {
14981498
Memo: testMemo,
14991499
PartitionConfig: testPartitionConfig,
15001500
ActiveClusterSelectionPolicy: &types.ActiveClusterSelectionPolicy{
1501-
ClusterAttribute: &types.ClusterAttribute{
1502-
Scope: "region",
1503-
Name: "us-west-1",
1504-
},
1501+
ActiveClusterSelectionStrategy: types.ActiveClusterSelectionStrategyRegionSticky.Ptr(),
1502+
StickyRegion: "region1",
15051503
},
15061504
},
15071505
ExecutionStats: &p.ExecutionStats{

common/persistence/serializer_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,9 @@ func generateActiveClusters() *types.ActiveClusters {
539539

540540
func generateActiveClusterSelectionPolicy() *types.ActiveClusterSelectionPolicy {
541541
return &types.ActiveClusterSelectionPolicy{
542-
ClusterAttribute: &types.ClusterAttribute{
543-
Scope: "region",
544-
Name: "us-west-1",
545-
},
542+
ActiveClusterSelectionStrategy: types.ActiveClusterSelectionStrategyRegionSticky.Ptr(),
543+
StickyRegion: "region1",
544+
ExternalEntityType: "externalEntityType1",
545+
ExternalEntityKey: "externalEntityKey1",
546546
}
547547
}

common/types/mapper/proto/api.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6752,6 +6752,30 @@ func FromActiveClusterSelectionPolicy(p *types.ActiveClusterSelectionPolicy) *ap
67526752
if p == nil {
67536753
return nil
67546754
}
6755+
// TODO(active-active): Remove the switch statement once the strategy is removed
6756+
switch p.GetStrategy() {
6757+
case types.ActiveClusterSelectionStrategyRegionSticky:
6758+
return &apiv1.ActiveClusterSelectionPolicy{
6759+
Strategy: apiv1.ActiveClusterSelectionStrategy_ACTIVE_CLUSTER_SELECTION_STRATEGY_REGION_STICKY,
6760+
StrategyConfig: &apiv1.ActiveClusterSelectionPolicy_ActiveClusterStickyRegionConfig{
6761+
ActiveClusterStickyRegionConfig: &apiv1.ActiveClusterStickyRegionConfig{
6762+
StickyRegion: p.StickyRegion,
6763+
},
6764+
},
6765+
ClusterAttribute: FromClusterAttribute(p.ClusterAttribute),
6766+
}
6767+
case types.ActiveClusterSelectionStrategyExternalEntity:
6768+
return &apiv1.ActiveClusterSelectionPolicy{
6769+
Strategy: apiv1.ActiveClusterSelectionStrategy_ACTIVE_CLUSTER_SELECTION_STRATEGY_EXTERNAL_ENTITY,
6770+
StrategyConfig: &apiv1.ActiveClusterSelectionPolicy_ActiveClusterExternalEntityConfig{
6771+
ActiveClusterExternalEntityConfig: &apiv1.ActiveClusterExternalEntityConfig{
6772+
ExternalEntityType: p.ExternalEntityType,
6773+
ExternalEntityKey: p.ExternalEntityKey,
6774+
},
6775+
},
6776+
ClusterAttribute: FromClusterAttribute(p.ClusterAttribute),
6777+
}
6778+
}
67556779
return &apiv1.ActiveClusterSelectionPolicy{
67566780
ClusterAttribute: FromClusterAttribute(p.ClusterAttribute),
67576781
}
@@ -6761,6 +6785,22 @@ func ToActiveClusterSelectionPolicy(p *apiv1.ActiveClusterSelectionPolicy) *type
67616785
if p == nil {
67626786
return nil
67636787
}
6788+
// TODO(active-active): Remove the switch statement once the strategy is removed
6789+
switch p.Strategy {
6790+
case apiv1.ActiveClusterSelectionStrategy_ACTIVE_CLUSTER_SELECTION_STRATEGY_REGION_STICKY:
6791+
return &types.ActiveClusterSelectionPolicy{
6792+
ActiveClusterSelectionStrategy: types.ActiveClusterSelectionStrategyRegionSticky.Ptr(),
6793+
StickyRegion: p.StrategyConfig.(*apiv1.ActiveClusterSelectionPolicy_ActiveClusterStickyRegionConfig).ActiveClusterStickyRegionConfig.StickyRegion,
6794+
ClusterAttribute: ToClusterAttribute(p.ClusterAttribute),
6795+
}
6796+
case apiv1.ActiveClusterSelectionStrategy_ACTIVE_CLUSTER_SELECTION_STRATEGY_EXTERNAL_ENTITY:
6797+
return &types.ActiveClusterSelectionPolicy{
6798+
ActiveClusterSelectionStrategy: types.ActiveClusterSelectionStrategyExternalEntity.Ptr(),
6799+
ExternalEntityType: p.StrategyConfig.(*apiv1.ActiveClusterSelectionPolicy_ActiveClusterExternalEntityConfig).ActiveClusterExternalEntityConfig.ExternalEntityType,
6800+
ExternalEntityKey: p.StrategyConfig.(*apiv1.ActiveClusterSelectionPolicy_ActiveClusterExternalEntityConfig).ActiveClusterExternalEntityConfig.ExternalEntityKey,
6801+
ClusterAttribute: ToClusterAttribute(p.ClusterAttribute),
6802+
}
6803+
}
67646804
return &types.ActiveClusterSelectionPolicy{
67656805
ClusterAttribute: ToClusterAttribute(p.ClusterAttribute),
67666806
}

common/types/mapper/thrift/shared.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7045,7 +7045,11 @@ func FromActiveClusterSelectionPolicy(t *types.ActiveClusterSelectionPolicy) *sh
70457045
return nil
70467046
}
70477047
return &shared.ActiveClusterSelectionPolicy{
7048-
ClusterAttribute: FromClusterAttribute(t.ClusterAttribute),
7048+
Strategy: FromActiveClusterSelectionStrategy(t.ActiveClusterSelectionStrategy),
7049+
ExternalEntityType: &t.ExternalEntityType,
7050+
ExternalEntityKey: &t.ExternalEntityKey,
7051+
StickyRegion: &t.StickyRegion,
7052+
ClusterAttribute: FromClusterAttribute(t.ClusterAttribute),
70497053
}
70507054
}
70517055

@@ -7054,10 +7058,40 @@ func ToActiveClusterSelectionPolicy(t *shared.ActiveClusterSelectionPolicy) *typ
70547058
return nil
70557059
}
70567060
return &types.ActiveClusterSelectionPolicy{
7057-
ClusterAttribute: ToClusterAttribute(t.ClusterAttribute),
7061+
ActiveClusterSelectionStrategy: ToActiveClusterSelectionStrategy(t.Strategy),
7062+
ExternalEntityType: *t.ExternalEntityType,
7063+
ExternalEntityKey: *t.ExternalEntityKey,
7064+
StickyRegion: *t.StickyRegion,
7065+
ClusterAttribute: ToClusterAttribute(t.ClusterAttribute),
70587066
}
70597067
}
70607068

7069+
func FromActiveClusterSelectionStrategy(t *types.ActiveClusterSelectionStrategy) *shared.ActiveClusterSelectionStrategy {
7070+
if t == nil {
7071+
return nil
7072+
}
7073+
switch *t {
7074+
case types.ActiveClusterSelectionStrategyRegionSticky:
7075+
return shared.ActiveClusterSelectionStrategyRegionSticky.Ptr()
7076+
case types.ActiveClusterSelectionStrategyExternalEntity:
7077+
return shared.ActiveClusterSelectionStrategyExternalEntity.Ptr()
7078+
}
7079+
panic("unexpected enum value")
7080+
}
7081+
7082+
func ToActiveClusterSelectionStrategy(t *shared.ActiveClusterSelectionStrategy) *types.ActiveClusterSelectionStrategy {
7083+
if t == nil {
7084+
return nil
7085+
}
7086+
switch *t {
7087+
case shared.ActiveClusterSelectionStrategyRegionSticky:
7088+
return types.ActiveClusterSelectionStrategyRegionSticky.Ptr()
7089+
case shared.ActiveClusterSelectionStrategyExternalEntity:
7090+
return types.ActiveClusterSelectionStrategyExternalEntity.Ptr()
7091+
}
7092+
panic("unexpected enum value")
7093+
}
7094+
70617095
// FromWorkflowExecutionTerminatedEventAttributes converts internal WorkflowExecutionTerminatedEventAttributes type to thrift
70627096
func FromWorkflowExecutionTerminatedEventAttributes(t *types.WorkflowExecutionTerminatedEventAttributes) *shared.WorkflowExecutionTerminatedEventAttributes {
70637097
if t == nil {

common/types/mapper/thrift/shared_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3595,6 +3595,8 @@ func TestActiveClusterSelectionPolicyConversion(t *testing.T) {
35953595
testCases := []*types.ActiveClusterSelectionPolicy{
35963596
nil,
35973597
{},
3598+
&testdata.ActiveClusterSelectionPolicyExternalEntity,
3599+
&testdata.ActiveClusterSelectionPolicyRegionSticky,
35983600
&testdata.ActiveClusterSelectionPolicyWithClusterAttribute,
35993601
}
36003602

common/types/shared.go

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2759,7 +2759,22 @@ func (c *ClusterAttribute) Equals(other *ClusterAttribute) bool {
27592759
return c.Scope == other.Scope && c.Name == other.Name
27602760
}
27612761

2762+
type ActiveClusterSelectionStrategy int32
2763+
2764+
const (
2765+
ActiveClusterSelectionStrategyRegionSticky ActiveClusterSelectionStrategy = iota
2766+
ActiveClusterSelectionStrategyExternalEntity
2767+
)
2768+
27622769
type ActiveClusterSelectionPolicy struct {
2770+
ActiveClusterSelectionStrategy *ActiveClusterSelectionStrategy `json:"activeClusterSelectionStrategy,omitempty"`
2771+
2772+
StickyRegion string `json:"stickyRegion,omitempty"`
2773+
2774+
ExternalEntityType string `json:"externalEntityType,omitempty"`
2775+
ExternalEntityKey string `json:"externalEntityKey,omitempty"`
2776+
2777+
// TODO(active-active): Remove the fields above
27632778
ClusterAttribute *ClusterAttribute `json:"clusterAttribute,omitempty" yaml:"clusterAttribute,omitempty"`
27642779
}
27652780

@@ -2778,7 +2793,54 @@ func (p *ActiveClusterSelectionPolicy) Equals(other *ActiveClusterSelectionPolic
27782793
return false
27792794
}
27802795

2781-
return p.ClusterAttribute.Equals(other.ClusterAttribute)
2796+
return p.GetStrategy() == other.GetStrategy() &&
2797+
p.StickyRegion == other.StickyRegion &&
2798+
p.ExternalEntityType == other.ExternalEntityType &&
2799+
p.ExternalEntityKey == other.ExternalEntityKey && p.ClusterAttribute.Equals(other.ClusterAttribute)
2800+
}
2801+
2802+
func (p *ActiveClusterSelectionPolicy) GetStrategy() ActiveClusterSelectionStrategy {
2803+
if p == nil || p.ActiveClusterSelectionStrategy == nil {
2804+
return ActiveClusterSelectionStrategyRegionSticky
2805+
}
2806+
return *p.ActiveClusterSelectionStrategy
2807+
}
2808+
2809+
func (e ActiveClusterSelectionStrategy) Ptr() *ActiveClusterSelectionStrategy {
2810+
return &e
2811+
}
2812+
2813+
func (e ActiveClusterSelectionStrategy) String() string {
2814+
switch e {
2815+
case ActiveClusterSelectionStrategyRegionSticky:
2816+
return "REGION_STICKY"
2817+
case ActiveClusterSelectionStrategyExternalEntity:
2818+
return "EXTERNAL_ENTITY"
2819+
}
2820+
2821+
return fmt.Sprintf("ActiveClusterSelectionStrategy(%d)", e)
2822+
}
2823+
2824+
func (e ActiveClusterSelectionStrategy) MarshalText() ([]byte, error) {
2825+
return []byte(e.String()), nil
2826+
}
2827+
2828+
func (e *ActiveClusterSelectionStrategy) UnmarshalText(value []byte) error {
2829+
switch s := strings.ToUpper(string(value)); s {
2830+
case "REGION_STICKY":
2831+
*e = ActiveClusterSelectionStrategyRegionSticky
2832+
return nil
2833+
case "EXTERNAL_ENTITY":
2834+
*e = ActiveClusterSelectionStrategyExternalEntity
2835+
return nil
2836+
default:
2837+
val, err := strconv.ParseInt(s, 10, 32)
2838+
if err != nil {
2839+
return fmt.Errorf("unknown enum value %q for %q: %v", s, "ActiveClusterSelectionStrategy", err)
2840+
}
2841+
*e = ActiveClusterSelectionStrategy(val)
2842+
return nil
2843+
}
27822844
}
27832845

27842846
// DomainStatus is an internal type (TBD...)

common/types/testdata/common.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,15 @@ var (
500500
},
501501
ExclusiveMaxReadLevel: &TaskKey,
502502
}
503+
ActiveClusterSelectionPolicyRegionSticky = types.ActiveClusterSelectionPolicy{
504+
ActiveClusterSelectionStrategy: types.ActiveClusterSelectionStrategyRegionSticky.Ptr(),
505+
StickyRegion: "region1",
506+
}
507+
ActiveClusterSelectionPolicyExternalEntity = types.ActiveClusterSelectionPolicy{
508+
ActiveClusterSelectionStrategy: types.ActiveClusterSelectionStrategyExternalEntity.Ptr(),
509+
ExternalEntityType: "externalEntityType1",
510+
ExternalEntityKey: "externalEntityKey1",
511+
}
503512
ClusterAttribute = types.ClusterAttribute{
504513
Scope: "region",
505514
Name: "us-west-1",

common/types/testdata/history.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ var (
276276
Header: &Header,
277277
PartitionConfig: PartitionConfig,
278278
RequestID: RequestID,
279-
ActiveClusterSelectionPolicy: &ActiveClusterSelectionPolicyWithClusterAttribute,
279+
ActiveClusterSelectionPolicy: &ActiveClusterSelectionPolicyExternalEntity,
280280
CronOverlapPolicy: &CronOverlapPolicy,
281281
}
282282
WorkflowExecutionCompletedEventAttributes = types.WorkflowExecutionCompletedEventAttributes{
@@ -476,7 +476,7 @@ var (
476476
Header: &Header,
477477
Memo: &Memo,
478478
SearchAttributes: &SearchAttributes,
479-
ActiveClusterSelectionPolicy: &ActiveClusterSelectionPolicyWithClusterAttribute,
479+
ActiveClusterSelectionPolicy: &ActiveClusterSelectionPolicyExternalEntity,
480480
CronOverlapPolicy: &CronOverlapPolicy,
481481
}
482482
StartChildWorkflowExecutionInitiatedEventAttributes = types.StartChildWorkflowExecutionInitiatedEventAttributes{

common/types/testdata/service_frontend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ var (
346346
SearchAttributes: &SearchAttributes,
347347
Header: &Header,
348348
FirstRunAtTimeStamp: &Timestamp1,
349-
ActiveClusterSelectionPolicy: &ActiveClusterSelectionPolicyWithClusterAttribute,
349+
ActiveClusterSelectionPolicy: &ActiveClusterSelectionPolicyExternalEntity,
350350
}
351351
StartWorkflowExecutionResponse = types.StartWorkflowExecutionResponse{
352352
RunID: RunID,
@@ -385,7 +385,7 @@ var (
385385
SearchAttributes: &SearchAttributes,
386386
Header: &Header,
387387
FirstRunAtTimestamp: &Timestamp1,
388-
ActiveClusterSelectionPolicy: &ActiveClusterSelectionPolicyWithClusterAttribute,
388+
ActiveClusterSelectionPolicy: &ActiveClusterSelectionPolicyRegionSticky,
389389
}
390390
SignalWithStartWorkflowExecutionAsyncRequest = types.SignalWithStartWorkflowExecutionAsyncRequest{
391391
SignalWithStartWorkflowExecutionRequest: &SignalWithStartWorkflowExecutionRequest,

0 commit comments

Comments
 (0)