db_handle.go ×5

Frontier kind: Code frontier

unlabeled · c_6d8dbc8a0eeb

1880 tests · 1884 LOC · 82 files · introduces 0 tests · 58 LOC · 4 files

Introduces — evidence that enters the hierarchy at this concept

Code
11 ranges58 lines · 4 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
262 ranges1884 lines · 82 files · Browse complete extent
All tests (intent)
1880 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.

4 files ranked by introduced lines: 58 introduced LOC across 11 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/common/persistence/sql/sqlplugin/db_handle.go 30 introduced LOC · 5 ranges

Open complete file

54 metricsHandler metrics.Handler,
55 timeSource clock.TimeSource,
56 > ) *DatabaseHandle { db_handle.go
57 > handle := &DatabaseHandle{
58 > running: true,
59 > connect: connect,
60 > needsRefresh: needsRefresh,
61 > metrics: metricsHandler,
62 > logger: logger,
63 > timeSource: timeSource,
64 > }
65 > handle.reporter = newDBMetricReporter(dbKind, handle)
66 > handle.reporter.Start()
67 > handle.reconnect(true)
68 > return handle
69 > }
70
71 // Close and reopen the underlying database connection
72 > func (h *DatabaseHandle) reconnect(force bool) *sqlx.DB { db_handle.go
73 > h.Lock()
74 > defer h.Unlock()
75 >
76 > // Don't reconnect if we've been closed
77 > if !h.running {
78 return nil
79 }
80
81 > prevConn := h.db.Load() db_handle.go
82 > if prevConn != nil {
83 if !force {
84 // Another goroutine already reconnected
92 }
93
94 > metrics.PersistenceSessionRefreshAttempts.With(h.metrics).Record(1) db_handle.go
95 >
96 > now := h.timeSource.Now()
97 > lastRefresh := h.lastRefresh
98 > if now.Sub(lastRefresh) < sessionRefreshMinInternal {
99 h.logger.Warn("sql handle: did not refresh database connection pool because the last refresh was too close",
100 tag.Duration("min_refresh_interval_seconds", sessionRefreshMinInternal))
104 }
105
106 > h.lastRefresh = now db_handle.go
107 > newConn, err := h.connect()
108 > if err != nil {
109 h.logger.Error("sql handle: unable to refresh database connection pool", tag.Error(err))
110 handler := h.metrics.WithTags(metrics.FailureTag("error"))
go.temporal.io/server/common/persistence/sql/sqlplugin/db_metrics.go 23 introduced LOC · 4 ranges

Open complete file

23 }
24
25 > func newDBMetricReporter(dbKind DbKind, handle *DatabaseHandle) *DBMetricsReporter { db_metrics.go
26 > reporter := &DBMetricsReporter{
27 > interval: time.Minute,
28 > handle: handle,
29 > metrics: handle.metrics.WithTags(metrics.PersistenceDBKindTag(dbKind.String())),
30 > quit: make(chan struct{}),
31 > logger: handle.logger,
32 > }
33 > reporter.started.Store(false)
34 > reporter.stopped.Store(false)
35 > return reporter
36 > }
37
38 // Start run metrics report in background
39 // yield control immediately without blocking
40 // safe to called multiple time
41 > func (r *DBMetricsReporter) Start() { db_metrics.go
42 > if !r.started.CompareAndSwap(false, true) {
43 return
44 }
45 > r.wg.Add(1) db_metrics.go
46 > go r.run()
47 }
48
49 > func (r *DBMetricsReporter) run() { db_metrics.go
50 > defer r.wg.Done()
51 > ticker := time.NewTicker(r.interval)
52 > defer ticker.Stop()
53 >
54 > for {
55 > select {
56 case <-r.quit:
57 return
go.temporal.io/server/common/metrics/tags.go 3 introduced LOC · 1 range

Open complete file

599 }
600
601 > func PersistenceDBKindTag(kind string) Tag { tags.go
602 > return Tag{Key: PersistenceDBKindTagName, Value: kind}
603 > }
604
605 func HeaderCallsiteTag(kind string) Tag {
go.temporal.io/server/common/persistence/sql/sqlplugin/interfaces.go 2 introduced LOC · 1 range

Open complete file

142 case DbKindVisibility:
143 return "visibility"
144 > default: interfaces.go
145 > return "unknown"
146 }
147 }