916
stage *tasks.DeleteWorkflowExecutionStage,
917
retentionDelete bool,
919
>
// DeleteWorkflowExecution is a 4 stages process (order is very important and should not be changed):
920
>
// 1. Add visibility delete task, i.e. schedule visibility record delete, and execution replication delete task,
921
>
// 2. Delete current workflow execution pointer,
922
>
// 3. Delete workflow mutable state,
923
>
// 4. Delete history branch.
924
>
925
>
// This function is called from task processor and should not be called directly.
926
>
// It may fail at any stage and task processor will retry. All stages are idempotent.
927
>
928
>
// If process fails after stage 1 then workflow execution becomes invisible but mutable state is still there and task can be safely retried.
929
>
// Stage 2 doesn't affect mutable state neither and doesn't block retry.
930
>
// After stage 3 task can't be retried because mutable state is gone and this might leave history branch in DB.
931
>
// The history branch won't be accessible (because mutable state is deleted) and special garbage collection workflow will delete it eventually.
932
>
// Stage 4 shouldn't be done earlier because if this func fails after it, workflow execution will be accessible but won't have history (inconsistent state).
933
>
934
>
engine, err := s.GetEngine(ctx)
935
>
if err != nil {
936
return err
937
}
938
939
// Do not get namespace cache within shard lock.
940
>
_, err = s.GetNamespaceRegistry().GetNamespaceByID(namespace.ID(key.NamespaceID))
context_impl.go
941
>
deleteVisibilityRecord := true
942
>
if err != nil {
943
if _, isNotFound := err.(*serviceerror.NamespaceNotFound); isNotFound {
944
// If namespace is not found, skip visibility record delete but proceed with other deletions.