handover_workflow.go ×14

Frontier kind: Code frontier

unlabeled · c_1f36a1686e42

2 tests · 2501 LOC · 121 files · introduces 0 tests · 69 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
14 ranges69 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
355 ranges2501 lines · 121 files · Browse complete extent
All tests (intent)
2 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

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 native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 69 introduced LOC across 14 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/service/worker/migration/handover_workflow.go 69 introduced LOC · 14 ranges

Open complete file

60 }
61
62 > func NamespaceHandoverWorkflow(ctx workflow.Context, params NamespaceHandoverParams) (retErr error) { handover_workflow.go
63 > if err := validateAndSetNamespaceHandoverParams(&params); err != nil {
64 return err
65 }
66 > retryPolicy := &temporal.RetryPolicy{ handover_workflow.go
67 > InitialInterval: time.Second,
68 > MaximumInterval: time.Second,
69 > BackoffCoefficient: 1,
70 > }
71 > ao := workflow.ActivityOptions{
72 > StartToCloseTimeout: time.Second * 10,
73 > RetryPolicy: retryPolicy,
74 > }
75 > ctx = workflow.WithActivityOptions(ctx, ao)
76 >
77 > // ** Step 1: Get Cluster Metadata **
78 > var metadataResp MetadataResponse
79 > MetadataRequest := MetadataRequest{Namespace: params.Namespace}
80 > var a *activities
81 > err := workflow.ExecuteActivity(ctx, a.GetMetadata, MetadataRequest).Get(ctx, &metadataResp)
82 > if err != nil {
83 return err
84 }
85
86 // ** Step 2: Get current replication status **
87 > var repStatus ReplicationStatus handover_workflow.go
88 > err = workflow.ExecuteActivity(ctx, a.GetMaxReplicationTaskIDs).Get(ctx, &repStatus)
89 > if err != nil {
90 return err
91 }
92
93 // ** Step 3: Wait for Remote Cluster to catch-up on Replication Tasks
94 > ao2 := workflow.ActivityOptions{ handover_workflow.go
95 > StartToCloseTimeout: time.Hour,
96 > HeartbeatTimeout: time.Second * 10,
97 > RetryPolicy: retryPolicy,
98 > }
99 > ctx2 := workflow.WithActivityOptions(ctx, ao2)
100 > waitRequest := WaitReplicationRequest{
101 > Namespace: params.Namespace,
102 > ShardCount: metadataResp.ShardCount,
103 > RemoteCluster: params.RemoteCluster,
104 > AllowedLagging: time.Duration(params.AllowedLaggingSeconds) * time.Second,
105 > WaitForTaskIds: repStatus.MaxReplicationTaskIds,
106 > AllowedLaggingTasks: params.AllowedLaggingTasks,
107 > }
108 > err = workflow.ExecuteActivity(ctx2, a.WaitReplication, waitRequest).Get(ctx2, nil)
109 > if err != nil {
110 return err
111 }
114 // handover failed or succeeded, the namespace (for whichever cluster it is Active on)
115 // is able to process traffic again.
116 > resetState := func() { handover_workflow.go
117 > resetStateRequest := updateStateRequest{
118 > Namespace: params.Namespace,
119 > NewState: enumspb.REPLICATION_STATE_NORMAL,
120 > }
121 > var err error
122 > if workflow.GetVersion(ctx, "detach-handover-ctx-20250829", workflow.DefaultVersion, 1) > workflow.DefaultVersion {
123 > infiniteRetryOption := workflow.ActivityOptions{StartToCloseTimeout: time.Second * 10}
124 > detachCtx, cancel := workflow.NewDisconnectedContext(ctx)
125 > resetStateCtx := workflow.WithActivityOptions(detachCtx, infiniteRetryOption)
126 > err = workflow.ExecuteActivity(resetStateCtx, a.UpdateNamespaceState, resetStateRequest).Get(resetStateCtx, nil)
127 > cancel()
128 > } else {
129 err = workflow.ExecuteActivity(ctx, a.UpdateNamespaceState, resetStateRequest).Get(ctx, nil)
130 }
131 > if err != nil && retErr == nil { handover_workflow.go
132 retErr = err
133 }
136 // Register before Step 4 so a cancel during the HANDOVER write still triggers the reset.
137 // The reset activity is idempotent so a no-op pre-Step-4 is fine.
138 > deferBeforeHandover := workflow.GetVersion(ctx, "defer-before-handover-write-20260510", workflow.DefaultVersion, 1) > workflow.DefaultVersion handover_workflow.go
139 > if deferBeforeHandover {
140 > defer resetState()
141 > }
142
143 // ** Step 4: RecoverOrInitialize Handover (WARNING: Namespace cannot serve traffic while in this state)
144 > handoverRequest := updateStateRequest{ handover_workflow.go
145 > Namespace: params.Namespace,
146 > NewState: enumspb.REPLICATION_STATE_HANDOVER,
147 > }
148 > err = workflow.ExecuteActivity(ctx, a.UpdateNamespaceState, handoverRequest).Get(ctx, nil)
149 > if err != nil {
150 return err
151 }
186 }
187
188 > func validateAndSetNamespaceHandoverParams(params *NamespaceHandoverParams) error { handover_workflow.go
189 > if len(params.Namespace) == 0 {
190 return temporal.NewNonRetryableApplicationError("InvalidArgument: Namespace is required", "InvalidArgument", nil)
191 }
192 > if len(params.RemoteCluster) == 0 { handover_workflow.go
193 return temporal.NewNonRetryableApplicationError("InvalidArgument: RemoteCluster is required", "InvalidArgument", nil)
194 }
195 > if params.AllowedLaggingSeconds <= minimumAllowedLaggingSeconds { handover_workflow.go
196 params.AllowedLaggingSeconds = minimumAllowedLaggingSeconds
197 }
198 > if params.AllowedLaggingSeconds >= maximumAllowedLaggingSeconds { handover_workflow.go
199 params.AllowedLaggingSeconds = maximumAllowedLaggingSeconds
200 }
201 > if params.HandoverTimeoutSeconds >= maximumHandoverTimeoutSeconds { handover_workflow.go
202 params.HandoverTimeoutSeconds = maximumHandoverTimeoutSeconds
203 }
204
205 > return nil handover_workflow.go
206 }