controller_impl.go ×11

Frontier kind: Code frontier

unlabeled · c_152b18185570

2 tests · 5176 LOC · 188 files · introduces 0 tests · 40 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
11 ranges40 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
901 ranges5176 lines · 188 files · Browse complete extent
All tests (intent)
2 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: 40 introduced LOC across 11 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/service/history/shard/controller_impl.go 40 introduced LOC · 11 ranges

Open complete file

306 // history instance can continue to process requests for the shard until the
307 // new owner actually acquires the shard.
308 > func (c *ControllerImpl) shardLingerThenClose(ctx context.Context, shardID int32) { controller_impl.go
309 > c.RLock()
310 > shard, ok := c.historyShards[shardID]
311 > c.RUnlock()
312 > if !ok {
313 return
314 }
319 // could be lingering on a shard that this instance should own, but this
320 // instance's acquireShards concurrency slots are filled with lingering shards.
321 > if !c.beginLinger(shard) { controller_impl.go
322 return
323 }
324
325 > go func() { controller_impl.go
326 > defer c.endLinger(shard)
327 > c.doLinger(ctx, shard)
328 > }()
329 }
330
331 > func (c *ControllerImpl) beginLinger(shard historyi.ControllableContext) bool { controller_impl.go
332 > c.lingerState.Lock()
333 > defer c.lingerState.Unlock()
334 > if _, ok := c.lingerState.shards[shard]; ok {
335 return false
336 }
337 > c.lingerState.shards[shard] = struct{}{} controller_impl.go
338 > return true
339 }
340
341 > func (c *ControllerImpl) endLinger(shard historyi.ControllableContext) { controller_impl.go
342 > c.lingerState.Lock()
343 > defer c.lingerState.Unlock()
344 > delete(c.lingerState.shards, shard)
345 > }
346
347 > func (c *ControllerImpl) doLinger(ctx context.Context, shard historyi.ControllableContext) { controller_impl.go
348 > startTime := time.Now()
349 > // Enforce a max limit to ensure we close the shard in a reasonable time,
350 > // and to indirectly limit the number of lingering shards.
351 > timeLimit := min(c.config.ShardLingerTimeLimit(), shardLingerMaxTimeLimit)
352 > ctx, cancel := context.WithTimeout(ctx, timeLimit)
353 > defer cancel()
354 >
355 > qps := c.config.ShardLingerOwnershipCheckQPS()
356 > // The limiter must be configured with burst>=1. With burst=1,
357 > // the first call to Wait() won't be delayed.
358 > limiter := rate.NewLimiter(rate.Limit(qps), 1)
359 >
360 > for {
361 > if !shard.IsValid() {
362 metrics.ShardLingerSuccess.With(c.taggedMetricsHandler).Record(time.Since(startTime))
363 break
364 }
365
366 > if err := limiter.Wait(ctx); err != nil { controller_impl.go
367 c.contextTaggedLogger.Info("shardLinger: wait timed out",
368 tag.ShardID(shard.GetShardID()),
375 // If this AssertOwnership or any other request on the shard receives
376 // a shard ownership lost error, the shard will be marked as invalid.
377 > _ = shard.AssertOwnership(ctx) controller_impl.go
378 }
379
380 > c.shardRemoveAndStop(shard) controller_impl.go
381 }
382
413 // current host is not owner of shard, unload it if it is already loaded.
414 if c.config.ShardLingerTimeLimit() > 0 {
415 > c.shardLingerThenClose(ctx, shardID) controller_impl.go
416 } else {
417 c.CloseShardByID(shardID)