pernamespaceworker.go ×6

Frontier kind: Code frontier

unlabeled · c_645bd5495147

22 tests · 3194 LOC · 156 files · introduces 0 tests · 63 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
6 ranges63 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
512 ranges3194 lines · 156 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.

1 file ranked by introduced lines: 63 introduced LOC across 6 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/service/worker/pernamespaceworker.go 63 introduced LOC · 6 ranges

Open complete file

422 }
423 // ensure this changes if multiplicity changes
424 > fmt.Fprintf(&componentSet, "%d,", workerAllocation.local) pernamespaceworker.go
425 >
426 > // get sdk worker options
427 > fmt.Fprintf(&componentSet, "%+v,", w.opts)
428 >
429 > // we do need a worker, but maybe we have one already
430 > w.lock.Lock()
431 > defer w.lock.Unlock()
432 >
433 > if args.ns != w.ns {
434 // stale refresh goroutine, do nothing
435 return nil
436 }
437
438 > if componentSet.String() == w.componentSet { pernamespaceworker.go
439 // no change in set of components enabled, leave existing running
440 return nil
442
443 // ask rate limiter if we can start now
444 > if !w.reserved { pernamespaceworker.go
445 > w.reserved = true
446 > if delay := w.wm.startLimiter.Reserve().Delay(); delay > 0 {
447 return errRetryAfter(delay)
448 }
450
451 // set of components changed, need to recreate worker. first stop old one
452 > w.stopWorkerLocked() pernamespaceworker.go
453 >
454 > // create new one. note that even before startWorker returns, the worker may have started
455 > // and already called the fatal error handler. we need to set w.client+worker+componentSet
456 > // before releasing the lock to keep our state consistent.
457 > client, worker, err := w.startWorker(enabledComponents, workerAllocation)
458 > if err != nil {
459 // TODO: add metric also
460 w.stopWorkerLocked() // for calling cleanup
471 components []workercommon.PerNSWorkerComponent,
472 allocation workerAllocation,
473 > ) (sdkclient.Client, sdkworker.Worker, error) { pernamespaceworker.go
474 > nsName := w.ns.Name().String()
475 > // this should not block because it uses an existing grpc connection
476 > client := w.wm.sdkClientFactory.NewClient(sdkclient.Options{
477 > Namespace: nsName,
478 > DataConverter: sdk.PreferProtoDataConverter,
479 > })
480 >
481 > var sdkoptions sdkworker.Options
482 >
483 > // copy from dynamic config. apply explicit defaults for some instead of using the sdk
484 > // defaults so that we can multiply below.
485 > sdkoptions.MaxConcurrentActivityExecutionSize = cmp.Or(w.opts.MaxConcurrentActivityExecutionSize, 1000)
486 > sdkoptions.WorkerActivitiesPerSecond = w.opts.WorkerActivitiesPerSecond
487 > sdkoptions.MaxConcurrentLocalActivityExecutionSize = cmp.Or(w.opts.MaxConcurrentLocalActivityExecutionSize, 1000)
488 > sdkoptions.WorkerLocalActivitiesPerSecond = w.opts.WorkerLocalActivitiesPerSecond
489 > sdkoptions.MaxConcurrentActivityTaskPollers = max(cmp.Or(w.opts.MaxConcurrentActivityTaskPollers, 2), 2)
490 > sdkoptions.MaxConcurrentWorkflowTaskExecutionSize = cmp.Or(w.opts.MaxConcurrentWorkflowTaskExecutionSize, 1000)
491 > sdkoptions.MaxConcurrentWorkflowTaskPollers = max(cmp.Or(w.opts.MaxConcurrentWorkflowTaskPollers, 2), 2)
492 > sdkoptions.StickyScheduleToStartTimeout = w.opts.StickyScheduleToStartTimeout
493 >
494 > sdkoptions.BackgroundActivityContext = headers.SetCallerInfo(context.Background(), headers.NewBackgroundHighCallerInfo(nsName))
495 > sdkoptions.Identity = fmt.Sprintf("temporal-system@%s@%s", w.wm.hostName, nsName)
496 > // increase these if we're supposed to run with more allocation
497 > sdkoptions.MaxConcurrentWorkflowTaskPollers *= allocation.local
498 > sdkoptions.MaxConcurrentActivityTaskPollers *= allocation.local
499 > sdkoptions.MaxConcurrentLocalActivityExecutionSize *= allocation.local
500 > sdkoptions.MaxConcurrentWorkflowTaskExecutionSize *= allocation.local
501 > sdkoptions.MaxConcurrentActivityExecutionSize *= allocation.local
502 > sdkoptions.OnFatalError = w.onFatalError
503 >
504 > // this should not block because the client already has server capabilities
505 > worker := w.wm.sdkClientFactory.NewWorker(client, w.wm.taskQueueName, sdkoptions)
506 > details := workercommon.RegistrationDetails{
507 > TotalWorkers: allocation.total,
508 > Multiplicity: allocation.local,
509 > }
510 > for _, cmp := range components {
511 > cleanup := cmp.Register(worker, w.ns, details)
512 > if cleanup != nil {
513 w.cleanup = append(w.cleanup, cleanup)
514 }
516
517 // this blocks by calling DescribeNamespace a few times (with a 10s timeout)
518 > err := worker.Start() pernamespaceworker.go
519 > if err != nil {
520 client.Close()
521 return nil, nil, err