go.temporal.io/server/chasm/component.go
136 LOC · 15 covered · 121 uncovered · 6 ranges · 846 concepts · 6 introducers · 360 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
//go:generate mockgen -package $GOPACKAGE -source $GOFILE -destination component_mock.go
package chasm
import (
"context"
"reflect"
"strconv"
commonpb "go.temporal.io/api/common/v1"
)
type Component interface {
LifecycleState(Context) LifecycleState
// we may not need this in the beginning
mustEmbedUnimplementedComponent()
}
type TerminableComponent interface {
Component
// Terminate method is invoked by the chasm framework on an execution's root component when the execution
// needs to be forcefully terminated.
// Some examples include:
// - Execution state becomes too large.
// - Two running executions with the same businessID when namespace performs a force failover.
Terminate(MutableContext, TerminateComponentRequest) (TerminateComponentResponse, error)
}
type TerminateComponentRequest struct {
Identity string
Reason string
Details *commonpb.Payloads
RequestID string
}
type TerminateComponentResponse struct{}
// RootComponent is the interface that must be implemented by the top level component of a chasm execution.
// When the RootComponent's LifecycleState transitions to a closed state, the entire execution is considered closed,
// and will be cleaned up by the chasm framework after namespace's retention period. The BusinessID is also available for reuse.
//
// TODO: (not yet true) Visibility record will no longer be updated after RootComponent is closed.
type RootComponent interface {
TerminableComponent
// ContextMetadata returns execution metadata to propagate to the request context.
// When the ContextMetadataInterceptor is configured with setTrailer=true (history, matching),
// these keys are propagated via gRPC trailers. Keys defined in common/contextutil/metadata.go.
ContextMetadata(Context) map[string]string
}
// Embed UnimplementedComponent to get forward compatibility
type UnimplementedComponent struct{}
func (UnimplementedComponent) mustEmbedUnimplementedComponent() {}
var UnimplementedComponentT = reflect.TypeFor[UnimplementedComponent]()
// Shall it be named ComponentLifecycleState?
type LifecycleState int
const (
// Lifecycle states that are considered OPEN
//
// LifecycleStateCreated LifecycleState = 1 << iota
LifecycleStateRunning LifecycleState = 2 << iota
LifecycleStatePaused
// Lifecycle states that are considered CLOSED
//
LifecycleStateCompleted
LifecycleStateFailed
// LifecycleStateTerminated
// LifecycleStateTimedout
// LifecycleStateReset
)
return s >= LifecycleStateCompleted
}
return s == LifecycleStatePaused
}
func (s LifecycleState) String() string {
switch s {
case LifecycleStateRunning:
return "Running"
case LifecycleStatePaused:
return "Paused"
case LifecycleStateCompleted:
return "Completed"
case LifecycleStateFailed:
return "Failed"
default:
return strconv.Itoa(int(s))
}
}
type OperationIntent int
const (
OperationIntentProgress OperationIntent = 1 << iota
OperationIntentObserve
OperationIntentUnspecified = OperationIntent(0)
)
// The operation intent must come from the context
// as the handler may not pass the endpoint request as Input to,
// say, the chasm.UpdateComponent method.
// So similar to the chasm engine, handler needs to add the intent
// to the context.
type operationIntentCtxKeyType struct{}
var operationIntentCtxKey = operationIntentCtxKeyType{}
func newContextWithOperationIntent(
ctx context.Context,
intent OperationIntent,
return context.WithValue(ctx, operationIntentCtxKey, intent)
}
func operationIntentFromContext(
ctx context.Context,
intent, ok := ctx.Value(operationIntentCtxKey).(OperationIntent)
if !ok {
}
}