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

Update workflow execution with version histories check #3679

Merged
merged 1 commit into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions common/persistence/cassandra/cassandraPersistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,25 +395,14 @@ workflow_state = ? ` +
`and task_id = ? ` +
`IF next_event_id = ?`

templateUpdateWorkflowExecutionQuery = `UPDATE executions ` +
`SET execution = ` + templateWorkflowExecutionType +
`, next_event_id = ? ` +
`, checksum = ` + templateChecksumType +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? ` +
`IF next_event_id = ? `

templateUpdateWorkflowExecutionWithVersionHistoriesQuery = `UPDATE executions ` +
`SET execution = ` + templateWorkflowExecutionType +
`, next_event_id = ? ` +
`, version_histories = ? ` +
`, version_histories_encoding = ? ` +
`, checksum = ` + templateChecksumType +
`, workflow_last_write_version = ? ` +
`, workflow_state = ? ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
Expand Down
231 changes: 82 additions & 149 deletions common/persistence/cassandra/cassandraPersistenceUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func applyWorkflowMutationBatch(
cqlNowTimestampMillis,
condition,
workflowMutation.Checksum,
workflowMutation.LastWriteVersion,
); err != nil {
return err
}
Expand Down Expand Up @@ -169,6 +170,7 @@ func applyWorkflowSnapshotBatchAsReset(
cqlNowTimestampMillis,
condition,
workflowSnapshot.Checksum,
workflowSnapshot.LastWriteVersion,
); err != nil {
return err
}
Expand Down Expand Up @@ -393,7 +395,7 @@ func createExecution(
completionData, completionEncoding := p.FromDataBlob(executionInfo.CompletionEvent)

if versionHistories == nil {
return &workflow.InternalDataInconsistencyError{Message: "encounter empty version histories in createExecution"}
return &workflow.InternalServiceError{Message: "encounter empty version histories in createExecution"}
}
versionHistoriesData, versionHistoriesEncoding := p.FromDataBlob(versionHistories)
batch.Query(templateCreateWorkflowExecutionWithVersionHistoriesQuery,
Expand Down Expand Up @@ -482,6 +484,7 @@ func updateExecution(
cqlNowTimestampMillis int64,
condition int64,
checksum checksum.Checksum,
lastWriteVersion int64,
) error {

// validate workflow state & close status
Expand Down Expand Up @@ -511,155 +514,85 @@ func updateExecution(

completionData, completionEncoding := p.FromDataBlob(executionInfo.CompletionEvent)
if versionHistories == nil {
// Updates will be called with null version histories while the feature is disabled
batch.Query(templateUpdateWorkflowExecutionQuery,
domainID,
workflowID,
runID,
parentDomainID,
parentWorkflowID,
parentRunID,
initiatedID,
executionInfo.CompletionEventBatchID,
completionData,
completionEncoding,
executionInfo.TaskList,
executionInfo.WorkflowTypeName,
executionInfo.WorkflowTimeout,
executionInfo.DecisionStartToCloseTimeout,
executionInfo.ExecutionContext,
executionInfo.State,
executionInfo.CloseStatus,
executionInfo.LastFirstEventID,
executionInfo.LastEventTaskID,
executionInfo.NextEventID,
executionInfo.LastProcessedEvent,
executionInfo.StartTimestamp,
executionInfo.LastUpdatedTimestamp,
executionInfo.CreateRequestID,
executionInfo.SignalCount,
executionInfo.HistorySize,
executionInfo.DecisionVersion,
executionInfo.DecisionScheduleID,
executionInfo.DecisionStartedID,
executionInfo.DecisionRequestID,
executionInfo.DecisionTimeout,
executionInfo.DecisionAttempt,
executionInfo.DecisionStartedTimestamp,
executionInfo.DecisionScheduledTimestamp,
executionInfo.DecisionOriginalScheduledTimestamp,
executionInfo.CancelRequested,
executionInfo.CancelRequestID,
executionInfo.StickyTaskList,
executionInfo.StickyScheduleToStartTimeout,
executionInfo.ClientLibraryVersion,
executionInfo.ClientFeatureVersion,
executionInfo.ClientImpl,
executionInfo.AutoResetPoints.Data,
executionInfo.AutoResetPoints.GetEncoding(),
executionInfo.Attempt,
executionInfo.HasRetryPolicy,
executionInfo.InitialInterval,
executionInfo.BackoffCoefficient,
executionInfo.MaximumInterval,
executionInfo.ExpirationTime,
executionInfo.MaximumAttempts,
executionInfo.NonRetriableErrors,
p.EventStoreVersion,
executionInfo.BranchToken,
executionInfo.CronSchedule,
executionInfo.ExpirationSeconds,
executionInfo.SearchAttributes,
executionInfo.Memo,
executionInfo.NextEventID,
checksum.Version,
checksum.Flavor,
checksum.Value,
shardID,
rowTypeExecution,
domainID,
workflowID,
runID,
defaultVisibilityTimestamp,
rowTypeExecutionTaskID,
condition)
} else {
// TODO also need to set the start / current / last write version
versionHistoriesData, versionHistoriesEncoding := p.FromDataBlob(versionHistories)
batch.Query(templateUpdateWorkflowExecutionWithVersionHistoriesQuery,
domainID,
workflowID,
runID,
parentDomainID,
parentWorkflowID,
parentRunID,
initiatedID,
executionInfo.CompletionEventBatchID,
completionData,
completionEncoding,
executionInfo.TaskList,
executionInfo.WorkflowTypeName,
executionInfo.WorkflowTimeout,
executionInfo.DecisionStartToCloseTimeout,
executionInfo.ExecutionContext,
executionInfo.State,
executionInfo.CloseStatus,
executionInfo.LastFirstEventID,
executionInfo.LastEventTaskID,
executionInfo.NextEventID,
executionInfo.LastProcessedEvent,
executionInfo.StartTimestamp,
executionInfo.LastUpdatedTimestamp,
executionInfo.CreateRequestID,
executionInfo.SignalCount,
executionInfo.HistorySize,
executionInfo.DecisionVersion,
executionInfo.DecisionScheduleID,
executionInfo.DecisionStartedID,
executionInfo.DecisionRequestID,
executionInfo.DecisionTimeout,
executionInfo.DecisionAttempt,
executionInfo.DecisionStartedTimestamp,
executionInfo.DecisionScheduledTimestamp,
executionInfo.DecisionOriginalScheduledTimestamp,
executionInfo.CancelRequested,
executionInfo.CancelRequestID,
executionInfo.StickyTaskList,
executionInfo.StickyScheduleToStartTimeout,
executionInfo.ClientLibraryVersion,
executionInfo.ClientFeatureVersion,
executionInfo.ClientImpl,
executionInfo.AutoResetPoints.Data,
executionInfo.AutoResetPoints.GetEncoding(),
executionInfo.Attempt,
executionInfo.HasRetryPolicy,
executionInfo.InitialInterval,
executionInfo.BackoffCoefficient,
executionInfo.MaximumInterval,
executionInfo.ExpirationTime,
executionInfo.MaximumAttempts,
executionInfo.NonRetriableErrors,
p.EventStoreVersion,
executionInfo.BranchToken,
executionInfo.CronSchedule,
executionInfo.ExpirationSeconds,
executionInfo.SearchAttributes,
executionInfo.Memo,
executionInfo.NextEventID,
versionHistoriesData,
versionHistoriesEncoding,
checksum.Version,
checksum.Flavor,
checksum.Value,
shardID,
rowTypeExecution,
domainID,
workflowID,
runID,
defaultVisibilityTimestamp,
rowTypeExecutionTaskID,
condition)
return &workflow.InternalServiceError{Message: "encounter empty version histories in updateExecution"}
}
// TODO also need to set the start / current / last write version
versionHistoriesData, versionHistoriesEncoding := p.FromDataBlob(versionHistories)
batch.Query(templateUpdateWorkflowExecutionWithVersionHistoriesQuery,
domainID,
workflowID,
runID,
parentDomainID,
parentWorkflowID,
parentRunID,
initiatedID,
executionInfo.CompletionEventBatchID,
completionData,
completionEncoding,
executionInfo.TaskList,
executionInfo.WorkflowTypeName,
executionInfo.WorkflowTimeout,
executionInfo.DecisionStartToCloseTimeout,
executionInfo.ExecutionContext,
executionInfo.State,
executionInfo.CloseStatus,
executionInfo.LastFirstEventID,
executionInfo.LastEventTaskID,
executionInfo.NextEventID,
executionInfo.LastProcessedEvent,
executionInfo.StartTimestamp,
executionInfo.LastUpdatedTimestamp,
executionInfo.CreateRequestID,
executionInfo.SignalCount,
executionInfo.HistorySize,
executionInfo.DecisionVersion,
executionInfo.DecisionScheduleID,
executionInfo.DecisionStartedID,
executionInfo.DecisionRequestID,
executionInfo.DecisionTimeout,
executionInfo.DecisionAttempt,
executionInfo.DecisionStartedTimestamp,
executionInfo.DecisionScheduledTimestamp,
executionInfo.DecisionOriginalScheduledTimestamp,
executionInfo.CancelRequested,
executionInfo.CancelRequestID,
executionInfo.StickyTaskList,
executionInfo.StickyScheduleToStartTimeout,
executionInfo.ClientLibraryVersion,
executionInfo.ClientFeatureVersion,
executionInfo.ClientImpl,
executionInfo.AutoResetPoints.Data,
executionInfo.AutoResetPoints.GetEncoding(),
executionInfo.Attempt,
executionInfo.HasRetryPolicy,
executionInfo.InitialInterval,
executionInfo.BackoffCoefficient,
executionInfo.MaximumInterval,
executionInfo.ExpirationTime,
executionInfo.MaximumAttempts,
executionInfo.NonRetriableErrors,
p.EventStoreVersion,
executionInfo.BranchToken,
executionInfo.CronSchedule,
executionInfo.ExpirationSeconds,
executionInfo.SearchAttributes,
executionInfo.Memo,
executionInfo.NextEventID,
versionHistoriesData,
versionHistoriesEncoding,
checksum.Version,
checksum.Flavor,
checksum.Value,
lastWriteVersion,
executionInfo.State,
shardID,
rowTypeExecution,
domainID,
workflowID,
runID,
defaultVisibilityTimestamp,
rowTypeExecutionTaskID,
condition)

return nil
}
Expand Down
Loading