MCPcopy Create free account
hub / github.com/temporalio/temporal / ValidateSideEffectTask

Method ValidateSideEffectTask

chasm/tree.go:3332–3435  ·  view source on GitHub ↗

ValidateSideEffectTask checks whether a side effect task should still be executed. Intended for use by standby handlers. It returns two booleans: - isTaskInTree: true if the task's logical counterpart still exists in the replicated tree state (node found, InitialVersionedTransition matches, and log

(
	ctx context.Context,
	chasmTask *tasks.ChasmTask,
)

Source from the content-addressed store, hash-verified

3330//
3331// If an error is returned both booleans are false.
3332func (n *Node) ValidateSideEffectTask(
3333 ctx context.Context,
3334 chasmTask *tasks.ChasmTask,
3335) (isTaskInTree bool, isValidByComponent bool, retErr error) {
3336
3337 taskInfo := chasmTask.Info
3338 taskTypeID := taskInfo.TypeId
3339 registrableTask, ok := n.registry.TaskByID(taskTypeID)
3340 if !ok {
3341 return false, false, softassert.UnexpectedInternalErr(
3342 n.logger,
3343 "unknown task type id",
3344 fmt.Errorf("%d", taskTypeID))
3345 }
3346
3347 if registrableTask.isPureTask {
3348 return false, false, softassert.UnexpectedInternalErr(
3349 n.logger,
3350 "ValidateSideEffectTask called on a Pure task, task type: ",
3351 fmt.Errorf("%s", registrableTask.fqType()))
3352 }
3353
3354 node, ok := n.findNode(taskInfo.Path)
3355 if !ok {
3356 return false, false, nil
3357 }
3358
3359 // node.serializedNode should always be available when running a side effect task.
3360 if transitionhistory.Compare(
3361 taskInfo.ComponentInitialVersionedTransition,
3362 node.serializedNode.Metadata.InitialVersionedTransition,
3363 ) != 0 {
3364 return false, false, nil
3365 }
3366
3367 // Verify the logical task this physical task was generated from still exists,
3368 // and capture it so we can use its Data pointer for the deserialization cache.
3369 //
3370 // A logical task can be dropped mid-flight (e.g. component paused then unpaused)
3371 // without the physical task being cancelled. Checking existence here prevents
3372 // stale physical tasks from executing after their logical counterpart is gone.
3373 //
3374 // TaskVersionedTransition is unset on physical tasks created before this field
3375 // was added; skip the check in that case to preserve backward compatibility.
3376 var logicalTask *persistencespb.ChasmComponentAttributes_Task
3377 if taskInfo.TaskVersionedTransition != nil {
3378 componentAttr := node.serializedNode.Metadata.GetComponentAttributes()
3379 for _, t := range componentAttr.GetSideEffectTasks() {
3380 if transitionhistory.Compare(t.VersionedTransition, taskInfo.TaskVersionedTransition) == 0 &&
3381 t.VersionedTransitionOffset == taskInfo.TaskVersionedTransitionOffset {
3382 logicalTask = t
3383 break
3384 }
3385 }
3386 if logicalTask == nil {
3387 return false, false, nil
3388 }
3389 }

Callers

nothing calls this directly

Calls 15

findNodeMethod · 0.95
UnexpectedInternalErrFunction · 0.92
CompareFunction · 0.92
deserializeTaskFunction · 0.85
TaskByIDMethod · 0.80
GetSideEffectTasksMethod · 0.80
prepareComponentValueMethod · 0.80
validateTaskMethod · 0.80
NewContextFunction · 0.70

Tested by

no test coverage detected