Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/shahab/v3-internal-protos' into …
Browse files Browse the repository at this point in the history
…shahab/transfer-versioning-info

# Conflicts:
#	service/history/workflow/mutable_state_impl.go
  • Loading branch information
ShahabT committed Nov 22, 2024
2 parents f3f96bf + 5d7333e commit 7828cf6
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 18 deletions.
14 changes: 8 additions & 6 deletions service/history/workflow/mutable_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,14 @@ type (
// If state transition history is empty (e.g. when disabled or fresh mutable state), returns 0.
NextTransitionCount() int64
// GetEffectiveDeployment returns the effective deployment in the following order:
// 1. DeploymentTransition.Deployment: this is returned when the wf is transitioning to a new
// deployment
// 2. VersioningOverride.Deployment: this is returned when user has set a PINNED override at wf
// start time, or later via UpdateWorkflowExecutionOptions.
// 3. Deployment: this is returned when there is no transition and not override (most common case).
// Deployment is set based on the worker-sent deployment in the latest WFT completion.
// 1. DeploymentTransition.Deployment: this is returned when the wf is transitioning to a
// new deployment
// 2. VersioningOverride.Deployment: this is returned when user has set a PINNED override
// at wf start time, or later via UpdateWorkflowExecutionOptions.
// 3. Deployment: this is returned when there is no transition and no override (the most
// common case). Deployment is set based on the worker-sent deployment in the latest WFT
// completion. Exception: if Deployment is set but the workflow's effective behavior is
// UNSPECIFIED, it means the workflow is unversioned, so effective deployment will be nil.
GetEffectiveDeployment() *deploymentpb.Deployment
// GetEffectiveVersioningBehavior returns the effective versioning behavior in the following
// order:
Expand Down
95 changes: 83 additions & 12 deletions service/history/workflow/mutable_state_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,16 +511,42 @@ func (s *mutableStateSuite) TestEffectiveDeployment() {
ms.executionInfo.VersioningInfo = versioningInfo
s.verifyEffectiveDeployment(nil, enumspb.VERSIONING_BEHAVIOR_UNSPECIFIED)

// ------- Without override, without transition

// deployment is set but behavior is not -> unversioned
versioningInfo.Deployment = deployment1
versioningInfo.Behavior = enumspb.VERSIONING_BEHAVIOR_UNSPECIFIED
s.verifyEffectiveDeployment(nil, enumspb.VERSIONING_BEHAVIOR_UNSPECIFIED)

versioningInfo.Deployment = deployment1
versioningInfo.Behavior = enumspb.VERSIONING_BEHAVIOR_PINNED
s.verifyEffectiveDeployment(deployment1, enumspb.VERSIONING_BEHAVIOR_PINNED)

versioningInfo.Deployment = deployment1
versioningInfo.Behavior = enumspb.VERSIONING_BEHAVIOR_AUTO_UPGRADE
s.verifyEffectiveDeployment(deployment1, enumspb.VERSIONING_BEHAVIOR_AUTO_UPGRADE)

// ------- With override, without transition

// deployment and behavior are not set, but override behavior is AUTO_UPGRADE -> AUTO_UPGRADE
versioningInfo.Deployment = nil
versioningInfo.Behavior = enumspb.VERSIONING_BEHAVIOR_UNSPECIFIED
versioningInfo.VersioningOverride = &workflowpb.VersioningOverride{
Behavior: enumspb.VERSIONING_BEHAVIOR_PINNED,
Deployment: deployment2,
Behavior: enumspb.VERSIONING_BEHAVIOR_AUTO_UPGRADE,
}
s.verifyEffectiveDeployment(deployment2, enumspb.VERSIONING_BEHAVIOR_PINNED)
s.verifyEffectiveDeployment(nil, enumspb.VERSIONING_BEHAVIOR_AUTO_UPGRADE)

// deployment is set, behavior is not, but override behavior is AUTO_UPGRADE -> AUTO_UPGRADE
versioningInfo.Deployment = deployment1
versioningInfo.Behavior = enumspb.VERSIONING_BEHAVIOR_UNSPECIFIED
versioningInfo.VersioningOverride = &workflowpb.VersioningOverride{
Behavior: enumspb.VERSIONING_BEHAVIOR_AUTO_UPGRADE,
}
s.verifyEffectiveDeployment(deployment1, enumspb.VERSIONING_BEHAVIOR_AUTO_UPGRADE)

// worker says PINNED, but override behavior is AUTO_UPGRADE -> AUTO_UPGRADE
versioningInfo.Deployment = deployment1
versioningInfo.Behavior = enumspb.VERSIONING_BEHAVIOR_PINNED
versioningInfo.VersioningOverride = &workflowpb.VersioningOverride{
Behavior: enumspb.VERSIONING_BEHAVIOR_AUTO_UPGRADE,
// Technically, API should not allow deployment to be set for AUTO_UPGRADE override, but we
Expand All @@ -529,13 +555,56 @@ func (s *mutableStateSuite) TestEffectiveDeployment() {
}
s.verifyEffectiveDeployment(deployment1, enumspb.VERSIONING_BEHAVIOR_AUTO_UPGRADE)

// deployment and behavior are not set, but override behavior is PINNED -> PINNED
versioningInfo.Deployment = nil
versioningInfo.Behavior = enumspb.VERSIONING_BEHAVIOR_UNSPECIFIED
versioningInfo.VersioningOverride = &workflowpb.VersioningOverride{
Behavior: enumspb.VERSIONING_BEHAVIOR_PINNED,
Deployment: deployment2,
}
s.verifyEffectiveDeployment(deployment2, enumspb.VERSIONING_BEHAVIOR_PINNED)

// deployment is set, behavior is not, but override behavior is PINNED --> PINNED
versioningInfo.Deployment = deployment1
versioningInfo.Behavior = enumspb.VERSIONING_BEHAVIOR_UNSPECIFIED
versioningInfo.VersioningOverride = &workflowpb.VersioningOverride{
Behavior: enumspb.VERSIONING_BEHAVIOR_PINNED,
Deployment: deployment2,
}
s.verifyEffectiveDeployment(deployment2, enumspb.VERSIONING_BEHAVIOR_PINNED)

// worker says AUTO_UPGRADE, but override behavior is PINNED --> PINNED
versioningInfo.Deployment = deployment1
versioningInfo.Behavior = enumspb.VERSIONING_BEHAVIOR_AUTO_UPGRADE
versioningInfo.VersioningOverride = &workflowpb.VersioningOverride{
Behavior: enumspb.VERSIONING_BEHAVIOR_PINNED,
Deployment: deployment2,
}
s.verifyEffectiveDeployment(deployment2, enumspb.VERSIONING_BEHAVIOR_PINNED)

// ------- With transition

versioningInfo.Deployment = deployment1
versioningInfo.Behavior = enumspb.VERSIONING_BEHAVIOR_PINNED
versioningInfo.VersioningOverride = &workflowpb.VersioningOverride{
Behavior: enumspb.VERSIONING_BEHAVIOR_AUTO_UPGRADE,
Deployment: deployment2,
}
versioningInfo.DeploymentTransition = &workflowpb.DeploymentTransition{
Deployment: deployment3,
}
s.verifyEffectiveDeployment(deployment3, enumspb.VERSIONING_BEHAVIOR_AUTO_UPGRADE)

// Transitioning to unversioned
versioningInfo.DeploymentTransition.Deployment = nil
versioningInfo.Deployment = deployment1
versioningInfo.Behavior = enumspb.VERSIONING_BEHAVIOR_PINNED
versioningInfo.VersioningOverride = &workflowpb.VersioningOverride{
Behavior: enumspb.VERSIONING_BEHAVIOR_AUTO_UPGRADE,
Deployment: deployment2,
}
versioningInfo.DeploymentTransition = &workflowpb.DeploymentTransition{
Deployment: nil,
}
s.verifyEffectiveDeployment(nil, enumspb.VERSIONING_BEHAVIOR_AUTO_UPGRADE)
}

Expand Down Expand Up @@ -611,7 +680,7 @@ func (s *mutableStateSuite) TestUnpinnedFirstWorkflowTask() {
s.verifyEffectiveDeployment(deployment1, enumspb.VERSIONING_BEHAVIOR_AUTO_UPGRADE)
}

func (s *mutableStateSuite) TestUnpinnedRedirected() {
func (s *mutableStateSuite) TestUnpinnedTransition() {
tq := &taskqueuepb.TaskQueue{Name: "tq"}
behavior := enumspb.VERSIONING_BEHAVIOR_AUTO_UPGRADE
s.createMutableStateWithVersioningBehavior(behavior, deployment1, tq)
Expand Down Expand Up @@ -649,7 +718,7 @@ func (s *mutableStateSuite) TestUnpinnedRedirected() {
s.NoError(err)
}

func (s *mutableStateSuite) TestUnpinnedRedirectFailed() {
func (s *mutableStateSuite) TestUnpinnedTransitionFailed() {
tq := &taskqueuepb.TaskQueue{Name: "tq"}
behavior := enumspb.VERSIONING_BEHAVIOR_AUTO_UPGRADE
s.createMutableStateWithVersioningBehavior(behavior, deployment1, tq)
Expand All @@ -658,8 +727,8 @@ func (s *mutableStateSuite) TestUnpinnedRedirectFailed() {
s.NoError(err)
s.verifyEffectiveDeployment(deployment1, behavior)

redirectStarted := s.mutableState.StartDeploymentTransition(deployment2)
s.True(redirectStarted)
transitionStarted := s.mutableState.StartDeploymentTransition(deployment2)
s.True(transitionStarted)
s.verifyEffectiveDeployment(deployment2, behavior)

_, wft, err = s.mutableState.AddWorkflowTaskStartedEvent(
Expand All @@ -686,10 +755,11 @@ func (s *mutableStateSuite) TestUnpinnedRedirectFailed() {
0,
)
s.NoError(err)
s.verifyEffectiveDeployment(deployment1, behavior)
// WFT failure does not fail transition
s.verifyEffectiveDeployment(deployment2, behavior)
}

func (s *mutableStateSuite) TestUnpinnedRedirectTimeout() {
func (s *mutableStateSuite) TestUnpinnedTransitionTimeout() {
tq := &taskqueuepb.TaskQueue{Name: "tq"}
behavior := enumspb.VERSIONING_BEHAVIOR_AUTO_UPGRADE
s.createMutableStateWithVersioningBehavior(behavior, deployment1, tq)
Expand All @@ -698,8 +768,8 @@ func (s *mutableStateSuite) TestUnpinnedRedirectTimeout() {
s.NoError(err)
s.verifyEffectiveDeployment(deployment1, behavior)

redirectStarted := s.mutableState.StartDeploymentTransition(deployment2)
s.True(redirectStarted)
transitionStarted := s.mutableState.StartDeploymentTransition(deployment2)
s.True(transitionStarted)
s.verifyEffectiveDeployment(deployment2, behavior)

_, wft, err = s.mutableState.AddWorkflowTaskStartedEvent(
Expand All @@ -716,6 +786,7 @@ func (s *mutableStateSuite) TestUnpinnedRedirectTimeout() {

_, err = s.mutableState.AddWorkflowTaskTimedOutEvent(wft)
s.NoError(err)
// WFT timeout does not fail transition
s.verifyEffectiveDeployment(deployment1, behavior)
}

Expand Down

0 comments on commit 7828cf6

Please sign in to comment.