api.go ×22

Frontier kind: Code frontier

unlabeled · c_841171973c51

40 tests · 6617 LOC · 214 files · introduces 0 tests · 128 LOC · 4 files

Introduces — evidence that enters the hierarchy at this concept

Code
26 ranges128 lines · 4 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1326 ranges6617 lines · 214 files · Browse complete extent
All tests (intent)
40 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.

4 files ranked by introduced lines: 128 introduced LOC across 26 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/service/history/api/startworkflow/api.go 107 introduced LOC · 22 ranges

Open complete file

95 reactivationSignaler api.VersionReactivationSignalerFn,
96 createLeaseFn api.CreateOrUpdateLeaseFunc,
97 > ) (*Starter, error) { api.go
98 > namespaceEntry, err := api.GetActiveNamespace(shardContext, namespace.ID(request.GetNamespaceId()), request.StartRequest.WorkflowId)
99 > if err != nil {
100 return nil, err
101 }
102
103 > return &Starter{ api.go
104 > // metricsHandler is lazily created when needed in Starter.getMetricsHandler
105 > metricsHandler: nil,
106 > shardContext: shardContext,
107 > workflowConsistencyChecker: workflowConsistencyChecker,
108 > matchingClient: matchingClient,
109 > tokenSerializer: tokenSerializer,
110 > request: request,
111 > namespace: namespaceEntry,
112 > createOrUpdateLeaseFn: createLeaseFn,
113 > versionCache: versionCache,
114 > reactivationSignaler: reactivationSignaler,
115 > }, nil
116 }
117
118 // prepare applies request overrides, validates the request, and records eager execution metrics.
119 > func (s *Starter) prepare(ctx context.Context) error { api.go
120 > request := s.request.StartRequest
121 >
122 > api.MigrateWorkflowIDReusePolicyForRunningWorkflow(
123 > &request.WorkflowIdReusePolicy,
124 > &request.WorkflowIdConflictPolicy)
125 >
126 > api.OverrideStartWorkflowExecutionRequest(
127 > request,
128 > metrics.HistoryStartWorkflowExecutionScope,
129 > s.shardContext,
130 > s.shardContext.GetMetricsHandler(),
131 > )
132 >
133 > err := api.ValidateStartWorkflowExecutionRequest(ctx, request, s.shardContext, s.namespace, "StartWorkflowExecution")
134 > if err != nil {
135 return err
136 }
137
138 // Validation for versioning override, if any.
139 > s.shouldSkipReactivation, s.revisionNumber, err = worker_versioning.ValidateVersioningOverrideAndGetReactivationEligibility(ctx, request.GetVersioningOverride(), s.matchingClient, s.versionCache, request.GetTaskQueue().GetName(), enumspb.TASK_QUEUE_TYPE_WORKFLOW, s.namespace.ID().String()) api.go
140 > if err != nil {
141 return err
142 }
143
144 > if request.RequestEagerExecution { api.go
145 metricsHandler := s.getMetricsHandler()
146 metrics.WorkflowEagerExecutionCounter.With(metricsHandler).Record(1)
157 }
158 }
159 > return nil api.go
160 }
161
173 }
174
175 > func (s *Starter) requestEagerStart() bool { api.go
176 > return s.request.StartRequest.GetRequestEagerExecution()
177 > }
178
179 // Invoke starts a new workflow execution.
182 func (s *Starter) Invoke(
183 ctx context.Context,
184 > ) (resp *historyservice.StartWorkflowExecutionResponse, startOutcome StartOutcome, retError error) { api.go
185 > request := s.request.StartRequest
186 > if err := s.prepare(ctx); err != nil {
187 return nil, StartErr, err
188 }
189
190 > creationParams, err := s.prepareNewWorkflow(ctx, request.GetWorkflowId()) api.go
191 > if err != nil {
192 return nil, StartErr, err
193 }
194 > defer func() { api.go
195 > creationParams.workflowLease.GetReleaseFn()(retError)
196 > }()
197
198 > currentExecutionLock, err := s.lockCurrentWorkflowExecution(ctx) api.go
199 > if err != nil {
200 return nil, StartErr, err
201 }
202 > defer func() { api.go
203 > currentExecutionLock(retError)
204 > }()
205
206 > err = s.createBrandNew(ctx, creationParams) api.go
207 > if err != nil {
208 var currentWorkflowConditionFailedError *persistence.CurrentWorkflowConditionFailedError
209 if errors.As(err, &currentWorkflowConditionFailedError) && len(currentWorkflowConditionFailedError.RunID) > 0 {
235 func (s *Starter) lockCurrentWorkflowExecution(
236 ctx context.Context,
237 > ) (historyi.ReleaseWorkflowContextFunc, error) { api.go
238 > currentRelease, err := s.workflowConsistencyChecker.GetWorkflowCache().GetOrCreateCurrentExecution(
239 > ctx,
240 > s.shardContext,
241 > s.namespace.ID(),
242 > s.request.StartRequest.WorkflowId,
243 > chasm.WorkflowArchetypeID,
244 > locks.PriorityHigh,
245 > )
246 > if err != nil {
247 return nil, err
248 }
249 > return currentRelease, nil api.go
250 }
251
252 // prepareNewWorkflow creates a new workflow context, and closes its mutable state transaction as snapshot.
253 // It returns the creationContext which can later be used to insert into the executions table.
254 > func (s *Starter) prepareNewWorkflow(ctx context.Context, workflowID string) (*creationParams, error) { api.go
255 > runID := primitives.NewUUID().String()
256 > mutableState, err := api.NewWorkflowWithSignal(
257 > s.shardContext,
258 > s.namespace,
259 > workflowID,
260 > runID,
261 > s.request,
262 > nil,
263 > )
264 > if err != nil {
265 return nil, err
266 }
267
268 > workflowLease, err := s.createOrUpdateLeaseFn(nil, s.shardContext, mutableState) api.go
269 > if err != nil {
270 return nil, err
271 }
272
273 > workflowTaskInfo := mutableState.GetStartedWorkflowTask() api.go
274 > if s.requestEagerStart() && workflowTaskInfo == nil {
275 return nil, softassert.UnexpectedInternalErr(
276 s.shardContext.GetLogger(),
279 )
280 }
281 > workflowSnapshot, eventBatches, err := mutableState.CloseTransactionAsSnapshot( api.go
282 > ctx,
283 > historyi.TransactionPolicyActive,
284 > )
285 > if err != nil {
286 return nil, err
287 }
288 > if len(eventBatches) != 1 { api.go
289 return nil, softassert.UnexpectedInternalErr(
290 s.shardContext.GetLogger(),
294 }
295
296 > return &creationParams{ api.go
297 > workflowID: workflowID,
298 > runID: runID,
299 > workflowLease: workflowLease,
300 > workflowTaskInfo: workflowTaskInfo,
301 > workflowSnapshot: workflowSnapshot,
302 > workflowEventBatches: eventBatches,
303 > }, nil
304 }
305
306 // createBrandNew creates a "brand new" execution in the executions table.
307 > func (s *Starter) createBrandNew(ctx context.Context, creationParams *creationParams) error { api.go
308 > return creationParams.workflowLease.GetContext().CreateWorkflowExecution(
309 > ctx,
310 > s.shardContext,
311 > persistence.CreateWorkflowModeBrandNew,
312 > "", // prevRunID
313 > 0, // prevLastWriteVersion
314 > creationParams.workflowLease.GetMutableState(),
315 > creationParams.workflowSnapshot,
316 > creationParams.workflowEventBatches,
317 > historyi.TransactionPolicyActive,
318 > )
319 > }
320
321 // handleConflict handles CurrentWorkflowConditionFailedError where there's a workflow with the same workflowID.
go.temporal.io/server/service/history/history_engine.go 14 introduced LOC · 2 ranges

Open complete file

412 ctx context.Context,
413 startRequest *historyservice.StartWorkflowExecutionRequest,
414 > ) (*historyservice.StartWorkflowExecutionResponse, error) { history_engine.go
415 > starter, err := startworkflow.NewStarter(
416 > e.shardContext,
417 > e.workflowConsistencyChecker,
418 > e.tokenSerializer,
419 > startRequest,
420 > e.matchingClient,
421 > e.versionCache,
422 > e.workerDeploymentClient.SignalVersionReactivation,
423 > api.NewWorkflowLeaseAndContext,
424 > )
425 > if err != nil {
426 return nil, err
427 }
428
429 > resp, _, err := starter.Invoke(ctx) history_engine.go
430 > return resp, err
431 }
432
go.temporal.io/server/api/historyservice/v1/request_response.pb.go 4 introduced LOC · 1 range

Open complete file

237 }
238
239 > func (x *StartWorkflowExecutionRequest) GetNamespaceId() string { request_response.pb.go
240 > if x != nil {
241 > return x.NamespaceId
242 > }
243 return ""
244 }
go.temporal.io/server/service/history/api/consistency_checker.go 3 introduced LOC · 1 range

Open complete file

91 }
92
93 > func (c *WorkflowConsistencyCheckerImpl) GetWorkflowCache() wcache.Cache { consistency_checker.go
94 > return c.workflowCache
95 > }
96
97 func (c *WorkflowConsistencyCheckerImpl) GetCurrentWorkflowRunID(