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

Add signal external workflow decision #485

Merged
merged 13 commits into from
Jan 22, 2018
Merged

Add signal external workflow decision #485

merged 13 commits into from
Jan 22, 2018

Conversation

vancexu
Copy link
Contributor

@vancexu vancexu commented Dec 29, 2017

related #429
client side change: cadence-workflow/cadence-go-client#329

Copy link
Contributor

@samarabbas samarabbas left a comment

Choose a reason for hiding this comment

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

Reviewed IDL and schema changes. Will do the engine changes tomorrow.

@@ -109,6 +110,9 @@ enum EventType {
RequestCancelExternalWorkflowExecutionFailed,
ExternalWorkflowExecutionCancelRequested,
MarkerRecorded,
SignalExternalWorkflowExecutionInitiated,
Copy link
Contributor

Choose a reason for hiding this comment

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

This will break existing clients. Please add new values at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know. Thanks.

@@ -132,6 +136,7 @@ enum DecisionTaskFailedCause {
BAD_COMPLETE_WORKFLOW_EXECUTION_ATTRIBUTES,
BAD_FAIL_WORKFLOW_EXECUTION_ATTRIBUTES,
BAD_CANCEL_WORKFLOW_EXECUTION_ATTRIBUTES,
BAD_SIGNAL_WORKFLOW_EXECUTION_ATTRIBUTES,
Copy link
Contributor

Choose a reason for hiding this comment

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

Add new enums towards the very end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

60: optional binary control
}

struct ExternalWorkflowExecutionSignalRequestedEventAttributes {
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably rename it to ExternalWorkflowExecutionSignaledEventAttributes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will probably not change this, because the event type is EventTypeExternalWorkflowExecutionSignalRequested. If I rename this to ExternalWorkflowExecutionSignaledEventAttributes, then I probably need to change the event name to EventTypeExternalWorkflowExecutionSignaled, but we try to be consistent with SWF so wouldn't change event name.

I'm still open minded, let me know if you still prefer new name

Choose a reason for hiding this comment

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

SWF is using ExternalWorkflowExecutionSignaled.

struct DeleteWorkflowExecutionSignalRequest {
10: optional string domain
20: optional WorkflowExecution workflowExecution
30: optional string identity
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably identity does not make sense here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, removed.

* DeleteWorkflowExecutionSignal is used to delete a signal request ID that was previously recorded. This is currently
* used to clean execution info when signal decision finished.
**/
void DeleteWorkflowExecutionSignal(1: DeleteWorkflowExecutionSignalRequest deleteRequest)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's rename this to RemoveSignalMutableState

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,9 @@
CREATE TYPE signal_info (
Copy link
Contributor

Choose a reason for hiding this comment

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

This should go into v0.3. We have already released v0.2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will move when rebase

TargetDomainID string
TargetWorkflowID string
TargetRunID string
ScheduleID int64
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe rename to InitiatedID

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

InitiatedID int64
SignalRequestID string
SignalName string
Input []byte
Copy link
Contributor

Choose a reason for hiding this comment

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

You probably need to store the entire SignalInitiatedEvent here.

@@ -655,6 +686,7 @@ type (
GetWorkflowExecution(request *GetWorkflowExecutionRequest) (*GetWorkflowExecutionResponse, error)
UpdateWorkflowExecution(request *UpdateWorkflowExecutionRequest) error
DeleteWorkflowExecution(request *DeleteWorkflowExecutionRequest) error
DeleteSignalRequestedID(request *DeleteWorkflowExecutionSignalRequestedRequest) error
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this is a new API but DeleteSignalInfo is part of update?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
Copy link
Contributor

Choose a reason for hiding this comment

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

This is also updating the mutable state. Make sure it is protected by conditional check on range_id and next_event_id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed, protected by using updateWorkflowExecution.

return event
}

func (b *historyBuilder) newSignalExternalWorkflowExecutionFailedEvent(decisionTaskCompletedEventID, initiatedEventID int64,
Copy link
Contributor

Choose a reason for hiding this comment

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

You never set control on this event.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

return event
}

func (b *historyBuilder) newExternalWorkflowExecutionSignalRequestedEvent(initiatedEventID int64,
Copy link
Contributor

Choose a reason for hiding this comment

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

You never set control on this event.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

transferTasks = append(transferTasks, &persistence.SignalExecutionTask{
TargetDomainID: foreignInfo.ID,
TargetWorkflowID: attributes.GetWorkflowId(),
TargetRunID: common.StringDefault(attributes.RunId),
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the generated getter: attributes.GetRunId()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -1528,6 +1560,17 @@ func (e *historyEngineImpl) SignalWorkflowExecution(signalRequest *h.SignalWorkf
return &workflow.EntityNotExistsError{Message: "Workflow execution already completed."}
}

// deduplicate by request id for signal decision
if request.RequestId != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be simplified if you use the generated getter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed, good to know

@@ -1536,6 +1579,42 @@ func (e *historyEngineImpl) SignalWorkflowExecution(signalRequest *h.SignalWorkf
})
}

func (e *historyEngineImpl) DeleteWorkflowExecutionSignal(deleteRequest *h.DeleteWorkflowExecutionSignalRequest) error {
domainID, err := getDomainUUID(deleteRequest.DomainUUID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets use the updateWorkflowExecution helper defined in historyEngineImpl for making this update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

return nil
}

if e.DeletePendingSignal(initiatedID) == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

What if this is not nil?

Copy link
Contributor Author

@vancexu vancexu Jan 9, 2018

Choose a reason for hiding this comment

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

Good question. We have some options:

  1. add new PendingSignalNotExistEvent event when err happens
  2. add success (or failed) event no matter err happens or not
  3. add nothing when err happens (current implementation) .

Which one do you like best?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added log if err happens.

return nil
}

if e.DeletePendingSignal(initiatedID) == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this is not nil?

},
}

op := func() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you just create a helper for SignalExecutionWithRetry.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

initiatedEventID := task.ScheduleID
ri, isRunning := msBuilder.GetSignalInfo(initiatedEventID)
if !isRunning {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

You still want to call delete on the target to make sure we don't leak requestIDs in mutable state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In which case leak can happens?
I found it hard to delete target here because no ri.SignalRequestId can be obtained here.


// Check to see if the error is non-transient, in which case add SignalFailed
// event and complete transfer task by setting the err = nil
if common.IsServiceNonRetryableError(err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Make sure to add a test for expected error types here. Otherwise this transfer task can go into infinite loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added tests for transferQueueProcessor

@coveralls
Copy link

Coverage Status

Coverage increased (+0.7%) to 67.261% when pulling 09c0a09 on signaldi into 7a51af2 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.8%) to 67.381% when pulling 21e5cac on signaldi into 7a51af2 on master.

@coveralls
Copy link

coveralls commented Jan 20, 2018

Coverage Status

Coverage increased (+0.6%) to 67.283% when pulling 3a996e2 on signaldi into 7c79aaf on master.

@vancexu vancexu merged commit bd9eb9f into master Jan 22, 2018
@vancexu vancexu deleted the signaldi branch January 22, 2018 21:11
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.

4 participants