context_impl.go ×4

Frontier kind: Code frontier

unlabeled · c_eaf7c5ea52a0

703 tests · 3137 LOC · 142 files · introduces 0 tests · 55 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
4 ranges55 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
420 ranges3137 lines · 142 files · Browse complete extent
All tests (intent)
703 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: 55 introduced LOC across 4 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/service/history/shard/context_impl.go 55 introduced LOC · 4 ranges

Open complete file

1558 }
1559
1560 > func (s *ContextImpl) transition(request contextRequest) error { context_impl.go
1561 > /* State transitions:
1562 >
1563 > The normal pattern:
1564 > Initialized
1565 > controller calls start()
1566 > Acquiring
1567 > acquireShard gets the shard
1568 > Acquired
1569 >
1570 > If we get a transient error from persistence:
1571 > Acquired
1572 > transient error: handleErrorLocked calls transition(contextRequestLost)
1573 > Acquiring
1574 > acquireShard gets the shard
1575 > Acquired
1576 >
1577 > If we get shard ownership lost:
1578 > Acquired
1579 > ShardOwnershipLostError: handleErrorLocked calls transition(contextRequestStop)
1580 > Stopping
1581 > controller removes from map and calls FinishStop()
1582 > Stopped
1583 >
1584 > Stopping can be triggered internally (if we get a ShardOwnershipLostError, or fail to acquire the rangeid
1585 > lock after several minutes) or externally (from controller, e.g. controller shutting down or admin force-
1586 > unload shard). If it's triggered internally, we transition to Stopping, then make an asynchronous callback
1587 > to controller, which will remove us from the map and call FinishStop(), which will transition to Stopped and
1588 > stop the engine. If it's triggered externally, we'll skip over Stopping and go straight to Stopped.
1589 >
1590 > If we transition externally to Stopped, and the acquireShard goroutine is still running, we can't kill it,
1591 > but we should make sure that it can't do anything: the context it uses for persistence ops will be
1592 > canceled, and if it tries to transition states, it will fail.
1593 >
1594 > Invariants:
1595 > - Once state is Stopping, it can only go to Stopped.
1596 > - Once state is Stopped, it can't go anywhere else.
1597 > - At the start of acquireShard, state must be Acquiring.
1598 > - By the end of acquireShard, state must not be Acquiring: either acquireShard set it to Acquired, or the
1599 > controller set it to Stopped.
1600 > - If state is Acquiring, acquireShard should be running in the background.
1601 > - Only acquireShard can use contextRequestAcquired (i.e. transition from Acquiring to Acquired).
1602 > - Once state has reached Acquired at least once, and not reached Stopped, engineFuture must be set.
1603 > - Only the controller may call start() and FinishStop().
1604 > - The controller must call FinishStop() for every ContextImpl it creates.
1605 >
1606 > */
1607 >
1608 > s.stateLock.Lock()
1609 > defer s.stateLock.Unlock()
1610 >
1611 > setStateAcquiring := func() {
1612 s.state = contextStateAcquiring
1613 s.contextTaggedLogger.Info("", tag.LifeCycleStarted, tag.ComponentShardContext)
1615 }
1616
1617 > setStateStopping := func(request contextRequestStop) { context_impl.go
1618 s.state = contextStateStopping
1619 s.stopReason = request.reason
1627 }
1628
1629 > setStateStopped := func() { context_impl.go
1630 s.state = contextStateStopped
1631 s.contextTaggedLogger.Info("", tag.LifeCycleStopped, tag.ComponentShardContext)
1635 }
1636
1637 > switch s.state { context_impl.go
1638 case contextStateInitialized:
1639 switch request := request.(type) {