context_impl.go ×7

Frontier kind: Code frontier

unlabeled · c_fae7930d5f35

38 tests · 3242 LOC · 145 files · introduces 0 tests · 35 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
7 ranges35 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
446 ranges3242 lines · 145 files · Browse complete extent
All tests (intent)
38 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: 35 introduced LOC across 7 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/service/history/shard/context_impl.go 35 introduced LOC · 7 ranges

Open complete file

1648 return nil
1649 }
1650 > case contextStateAcquiring: context_impl.go
1651 > switch request := request.(type) {
1652 case contextRequestAcquire:
1653 return nil // nothing to do, already acquiring
1784 }
1785
1786 > func (s *ContextImpl) loadShardMetadata(ownershipChanged *bool) error { context_impl.go
1787 > // Only have to do this once, we can just re-acquire the rangeid lock after that
1788 > s.rLock()
1789 > if s.shardInfo != nil {
1790 s.rUnlock()
1791 return nil
1920 }
1921
1922 > func (s *ContextImpl) acquireShard() { context_impl.go
1923 > // This is called in two contexts: initially acquiring the rangeid lock, and trying to
1924 > // re-acquire it after a persistence error. In both cases, we retry the acquire operation
1925 > // (renewRangeLocked) for 5 minutes. Each individual attempt uses shardIOTimeout (by default, 5s) as
1926 > // the timeout. This lets us handle a few minutes of persistence unavailability without
1927 > // dropping and reloading the whole shard context, which is relatively expensive (includes
1928 > // caches that would have to be refilled, etc.).
1929 > //
1930 > // We stop retrying on any of:
1931 > // 1. We succeed in acquiring the rangeid lock.
1932 > // 2. We get ShardOwnershipLostError or lifecycleCtx ended.
1933 > // 3. The state changes to Stopping or Stopped.
1934 > //
1935 > // If the shard controller sees that service resolver has assigned ownership to someone
1936 > // else, it will call FinishStop, which will trigger case 3 above, and also cancel
1937 > // lifecycleCtx. The persistence operations called here use lifecycleCtx as their context,
1938 > // so if we were blocked in any of them, they should return immediately with a context
1939 > // canceled error.
1940 > policy := s.acquireShardRetryPolicy
1941 > if policy == nil {
1942 policy = backoff.NewExponentialRetryPolicy(1 * time.Second).WithExpirationInterval(5 * time.Minute)
1943 }
1944
1945 // Remember this value across attempts
1946 > ownershipChanged := false context_impl.go
1947 >
1948 > op := func() error {
1949 > if !s.IsValid() {
1950 return s.newShardClosedErrorWithShardID()
1951 }
1952
1953 // Initial load of shard metadata
1954 > err := s.loadShardMetadata(&ownershipChanged) context_impl.go
1955 > if err != nil {
1956 return err
1957 }
2011
2012 // keep retrying except ShardOwnershipLostError or lifecycle context ended
2013 > acquireShardRetryable := func(err error) (isRetryable bool) { context_impl.go
2014 defer func() {
2015 s.contextTaggedLogger.Error(
2028 return true
2029 }
2030 > err := backoff.ThrottleRetry(op, policy, acquireShardRetryable) context_impl.go
2031 > if err != nil {
2032 // We got an non-retryable error, e.g. ShardOwnershipLostError
2033 s.contextTaggedLogger.Error("Couldn't acquire shard", tag.Error(err))