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.

1 //go:generate mockgen -package $GOPACKAGE -source $GOFILE -destination component_mock.go
2
3 package chasm
4
5 import (
6 "context"
7 "reflect"
8 "strconv"
9
10 commonpb "go.temporal.io/api/common/v1"
11 )
12
13 type Component interface {
14 LifecycleState(Context) LifecycleState
15
16 // we may not need this in the beginning
17 mustEmbedUnimplementedComponent()
18 }
19
20 type TerminableComponent interface {
21 Component
22
23 // Terminate method is invoked by the chasm framework on an execution's root component when the execution
24 // needs to be forcefully terminated.
25 // Some examples include:
26 // - Execution state becomes too large.
27 // - Two running executions with the same businessID when namespace performs a force failover.
28 Terminate(MutableContext, TerminateComponentRequest) (TerminateComponentResponse, error)
29 }
30
31 type TerminateComponentRequest struct {
32 Identity string
33 Reason string
34 Details *commonpb.Payloads
35 RequestID string
36 }
37
38 type TerminateComponentResponse struct{}
39
40 // RootComponent is the interface that must be implemented by the top level component of a chasm execution.
41 // When the RootComponent's LifecycleState transitions to a closed state, the entire execution is considered closed,
42 // and will be cleaned up by the chasm framework after namespace's retention period. The BusinessID is also available for reuse.
43 //
44 // TODO: (not yet true) Visibility record will no longer be updated after RootComponent is closed.
45 type RootComponent interface {
46 TerminableComponent
47
48 // ContextMetadata returns execution metadata to propagate to the request context.
49 // When the ContextMetadataInterceptor is configured with setTrailer=true (history, matching),
50 // these keys are propagated via gRPC trailers. Keys defined in common/contextutil/metadata.go.
51 ContextMetadata(Context) map[string]string
52 }
53
54 // Embed UnimplementedComponent to get forward compatibility
55 type UnimplementedComponent struct{}
56
57 func (UnimplementedComponent) mustEmbedUnimplementedComponent() {}
58
59 var UnimplementedComponentT = reflect.TypeFor[UnimplementedComponent]()
60
61 // Shall it be named ComponentLifecycleState?
62 type LifecycleState int
63
64 const (
65 // Lifecycle states that are considered OPEN
66 //
67 // LifecycleStateCreated LifecycleState = 1 << iota
68 LifecycleStateRunning LifecycleState = 2 << iota
69 LifecycleStatePaused
70
71 // Lifecycle states that are considered CLOSED
72 //
73 LifecycleStateCompleted
74 LifecycleStateFailed
75 // LifecycleStateTerminated
76 // LifecycleStateTimedout
77 // LifecycleStateReset
78 )
79
80 > func (s LifecycleState) IsClosed() bool { component.go ×1
81 > return s >= LifecycleStateCompleted
82 > }
83
84 > func (s LifecycleState) IsPaused() bool { component.go ×1
85 > return s == LifecycleStatePaused
86 > }
87
88 func (s LifecycleState) String() string {
89 switch s {
90 case LifecycleStateRunning:
91 return "Running"
92 case LifecycleStatePaused:
93 return "Paused"
94 case LifecycleStateCompleted:
95 return "Completed"
96 case LifecycleStateFailed:
97 return "Failed"
98 default:
99 return strconv.Itoa(int(s))
100 }
101 }
102
103 type OperationIntent int
104
105 const (
106 OperationIntentProgress OperationIntent = 1 << iota
107 OperationIntentObserve
108
109 OperationIntentUnspecified = OperationIntent(0)
110 )
111
112 // The operation intent must come from the context
113 // as the handler may not pass the endpoint request as Input to,
114 // say, the chasm.UpdateComponent method.
115 // So similar to the chasm engine, handler needs to add the intent
116 // to the context.
117 type operationIntentCtxKeyType struct{}
118
119 var operationIntentCtxKey = operationIntentCtxKeyType{}
120
121 func newContextWithOperationIntent(
122 ctx context.Context,
123 intent OperationIntent,
124 > ) context.Context { component.go ×1
125 > return context.WithValue(ctx, operationIntentCtxKey, intent)
126 > }
127
128 func operationIntentFromContext(
129 ctx context.Context,
130 > ) OperationIntent { component.go ×1
131 > intent, ok := ctx.Value(operationIntentCtxKey).(OperationIntent)
132 > if !ok {
133 > return OperationIntentUnspecified tree.go ×9
134 > }
135 > return intent component.go ×1
136 }