pernamespaceworker.go ×16

Frontier kind: Code frontier

unlabeled · c_e087dafae0a7

25 tests · 3058 LOC · 154 files · introduces 0 tests · 58 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
16 ranges58 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
481 ranges3058 lines · 154 files · Browse complete extent
All tests (intent)
25 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: 58 introduced LOC across 16 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/service/worker/pernamespaceworker.go 58 introduced LOC · 16 ranges

Open complete file

129 }
130
131 > func (wm *PerNamespaceWorkerManager) Running() bool { pernamespaceworker.go
132 > return atomic.LoadInt32(&wm.status) == common.DaemonStatusStarted
133 > }
134
135 func (wm *PerNamespaceWorkerManager) Start(
195 }
196
197 > func (wm *PerNamespaceWorkerManager) namespaceCallback(ns *namespace.Namespace, nsDeleted bool) { pernamespaceworker.go
198 > go wm.getWorkerByNamespace(ns).update(ns, nsDeleted, nil, nil)
199 > }
200
201 func (wm *PerNamespaceWorkerManager) refreshAll() {
232 }
233
234 > func (wm *PerNamespaceWorkerManager) getWorkerByNamespace(ns *namespace.Namespace) *perNamespaceWorker { pernamespaceworker.go
235 > wm.lock.Lock()
236 > defer wm.lock.Unlock()
237 >
238 > if worker, ok := wm.workers[ns.ID()]; ok {
239 return worker
240 }
241
242 > worker := &perNamespaceWorker{ pernamespaceworker.go
243 > wm: wm,
244 > logger: log.With(wm.logger, tag.WorkflowNamespace(ns.Name().String())),
245 > retrier: backoff.NewRetrier(backoff.NewExponentialRetryPolicy(wm.initialRetry), clock.NewRealTimeSource()),
246 > }
247 > count, c1 := wm.config.PerNamespaceWorkerCount(ns.Name().String(), worker.setWorkerCount)
248 > opts, c2 := wm.config.PerNamespaceWorkerOptions(ns.Name().String(), worker.setWorkerOptions)
249 > worker.ns = ns
250 > worker.count = count
251 > worker.opts = opts
252 > worker.cancel = func() { c1(); c2() }
253
254 > wm.workers[ns.ID()] = worker pernamespaceworker.go
255 > return worker
256 }
257
303
304 // called on namespace state change callback, membership change, and dynamic config change
305 > func (w *perNamespaceWorker) update(ns *namespace.Namespace, nsDeleted bool, newCount *int, newOpts *sdkworker.Options) { pernamespaceworker.go
306 > w.lock.Lock()
307 >
308 > if ns != nil {
309 > w.ns = ns
310 > // The name inside of *ns, which was used to initialize the logger, can change, but
311 > // don't update w.logger here, otherwise we'd have to hold w.lock just to log.
312 > }
313 > if newCount != nil {
314 w.count = *newCount
315 }
316 > if newOpts != nil { pernamespaceworker.go
317 w.opts = *newOpts
318 }
319
320 > refreshArgs := w.refreshArgs // copy before releasing lock pernamespaceworker.go
321 > isRetrying := w.retryTimer != nil
322 > w.lock.Unlock()
323 >
324 > if nsDeleted {
325 w.stopWorkerAndResetTimer()
326 // if namespace is fully deleted from db, we can remove from our map also
329 }
330
331 > if !isRetrying { pernamespaceworker.go
332 > w.refresh(refreshArgs)
333 > }
334 }
335
336 // handleError should be called on errors from worker creation or run. it will attempt to
337 // refresh the worker again at a later time.
338 > func (w *perNamespaceWorker) handleError(err error) { pernamespaceworker.go
339 > if err == nil {
340 return
341 }
379 // Returning an error from here means that we should retry creating/starting the worker.
380 // Returning noWorkerNeeded means any existing worker should be stopped.
381 > func (w *perNamespaceWorker) refresh(args refreshArgs) (retErr error) { pernamespaceworker.go
382 > defer func() {
383 > w.handleError(retErr)
384 > }()
385
386 // note w.lock is not locked until we're about to start/stop a worker
387
388 > if !w.wm.Running() || pernamespaceworker.go
389 > args.ns.State() == enumspb.NAMESPACE_STATE_DELETED ||
390 > //nolint:forbidigo // per-namespace worker lifecycle, no workflow context
391 > !args.ns.ActiveInCluster(w.wm.thisClusterName) {
392
393 return errNoWorkerNeeded
565 }
566
567 > func (w *perNamespaceWorker) stopWorkerLocked() { pernamespaceworker.go
568 > for _, cleanup := range w.cleanup {
569 cleanup()
570 }
571 > w.cleanup = nil pernamespaceworker.go
572 > if w.worker != nil {
573 w.worker.Stop()
574 w.worker = nil
575 }
576 > if w.client != nil { pernamespaceworker.go
577 w.client.Close()
578 w.client = nil
579 }
580 > w.componentSet = "" pernamespaceworker.go
581 }
582