Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IWF-129: Enable executingStateIds SAs for states with waitUntil #453

Merged
merged 18 commits into from
Oct 24, 2024

Conversation

lwolczynski
Copy link
Contributor

Description

Checklist

  • Code compiles correctly
  • Tests for the changes have been added
  • All tests passing
  • This PR change is backwards-compatible
  • This PR CONTAINS a (planned) breaking change (it is not backwards compatible)

Related Issue

Closes #411

@lwolczynski lwolczynski force-pushed the jira/lwolczynski/IWF-129 branch from 5a6ad52 to 7e56552 Compare October 16, 2024 19:50
config/config.go Outdated Show resolved Hide resolved
service/interpreter/stateExecutionCounter.go Outdated Show resolved Hide resolved
service/interpreter/stateExecutionCounter.go Outdated Show resolved Hide resolved
service/interpreter/stateExecutionCounter.go Show resolved Hide resolved
if config.GetDisableSystemSearchAttribute() {
return nil
}

if e.globalVersioner.IsAfterVersionOfOptimizedUpsertSearchAttribute() && len(executingStateIds) == 0 {
Copy link
Contributor

@longquanzheng longquanzheng Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This optimization is broken already for current default/ENABLED_FOR_ALL, and it won't work for ENABLED_FOR_STATES_WITH_WAIT_UNTIL. We need to fix it, and have to update ClearExecutingStateIdsSearchAttributeFinally as well.

To keep determinsm, we have to add a IsBeforeVersionOfExecutingStateIdMode in globalVersioner.
Then here:

if e.globalVersioner.IsAfterVersionOfOptimizedUpsertSearchAttribute() && 
e.globalVersioner.IsBeforeVersionOfExecutingStateIdMode() &&
len(executingStateIds) == 0 {
    // explain why we stopped using this optimization
    return nil
}

Similarly in ClearExecutingStateIdsSearchAttributeFinally:

if e.globalVersioner.IsAfterVersionOfOptimizedUpsertSearchAttribute() && 
e.globalVersioner.IsBeforeVersionOfExecutingStateIdMode() {
   if if config.GetDisableSystemSearchAttribute() {	
		return
   }
  if e.totalCurrentlyExecutingCount == 0{
      upsertSearchAttribute( []string{}) // clear the value.
   }
}

Btw, you can also create a method in globalVersioner IsAfterVersionOfOptimizedUpsertSearchAttributeAndBeforeVersionOfExecutingStateIdMode() to combinet this check. Maybe that will look better (maybe not, it looks hard to read actually)

Copy link
Contributor

@longquanzheng longquanzheng Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, I realized that the correct way to optimize this UpsertSearchAttribute(which is a temporal action) is to check the next state like this: #454

We can also do it in next PR -- as long as we don't release the this PR to production, we don't have to create a new version (so that we don't keep too many versions)

Copy link
Contributor Author

@lwolczynski lwolczynski Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsBeforeVersionOfExecutingStateIdMode is equal to !IsAfterVersionOfExecutingStateIdMode. Do we need an extra method for this check?

The latter method is somehow malformed in your snippet. I changed it to:

func (e *StateExecutionCounter) ClearExecutingStateIdsSearchAttributeFinally() {
	config := e.configer.Get()

	if e.globalVersioner.IsAfterVersionOfExecutingStateIdMode() {
		if config.GetExecutingStateIdMode() == "DISABLED" {
			return
		}
	} else {
		if config.GetDisableSystemSearchAttribute() {
			return
		}
	}

	if e.globalVersioner.IsAfterVersionOfOptimizedUpsertSearchAttribute() && !e.globalVersioner.IsAfterVersionOfExecutingStateIdMode() && e.totalCurrentlyExecutingCount == 0 {
		err := e.provider.UpsertSearchAttributes(e.ctx, map[string]interface{}{
			service.SearchAttributeExecutingStateIds: []string{},
		})
		if err != nil {
			e.provider.GetLogger(e.ctx).Error("error for upsert SearchAttributeExecutingStateIds", err)
		}
	}
}

We will need to refactor it further, since with how it is right now, SearchAttributeExecutingStateIds won't be cleared when e.globalVersioner.IsAfterVersionOfExecutingStateIdMode() == true.

And I'd rather work on #454 in a separate branch. I can rebase off of this one and merge #454 into here before merging to main if we want to release other changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsBeforeVersionOfExecutingStateIdMode is equal to !IsAfterVersionOfExecutingStateIdMode. Do we need an extra method for this check?

You are right, we don't have to. Sometimes I just prefer to not use negative statement/expression (reasons are like https://www.obsidiansecurity.com/blog/why-to-stop-writing-negative-code/ )

But no much difference and it's not always the case.

Copy link
Contributor

@longquanzheng longquanzheng Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I'd rather work on #454 in a separate branch. I can rebase off of this one and merge #454 into here before merging to main if we want to release other changes.

+1
Sounds good. btw maybe not add replay tests for this PR . Otherwise you will have to do it again (maybe it's fine) if we want to reuse the same version (because that optimization is a non-determinstic change)

@lwolczynski lwolczynski force-pushed the jira/lwolczynski/IWF-129 branch from 9dcc5f1 to fcaf759 Compare October 17, 2024 18:27
@lwolczynski lwolczynski marked this pull request as ready for review October 17, 2024 22:37
Comment on lines 95 to 96
time.Sleep(time.Second * 5) // wait for a few seconds so that timer is ready to be skipped
req3 := apiClient.DefaultApi.ApiV1WorkflowTimerSkipPost(context.Background())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would work, but I usually prefer signal which is more controllable than time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified this test and removed the command entirely

@lwolczynski lwolczynski force-pushed the jira/lwolczynski/IWF-129 branch from 32f62c9 to d504521 Compare October 18, 2024 16:08
@lwolczynski
Copy link
Contributor Author

Add comments addressed. Moving on to #454

@lwolczynski lwolczynski merged commit 297d8e0 into main Oct 24, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable executingStateIds system search attributes for only states that have waitUntil
2 participants