sequential_scheduler.go ×11

Frontier kind: Code frontier

unlabeled · c_d4d7d6478843

21 tests · 1646 LOC · 66 files · introduces 0 tests · 52 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
11 ranges52 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
203 ranges1646 lines · 66 files · Browse complete extent
All tests (intent)
21 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: 52 introduced LOC across 11 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/common/tasks/sequential_scheduler.go 52 introduced LOC · 11 ranges

Open complete file

52 taskQueueFactory SequentialTaskQueueFactory[T],
53 logger log.Logger,
54 > ) *SequentialScheduler[T] { sequential_scheduler.go
55 > return &SequentialScheduler[T]{
56 > status: common.DaemonStatusInitialized,
57 > shutdownChan: make(chan struct{}),
58 > options: options,
59 >
60 > logger: logger,
61 >
62 > queueFactory: taskQueueFactory,
63 > queueChan: make(chan SequentialTaskQueue[T], options.QueueSize),
64 > queues: collection.NewShardedConcurrentTxMap(1024, taskQueueHashFn),
65 > }
66 > }
67
68 > func (s *SequentialScheduler[T]) Start() { sequential_scheduler.go
69 > if !atomic.CompareAndSwapInt32(
70 > &s.status,
71 > common.DaemonStatusInitialized,
72 > common.DaemonStatusStarted,
73 > ) {
74 return
75 }
76
77 > initialWorkerCount, workerCountSubscriptionCancelFn := s.options.WorkerCount(s.updateWorkerCount) sequential_scheduler.go
78 > s.workerCountSubscriptionCancelFn = workerCountSubscriptionCancelFn
79 > s.updateWorkerCount(initialWorkerCount)
80 >
81 > s.logger.Info("sequential scheduler started")
82 }
83
199 }
200
201 > func (s *SequentialScheduler[T]) updateWorkerCount(targetWorkerNum int) { sequential_scheduler.go
202 > s.workerLock.Lock()
203 > defer s.workerLock.Unlock()
204 >
205 > if s.isStopped() {
206 // Always set the value to 0 when scheduler is stopped,
207 // in case there's a race condition between subscription callback invocation
210 }
211
212 > if targetWorkerNum < 0 { sequential_scheduler.go
213 s.logger.Error("Target worker pool size is negative. Please fix the dynamic config.", tag.Key("worker-pool-size"), tag.Value(targetWorkerNum))
214 return
215 }
216
217 > currentWorkerNum := len(s.workerShutdownCh) sequential_scheduler.go
218 > if targetWorkerNum == currentWorkerNum {
219 return
220 }
221
222 > if targetWorkerNum > currentWorkerNum { sequential_scheduler.go
223 > s.startWorkers(targetWorkerNum - currentWorkerNum)
224 > } else {
225 s.stopWorkers(currentWorkerNum - targetWorkerNum)
226 }
227
228 > s.logger.Info("Update worker pool size", tag.Key("worker-pool-size"), tag.Value(targetWorkerNum)) sequential_scheduler.go
229 }
230
231 func (s *SequentialScheduler[T]) startWorkers(
232 count int,
234 > for range count {
235 > shutdownCh := make(chan struct{})
236 > s.workerShutdownCh = append(s.workerShutdownCh, shutdownCh)
237 >
238 > s.shutdownWG.Add(1)
239 > go s.pollTaskQueue(shutdownCh)
240 > }
241 }
242
252 }
253
254 > func (s *SequentialScheduler[T]) pollTaskQueue(workerShutdownCh <-chan struct{}) { sequential_scheduler.go
255 > defer s.shutdownWG.Done()
256 >
257 > for {
258 > select {
259 case <-s.shutdownChan:
260 s.drainTasks()
368 }
369
370 > func (s *SequentialScheduler[T]) isStopped() bool { sequential_scheduler.go
371 > return atomic.LoadInt32(&s.status) == common.DaemonStatusStopped
372 > }