invoker_tasks.go ×13

Frontier kind: Code frontier

unlabeled · c_83e420644c52

22 tests · 5138 LOC · 170 files · introduces 0 tests · 71 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
18 ranges71 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1175 ranges5138 lines · 170 files · Browse complete extent
All tests (intent)
22 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: 71 introduced LOC across 18 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/chasm/lib/scheduler/invoker_tasks.go 53 introduced LOC · 13 ranges

Open complete file

432 _ chasm.TaskAttributes,
433 _ *schedulerpb.InvokerProcessBufferTask,
434 > ) error { invoker_tasks.go
435 > scheduler := invoker.Scheduler.Get(ctx)
436 > newTaggedMetricsHandler(h.metricsHandler, scheduler).
437 > Counter(metrics.ScheduleInvokerProcessBufferTask.Name()).
438 > Record(1, metrics.OutcomeTag(outcomeFired), metrics.ReasonTag(reasonNone))
439 >
440 > invoker.getOrCreateEventLog(ctx).LogEvent(ctx, "processBufferTask executed")
441 >
442 > // Make sure we have something to start.
443 > executionInfo := scheduler.Schedule.GetAction().GetStartWorkflow()
444 > if executionInfo == nil {
445 return queueerrors.NewUnprocessableTaskError("schedules must have an Action set")
446 }
447
448 // Compute actions to take from the current buffer.
449 > result := h.processBuffer(ctx, invoker, scheduler) invoker_tasks.go
450 >
451 > // Update Scheduler metadata.
452 > var totalMissedCatchup int64
453 > for _, count := range result.missedCatchupByActionRunning {
454 totalMissedCatchup += count
455 }
456 > scheduler.recordActionResult(&schedulerActionResult{ invoker_tasks.go
457 > overlapSkipped: result.overlapSkipped,
458 > missedCatchupWindow: totalMissedCatchup,
459 > })
460 > for overlapPolicy, count := range result.overlapSkippedByPolicy {
461 newTaggedMetricsHandler(h.metricsHandler, scheduler).WithTags(
462 metrics.StringTag(metrics.ScheduleOverlapPolicyTag, overlapPolicy.String()),
463 ).Counter(metrics.ScheduleOverlapSkipped.Name()).Record(count)
464 }
465 > for actionRunning, count := range result.missedCatchupByActionRunning { invoker_tasks.go
466 newTaggedMetricsHandler(h.metricsHandler, scheduler).WithTags(
467 metrics.StringTag(metrics.ScheduleMissedReasonTag, metrics.ScheduleMissedReasonBufferExpired),
471
472 // Update internal state and create new tasks.
473 > invoker.recordProcessBufferResult(ctx, &result) invoker_tasks.go
474 >
475 > return nil
476 }
477
483 invoker *Invoker,
484 scheduler *Scheduler,
485 > ) (result processBufferResult) { invoker_tasks.go
486 > runningWorkflows := invoker.runningWorkflowExecutions()
487 > isRunning := len(runningWorkflows) > 0
488 > result.missedCatchupByActionRunning = make(map[bool]int64)
489 >
490 > // Processing completely ignores any BufferedStart that's already executing/backing off.
491 > pendingBufferedStarts := util.FilterSlice(invoker.GetBufferedStarts(), func(start *schedulespb.BufferedStart) bool {
492 return start.Attempt == 0
493 })
494
495 // Resolve overlap policies and trim BufferedStarts that are skipped by policy.
496 > action := legacyscheduler.ProcessBuffer(pendingBufferedStarts, isRunning, scheduler.resolveOverlapPolicy) invoker_tasks.go
497 >
498 > // ProcessBuffer will drop starts by omitting them from NewBuffer. Start with the
499 > // diff between the input and NewBuffer, and add any executing starts.
500 > keepStarts := make(map[string]struct{}) // request ID -> is present
501 > for _, start := range action.NewBuffer {
502 keepStarts[start.GetRequestId()] = struct{}{}
503 }
504
505 // Combine all available starts.
506 > readyStarts := action.OverlappingStarts invoker_tasks.go
507 > if action.NonOverlappingStart != nil {
508 readyStarts = append(readyStarts, action.NonOverlappingStart)
509 }
510
511 // Update result metrics.
512 > result.overlapSkipped = action.OverlapSkipped invoker_tasks.go
513 > result.overlapSkippedByPolicy = action.OverlapSkippedByPolicy
514 >
515 > // Add starting workflows to result, trim others. Catchup-window expiry is
516 > // checked before useScheduledAction so that a start past its catchup
517 > // window doesn't consume a LimitedActions slot.
518 > droppedCounter := newTaggedMetricsHandler(h.metricsHandler, scheduler).
519 > Counter(metrics.ScheduleBufferedStartDropped.Name())
520 > for _, start := range readyStarts {
521 deadline := h.startWorkflowDeadline(ctx, scheduler, start)
522 if ctx.Now(invoker).After(deadline) {
552 }
553
554 > result.discardStarts = util.FilterSlice(pendingBufferedStarts, func(start *schedulespb.BufferedStart) bool { invoker_tasks.go
555 _, keep := keepStarts[start.GetRequestId()]
556 return !keep
558
559 // Terminate overrides cancel if both are requested.
560 > if action.NeedTerminate { invoker_tasks.go
561 result.terminateWorkflows = runningWorkflows
562 > } else if action.NeedCancel { invoker_tasks.go
563 result.cancelWorkflows = runningWorkflows
564 }
565
566 > return invoker_tasks.go
567 }
568
go.temporal.io/server/chasm/lib/scheduler/invoker.go 18 introduced LOC · 5 ranges

Open complete file

76 // recordProcessBufferResult updates the Invoker's internal state based on result, as well as the
77 // LastProcessedTime watermark. Tasks to continue execution are added, if needed.
78 > func (i *Invoker) recordProcessBufferResult(ctx chasm.MutableContext, result *processBufferResult) { invoker.go
79 > discards := make(map[string]bool) // request ID -> is present
80 > ready := make(map[string]bool)
81 > for _, start := range result.discardStarts {
82 discards[start.RequestId] = true
83 }
84 > for _, start := range result.startWorkflows { invoker.go
85 ready[start.RequestId] = true
86 }
87
88 // Drop discarded starts, and update requested starts for execution.
89 > var starts []*schedulespb.BufferedStart invoker.go
90 > readiedStarts := 0
91 > deferredStarts := 0
92 > for _, start := range i.GetBufferedStarts() {
93 if discards[start.RequestId] {
94 continue
111 }
112
113 > if readiedStarts > 0 || deferredStarts > 0 { invoker.go
114 i.getOrCreateEventLog(ctx).LogEvent(ctx,
115 fmt.Sprintf("recordProcessBufferResult readied %d starts, deferred %d starts", readiedStarts, deferredStarts))
117
118 // Update internal state.
119 > i.BufferedStarts = starts invoker.go
120 > i.CancelWorkflows = append(i.GetCancelWorkflows(), result.cancelWorkflows...)
121 > i.TerminateWorkflows = append(i.GetTerminateWorkflows(), result.terminateWorkflows...)
122 > i.LastProcessedTime = timestamppb.New(ctx.Now(i))
123 >
124 > // Re-arm tasks if this call changed state, or if the LastProcessedTime advance
125 > // just unblocked backed-off starts.
126 > i.addTasks(ctx)
127 }
128