invoker_tasks.go ×16

Frontier kind: Code frontier

unlabeled · c_b299baadd098

11 tests · 5605 LOC · 177 files · introduces 0 tests · 114 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
17 ranges114 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1279 ranges5605 lines · 177 files · Browse complete extent
All tests (intent)
11 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.

2 files ranked by introduced lines: 114 introduced LOC across 17 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/chasm/lib/scheduler/invoker_tasks.go 105 introduced LOC · 16 ranges

Open complete file

162 _ chasm.TaskAttributes,
163 _ *schedulerpb.InvokerExecuteTask,
164 > ) error { invoker_tasks.go
165 > var result executeResult
166 >
167 > var invoker *Invoker
168 > var scheduler *Scheduler
169 > var lastCompletionState *schedulerpb.LastCompletionResult
170 > var schedulerRef []byte
171 > var now time.Time
172 >
173 > // Read and deep copy returned components, since we'll continue to access them
174 > // outside of this function (outside of the MS lock).
175 > _, err := chasm.ReadComponent(
176 > ctx,
177 > invokerRef,
178 > func(i *Invoker, ctx chasm.Context, _ any) (struct{}, error) {
179 > invoker = &Invoker{
180 > InvokerState: common.CloneProto(i.InvokerState),
181 > }
182 >
183 > s := i.Scheduler.Get(ctx)
184 > scheduler = &Scheduler{
185 > SchedulerState: common.CloneProto(s.SchedulerState),
186 > cacheConflictToken: s.cacheConflictToken,
187 > compiledSpec: s.compiledSpec,
188 > }
189 >
190 > lcs := s.LastCompletionResult.Get(ctx)
191 > lastCompletionState = common.CloneProto(lcs)
192 >
193 > // Capture the scheduler's component ref so a per-start completion callback (carrying that
194 > // start's request ID in its token) can be built outside the MS lock.
195 > ref, err := ctx.Ref(s)
196 > if err != nil {
197 return struct{}{}, err
198 }
199 > schedulerRef = ref invoker_tasks.go
200 >
201 > // Captured here for applyBackoff (runs outside this closure): BackoffTime
202 > // must be framework-clock to match LastProcessedTime and task deadlines.
203 > now = ctx.Now(i)
204 >
205 > return struct{}{}, nil
206 },
207 nil,
208 )
209 > if err != nil { invoker_tasks.go
210 return fmt.Errorf("failed to read component: %w", err)
211 }
212 > if scheduler == nil { invoker_tasks.go
213 return errors.New("scheduler component was nil after read")
214 }
215
216 > logger := newTaggedLogger(h.baseLogger, scheduler) invoker_tasks.go
217 > metricsHandler := newTaggedMetricsHandler(h.metricsHandler, scheduler)
218 > metricsHandler.Counter(metrics.ScheduleInvokerExecuteTask.Name()).Record(1, metrics.OutcomeTag(outcomeFired), metrics.ReasonTag(reasonNone))
219 >
220 > // Terminate, cancel, and start workflows. The result struct contains the
221 > // complete outcome of all requests executed in a single batch.
222 > //
223 > // Invoker will never have work pending for more than one of these calls (terminate,
224 > // cancel, start) at a time, so it isn't sensible to run them in parallel. The
225 > // structure below is simply for code simplicity.
226 > ictx := h.newInvokerTaskHandlerContext(ctx, scheduler)
227 > result = result.Append(h.terminateWorkflows(ictx, logger, metricsHandler, scheduler, invoker.GetTerminateWorkflows()))
228 > result = result.Append(h.cancelWorkflows(ictx, logger, metricsHandler, scheduler, invoker.GetCancelWorkflows()))
229 > result = result.Append(h.startWorkflows(ictx, logger, metricsHandler, scheduler, invoker, lastCompletionState, schedulerRef, now))
230 >
231 > // Record action results on the Invoker (internal state), as well as the
232 > // Scheduler (user-facing metrics).
233 > _, _, err = chasm.UpdateComponent(
234 > ctx,
235 > invokerRef,
236 > func(i *Invoker, ctx chasm.MutableContext, _ any) (chasm.NoValue, error) {
237 > s := i.Scheduler.Get(ctx)
238 > // Use newlyStarted (not len(result.CompletedStarts)) so a concurrent
239 > // ExecuteTask's duplicate StartWorkflow can't inflate ActionCount.
240 > newlyStarted, droppedDuplicates := i.recordExecuteResult(ctx, &result)
241 > s.recordActionResult(&schedulerActionResult{actionCount: int64(newlyStarted)})
242 > if droppedDuplicates > 0 {
243 h.recordDuplicateExecuteDrops(s, droppedDuplicates)
244 }
245 > return nil, nil invoker_tasks.go
246 },
247 nil,
248 )
249 > if err != nil { invoker_tasks.go
250 return fmt.Errorf("failed to update component state: %w", err)
251 }
252
253 > return nil invoker_tasks.go
254 }
255
271 scheduler *Scheduler,
272 targets []*commonpb.WorkflowExecution,
273 > ) (result executeResult) { invoker_tasks.go
274 > var wg sync.WaitGroup
275 > var resultMutex sync.Mutex
276 >
277 > for _, wf := range targets {
278 if !ctx.takeNextAction() {
279 break
309 scheduler *Scheduler,
310 targets []*commonpb.WorkflowExecution,
311 > ) (result executeResult) { invoker_tasks.go
312 > var wg sync.WaitGroup
313 > var resultMutex sync.Mutex
314 >
315 > for _, wf := range targets {
316 if !ctx.takeNextAction() {
317 break
350 schedulerRef []byte,
351 now time.Time,
352 > ) (result executeResult) { invoker_tasks.go
353 > metricsWithTag := metricsHandler.WithTags(
354 > metrics.StringTag(metrics.ScheduleActionTypeTag, metrics.ScheduleActionStartWorkflow))
355 >
356 > var wg sync.WaitGroup
357 > var resultMutex sync.Mutex
358 >
359 > for _, start := range invoker.getEligibleBufferedStarts() {
360 // Starts that haven't been executed yet will remain in `BufferedStarts`,
361 // without change, so another ExecuteTask will be immediately created to continue
785 ctx context.Context,
786 scheduler *Scheduler,
787 > ) invokerTaskHandlerContext { invoker_tasks.go
788 > tweakables := h.config.Tweakables(scheduler.Namespace)
789 > maxActions := tweakables.MaxActionsPerExecution
790 > if maxActions <= 0 {
791 maxActions = DefaultTweakables.MaxActionsPerExecution
792 }
793
794 > return invokerTaskHandlerContext{ invoker_tasks.go
795 > Context: ctx,
796 > actionsTaken: 0,
797 > maxActions: maxActions,
798 > }
799 }
800
go.temporal.io/server/chasm/lib/scheduler/invoker.go 9 introduced LOC · 1 range

Open complete file

143
144 // Append combines two executeResults (no deduplication is done).
145 > func (e *executeResult) Append(o executeResult) executeResult { invoker.go
146 > return executeResult{
147 > CompletedStarts: append(e.CompletedStarts, o.CompletedStarts...),
148 > RetryableStarts: append(e.RetryableStarts, o.RetryableStarts...),
149 > FailedStarts: append(e.FailedStarts, o.FailedStarts...),
150 > CompletedCancels: append(e.CompletedCancels, o.CompletedCancels...),
151 > CompletedTerminates: append(e.CompletedTerminates, o.CompletedTerminates...),
152 > }
153 > }
154
155 // recordExecuteResult updates the Invoker's internal state with the results of a