session.go ×10

Frontier kind: Code frontier

unlabeled · c_92a88a881478

1404 tests · 2364 LOC · 114 files · introduces 0 tests · 69 LOC · 4 files

Introduces — evidence that enters the hierarchy at this concept

Code
22 ranges69 lines · 4 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
386 ranges2364 lines · 114 files · Browse complete extent
All tests (intent)
1404 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: 69 introduced LOC across 22 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/common/persistence/sql/sqlplugin/postgresql/plugin.go 22 introduced LOC · 5 ranges

Open complete file

58 logger log.Logger,
59 metricsHandler metrics.Handler,
60 > ) (sqlplugin.GenericDB, error) { plugin.go
61 > connect := func() (*sqlx.DB, error) {
62 > if cfg.Connect != nil {
63 return cfg.Connect(cfg)
64 }
65 > return p.createDBConnection(cfg, r) plugin.go
66 }
67 > needsRefresh := p.driver.IsConnNeedsRefreshError plugin.go
68 > handle := sqlplugin.NewDatabaseHandle(dbKind, connect, needsRefresh, logger, metricsHandler, clock.NewRealTimeSource())
69 > db := newDB(dbKind, cfg.DatabaseName, p.driver, handle, nil, logger)
70 > return db, nil
71 }
72
78 cfg *config.SQL,
79 resolver resolver.ServiceResolver,
80 > ) (*sqlx.DB, error) { plugin.go
81 > if cfg.DatabaseName != "" {
82 postgresqlSession, err := session.NewSession(cfg, p.driver, resolver)
83 if err != nil {
91 // (which captures the config pointer) sees the correct DatabaseName on
92 // reconnect
93 > cfgCopy := *cfg plugin.go
94 >
95 > var errors []error
96 > for _, databaseName := range defaultDatabaseNames {
97 > cfgCopy.DatabaseName = databaseName
98 > if postgresqlSession, err := session.NewSession(
99 > &cfgCopy,
100 > p.driver,
101 > resolver,
102 > ); err == nil {
103 > return postgresqlSession.DB, nil
104 > } else {
105 errors = append(errors, err)
106 }
go.temporal.io/server/common/persistence/sql/sqlplugin/postgresql/session/session.go 20 introduced LOC · 10 ranges

Open complete file

37 d driver.Driver,
38 resolver resolver.ServiceResolver,
39 > ) (*Session, error) { session.go
40 > db, err := createConnection(cfg, d, resolver)
41 > if err != nil {
42 return nil, err
43 }
44 > return &Session{DB: db}, nil session.go
45 }
46
55 d driver.Driver,
56 resolver resolver.ServiceResolver,
57 > ) (*sqlx.DB, error) { session.go
58 > var db *sqlx.DB
59 > var err error
60 >
61 > if cfg.PasswordCommand != nil {
62 db, err = d.CreateRefreshableConnection(func() (string, error) {
63 return buildDSN(cfg, resolver)
64 })
65 > } else { session.go
66 > var dsn string
67 > dsn, err = buildDSN(cfg, resolver)
68 > if err != nil {
69 return nil, err
70 }
71 > db, err = d.CreateConnection(dsn) session.go
72 }
73 > if err != nil { session.go
74 return nil, err
75 }
76 > if cfg.MaxConns > 0 { session.go
77 db.SetMaxOpenConns(cfg.MaxConns)
78 }
79 > if cfg.MaxIdleConns > 0 { session.go
80 db.SetMaxIdleConns(cfg.MaxIdleConns)
81 }
82 > if cfg.MaxConnLifetime > 0 { session.go
83 db.SetConnMaxLifetime(cfg.MaxConnLifetime)
84 }
85
86 // Maps struct names in CamelCase to snake without need for db struct tags.
87 > db.MapperFunc(strcase.ToSnake) session.go
88 > return db, nil
89 }
90
go.temporal.io/server/common/persistence/sql/sqlplugin/postgresql/db.go 16 introduced LOC · 2 ranges

Open complete file

51 tx *sqlx.Tx,
52 logger log.Logger,
53 > ) *db { db.go
54 > mdb := &db{
55 > dbKind: dbKind,
56 > dbName: dbName,
57 > dbDriver: dbDriver,
58 > handle: handle,
59 > tx: tx,
60 > logger: logger,
61 > }
62 > mdb.converter = &converter{}
63 > return mdb
64 > }
65
66 func (pdb *db) conn() sqlplugin.Conn {
86
87 // Close closes the connection to the mysql db
88 > func (pdb *db) Close() error { db.go
89 > pdb.handle.Close()
90 > return nil
91 > }
92
93 // PluginName returns the name of the mysql plugin
go.temporal.io/server/common/persistence/sql/sqlplugin/postgresql/admin.go 11 introduced LOC · 5 ranges

Open complete file

49
50 // Exec executes a sql statement
51 > func (pdb *db) Exec(stmt string, args ...any) error { admin.go
52 > db, err := pdb.handle.DB()
53 > if err != nil {
54 return err
55 }
56 > _, err = db.Exec(stmt, args...) admin.go
57 > return pdb.handle.ConvertError(err)
58 }
59
116
117 // CreateDatabase creates a database if it doesn't exist
118 > func (pdb *db) CreateDatabase(name string) error { admin.go
119 > if err := pdb.Exec(fmt.Sprintf(createDatabaseQuery, name)); err != nil {
120 if pdb.IsDupDatabaseError(err) {
121 return nil
124 }
125
126 > return nil admin.go
127 }
128
129 // DropDatabase drops a database
130 > func (pdb *db) DropDatabase(name string) error { admin.go
131 > return pdb.Exec(fmt.Sprintf(dropDatabaseQuery, name))
132 > }