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

Refactor workflow execution context & mutable state #2200

Merged
merged 10 commits into from
Jul 12, 2019

Conversation

wxing1292
Copy link
Contributor

@wxing1292 wxing1292 commented Jul 11, 2019

  • Introduce WorkflowEvents, which contains events to be persisted
  • Cleanup workflow execution continue as new path, now all create workflow persistence request is generated using mutable state
  • Remove appendFirstBatchHistoryForContinueAsNew, handle the persistence of continue as new history events in update method
  • Move mutable state helper functions to dedicated file
  • Introduce CloseTransactionAsSnapshot as close function for workflow creation
  • Introduce CloseTransactionAsMutation as close function for workflow update

* Introduce WorkflowEvents, which contains events to be persisted
* Cleanup workflow execution continue as new path, now all create workflow persistence request is generated using mutable state
* Remove appendFirstBatchHistoryForContinueAsNew, handle the persistence of continue as new history events in update method
* Move mutable state helper functions to dedicated file
* Introduce ToWorkflowSnapshot as close functino for workflow creation
* Introduce ToWorkflowMutation as close function for workflow update
@wxing1292
Copy link
Contributor Author

Note: the mutable state / workflow execution context re-write is still ongoing, meaning that there are things half done

@wxing1292
Copy link
Contributor Author

@yycptt plz verify the continue as new path (especially the cron related logic)

Copy link
Contributor

@venkat1109 venkat1109 left a comment

Choose a reason for hiding this comment

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

Left some comments mostly related to style.

e.pendingTimerTasks = append(e.pendingTimerTasks, timerTasks...)
}

func (e *mutableStateBuilder) ToWorkflowMutation(now time.Time) (*persistence.WorkflowMutation, []*persistence.WorkflowEvents, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we name this method CommitChanges() ? To me, that conveys the intention in a straightforward manner. ToXXX methods are usually used for format or type conversion of value types

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for this

Copy link
Contributor Author

@wxing1292 wxing1292 Jul 12, 2019

Choose a reason for hiding this comment

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

sure, but this function does not commit, not yet. this function aims to generate objects to be persisted.

one more thing, this function is generating a diff, there is another function which generates a snapshot.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe something like CreateWorkflowMutation, GenerateWorkflowMutation, CreateXXXDiff, etc.

Copy link
Contributor Author

@wxing1292 wxing1292 Jul 12, 2019

Choose a reason for hiding this comment

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

change to
CloseTransactionAsSnapshot
and
CloseTransactionAsMutation

return workflowMutation, workflowEventsSeq, nil
}

func (e *mutableStateBuilder) ToWorkflowSnapshot(now time.Time) (*persistence.WorkflowSnapshot, []*persistence.WorkflowEvents, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we name this method Commit() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if commit is the key word (meaning generating a snapshot or diff but does not persist it to DB), what about CommitMutation and CommitSnapshot?

e.updateBufferedEvents = nil
}
if len(e.bufferedEvents) > e.config.MaximumBufferedEventsBatch() {
return ErrBufferedEventsLimitExceeded
Copy link
Contributor

Choose a reason for hiding this comment

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

what does it mean when you return error at this stage ? What is the application supposed to do ? Can we return this error much earlier before we even flush events etc i.e. check if len(buffered) + len(updateBuffered) > limit ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right now this is handled by failing the decision

c.failInflightDecision()

ref: https://github.com/uber/cadence/blob/master/service/history/workflowExecutionContext.go#L750

The refactor need to incrementally change related logic

@@ -0,0 +1,185 @@
// Copyright (c) 2017 Uber Technologies, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/2017/2019

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

inputs map[int64]*persistence.ActivityInfo,
) []*persistence.ActivityInfo {

outputs := []*persistence.ActivityInfo{}
Copy link
Contributor

Choose a reason for hiding this comment

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

you know the size beforehand. Allocate exactly len(inputs) capacity slice. Same comment for rest of the methods

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

@@ -129,6 +129,10 @@ func (b *stateBuilderImpl) applyEvents(domainID, requestID string, execution sha
switch event.GetEventType() {
case shared.EventTypeWorkflowExecutionStarted:
attributes := event.WorkflowExecutionStartedEventAttributes
domainEntry, err := b.domainCache.GetDomainByID(domainID)
if err != nil {
return nil, nil, nil, err
Copy link
Contributor

Choose a reason for hiding this comment

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

this method signature definitely needs some revisiting. It takes about 6 params and returns 4 results

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed, let us do it one thing at a time :)

service/history/mutableStateBuilder.go Show resolved Hide resolved
e.pendingTimerTasks = append(e.pendingTimerTasks, timerTasks...)
}

func (e *mutableStateBuilder) ToWorkflowMutation(now time.Time) (*persistence.WorkflowMutation, []*persistence.WorkflowEvents, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for this

service/history/mutableStateBuilder.go Show resolved Hide resolved
service/history/mutableStateBuilder.go Outdated Show resolved Hide resolved
Copy link
Contributor

@yycptt yycptt left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@wxing1292 wxing1292 merged commit fcf79fd into master Jul 12, 2019
@wxing1292 wxing1292 deleted the mutable-state-close-transaction branch July 12, 2019 23:54
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.

3 participants