-
Notifications
You must be signed in to change notification settings - Fork 859
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
Nexus: Delete state machine on terminal state -- Part 3 #6984
base: main
Are you sure you want to change the base?
Changes from all commits
a302db5
1f58b61
d337f7d
e8727a1
5829c64
08ef2a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -209,34 +209,33 @@ func (ch *commandHandler) HandleCancelCommand( | |
Message: "empty CancelNexusOperationCommandAttributes", | ||
} | ||
} | ||
|
||
coll := nexusoperations.MachineCollection(ms.HSM()) | ||
nodeID := strconv.FormatInt(attrs.ScheduledEventId, 10) | ||
node, err := coll.Node(nodeID) | ||
_, err := coll.Node(nodeID) | ||
if err != nil { | ||
if errors.Is(err, hsm.ErrStateMachineNotFound) { | ||
if ms.HasAnyBufferedEvent(makeNexusOperationTerminalEventFilter(attrs.ScheduledEventId)) { | ||
// Allow cancelation if there are buffered terminal events | ||
event := ms.AddHistoryEvent(enumspb.EVENT_TYPE_NEXUS_OPERATION_CANCEL_REQUESTED, func(he *historypb.HistoryEvent) { | ||
he.Attributes = &historypb.HistoryEvent_NexusOperationCancelRequestedEventAttributes{ | ||
NexusOperationCancelRequestedEventAttributes: &historypb.NexusOperationCancelRequestedEventAttributes{ | ||
ScheduledEventId: attrs.ScheduledEventId, | ||
WorkflowTaskCompletedEventId: workflowTaskCompletedEventID, | ||
}, | ||
} | ||
he.UserMetadata = command.UserMetadata | ||
}) | ||
return nexusoperations.CancelRequestedEventDefinition{}.Apply(ms.HSM(), event) | ||
} | ||
return workflow.FailWorkflowTaskError{ | ||
Cause: enumspb.WORKFLOW_TASK_FAILED_CAUSE_BAD_REQUEST_CANCEL_NEXUS_OPERATION_ATTRIBUTES, | ||
Message: fmt.Sprintf("requested cancelation for a non-existing operation with scheduled event ID of %d", attrs.ScheduledEventId), | ||
// TODO(bergundy): Message: fmt.Sprintf("requested cancelation for a non-existing or already completed operation with scheduled event ID of %d", attrs.ScheduledEventId), | ||
Message: fmt.Sprintf("requested cancelation for a non-existing or already completed operation with scheduled event ID %d", attrs.ScheduledEventId), | ||
} | ||
} | ||
return err | ||
} | ||
// TODO(bergundy): Remove this when operation auto-deletes itself on terminal state. | ||
// Operation may already be in a terminal state because it doesn't yet delete itself. We don't want to accept | ||
// cancelation in this case. | ||
op, err := hsm.MachineData[nexusoperations.Operation](node) | ||
if err != nil { | ||
return err | ||
} | ||
// The operation is already in a terminal state and the terminal NexusOperation event has not just been buffered. | ||
// We allow the workflow to request canceling an operation that has just completed while a workflow task is in | ||
// flight since it cannot know about the state of the operation. | ||
// TODO(bergundy): When we support state machine deletion, this condition will have to change. | ||
if !nexusoperations.TransitionCanceled.Possible(op) && !ms.HasAnyBufferedEvent(makeNexusOperationTerminalEventFilter(attrs.ScheduledEventId)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You will need allow cancel while a terminal event is buffered (e.g. the SDK isn't aware yet that the operation has completed). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The check for buffered terminal event should be moved to where we error out when the node is not found. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is what you have in mind. Please take a look |
||
return workflow.FailWorkflowTaskError{ | ||
Cause: enumspb.WORKFLOW_TASK_FAILED_CAUSE_BAD_REQUEST_CANCEL_NEXUS_OPERATION_ATTRIBUTES, | ||
Message: fmt.Sprintf("requested cancelation for an already complete operation with scheduled event ID of %d", attrs.ScheduledEventId), | ||
Message: fmt.Sprintf("error looking up operation with scheduled event ID %d: %v", attrs.ScheduledEventId, err), | ||
} | ||
} | ||
|
||
|
@@ -256,7 +255,7 @@ func (ch *commandHandler) HandleCancelCommand( | |
if errors.Is(err, hsm.ErrStateMachineAlreadyExists) { | ||
return workflow.FailWorkflowTaskError{ | ||
Cause: enumspb.WORKFLOW_TASK_FAILED_CAUSE_BAD_REQUEST_CANCEL_NEXUS_OPERATION_ATTRIBUTES, | ||
Message: fmt.Sprintf("cancelation was already requested for an operation with scheduled event ID of %d", attrs.ScheduledEventId), | ||
Message: fmt.Sprintf("requested cancelation for operation with scheduled event ID %d that is already being canceled", attrs.ScheduledEventId), | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just inline this in the loop body, there's no value in extracting to a function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!