Cadence Internals(2):Cadence Workflow History Protocol #4544
longquanzheng
started this conversation in
Show and tell
Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
State machines
Decision
Activity
Timer
Child Workflow
Rules
At any point of time, there can only be one decision pending (scheduled or started)
DecisionTaskCompleted event drives the workflow to make progress. It tells Cadence server about the next things happening to the workflow
Schedule an activity → by ActivityScheduledEvent
Scheduled a timer → by TimerScheduledEvent
Scheduled a ChildWorkflow → by ChildWorklfowInitiatedEvent
…
Basically, decision [started event] task is the boundary for SDK to process a decision task.
The very first decision is scheduled by the server. Only certain events can trigger a next decision, include:
ActivityTaskCompleted/Failed/Timeout
WorkflowExecutionSignaled
TimerFired
ChildWorkflowStarted
ChildWorkflowCompleted/Failed/Timeout
...
A rule of thumb is that any event that can be useful to let a workflow to make progress.
For example, the ActivityTaskStarted event is not one of them because it’s not needed for workflow to make any progress/decision.
However, it should be clear that triggering decision task doesn't mean the workflow will always make some progress. It's possible/okay that a decision task will return empty results -- decision task completed with nothing scheduled. For example, a workflow receive a "trash signal" will trigger a decision task but it won't make any progress.
A DecisionCloseEvents( DecisionCompletedEvent, DecisionTimeoutEvent,DecisionFailedEvent) must be right after a DecisionStartedEvent. In other words, there cannot be other events between a DecisionStartedEvent and a DecisionCloseEvent. This rule is for making it easy to implement the replay mechanism in SDK (it makes the "boundary clear in history ).
Because of 4, when a workflow is executing a decision(last event is DecisionStartedEvent), all other incoming events, like WorkflowExecutionSignaled(receiving a signal), ActivityTaskStarted/ActivityTaskCompleted/etc, are stored into a “Buffer” of the workflow. The event will only be shown in the history when the pending decision is closed(completed/timeouted/failed).
For example, when a decision is started and in progress, if a workflow receives a signal, it will go to the buffer. Only when the decision is closed, the signal event can become visible in history.
A special case of 5: When the pending decision is completed by deciding to close the workflow(completing or failing), the server will reject the decision if there are any events in the buffer. This is to guarantee that workflow won’t lose any of those events like signals. Because after a workflow is closed, it won’t be able to process them anymore.
LocalActivity is executing within a decision. So there is no Scheduled/Started event.
History of Activity with retryOptions is special. The ActivityStartedEvent is being written when the activity is closed. (this is to keep history immutable as invariance). You can use WebUI to check if the activity has started by looking at the “Pending Activities” tab.
Beta Was this translation helpful? Give feedback.
All reactions