session.go ×11

Frontier kind: Code frontier

unlabeled · c_09dc86b8cb08

470 tests · 2377 LOC · 114 files · introduces 0 tests · 66 LOC · 4 files

Introduces — evidence that enters the hierarchy at this concept

Code
23 ranges66 lines · 4 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
392 ranges2377 lines · 114 files · Browse complete extent
All tests (intent)
470 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: 66 introduced LOC across 23 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/common/persistence/sql/sqlplugin/mysql/session/session.go 24 introduced LOC · 11 ranges

Open complete file

49 cfg *config.SQL,
50 resolver resolver.ServiceResolver,
51 > ) (*Session, error) { session.go
52 > db, err := createConnection(dbKind, cfg, resolver)
53 > if err != nil {
54 return nil, err
55 }
56 > return &Session{DB: db}, nil session.go
57 }
58
67 cfg *config.SQL,
68 resolver resolver.ServiceResolver,
69 > ) (*sqlx.DB, error) { session.go
70 > err := registerTLSConfig(cfg)
71 > if err != nil {
72 return nil, err
73 }
74
75 > var db *sqlx.DB session.go
76 > if cfg.PasswordCommand != nil {
77 c := sqlplugin.NewRefreshingConnector(
78 func() (string, error) {
89 return nil, err
90 }
91 > } else { session.go
92 > var dsn string
93 > dsn, err = buildDSN(dbKind, cfg, resolver)
94 > if err != nil {
95 return nil, err
96 }
97 > db, err = sqlx.Connect(driverName, dsn) session.go
98 > if err != nil {
99 return nil, err
100 }
101 }
102 > if cfg.MaxConns > 0 { session.go
103 db.SetMaxOpenConns(cfg.MaxConns)
104 }
105 > if cfg.MaxIdleConns > 0 { session.go
106 db.SetMaxIdleConns(cfg.MaxIdleConns)
107 }
108 > if cfg.MaxConnLifetime > 0 { session.go
109 db.SetConnMaxLifetime(cfg.MaxConnLifetime)
110 }
111
112 // Maps struct names in CamelCase to snake without need for db struct tags.
113 > db.MapperFunc(strcase.ToSnake) session.go
114 > return db, nil
115 }
116
202 }
203
204 > func registerTLSConfig(cfg *config.SQL) error { session.go
205 > if cfg.TLS == nil || !cfg.TLS.Enabled {
206 > return nil
207 > }
208
209 // TODO: create a way to set MinVersion and CipherSuites via cfg.
go.temporal.io/server/common/persistence/sql/sqlplugin/mysql/db.go 20 introduced LOC · 3 ranges

Open complete file

43 var _ sqlplugin.Tx = (*db)(nil)
44
45 > func isConnNeedsRefreshError(err error) bool { db.go
46 > myErr, ok := err.(*mysql.MySQLError)
47 > if !ok {
48 > return false
49 > }
50 return myErr.Number == readOnlyModeCode || myErr.Number == readOnlyTransactionCode || myErr.Number == tooManyConnectionsCode
51 }
64 tx *sqlx.Tx,
65 logger log.Logger,
66 > ) *db { db.go
67 > mdb := &db{
68 > dbKind: dbKind,
69 > dbName: dbName,
70 > handle: handle,
71 > tx: tx,
72 > logger: logger,
73 > }
74 > mdb.converter = &converter{}
75 > return mdb
76 > }
77
78 func (mdb *db) conn() sqlplugin.Conn {
107
108 // Close closes the connection to the mysql db
109 > func (mdb *db) Close() error { db.go
110 > mdb.handle.Close()
111 > return nil
112 > }
113
114 // PluginName returns the name of the mysql plugin
go.temporal.io/server/common/persistence/sql/sqlplugin/mysql/admin.go 11 introduced LOC · 4 ranges

Open complete file

75
76 // Exec executes a sql statement
77 > func (mdb *db) Exec(stmt string, args ...any) error { admin.go
78 > db, err := mdb.handle.DB()
79 > if err != nil {
80 return err
81 }
82 > _, err = db.Exec(stmt, args...) admin.go
83 > return mdb.handle.ConvertError(err)
84 }
85
115
116 // CreateDatabase creates a database if it doesn't exist
117 > func (mdb *db) CreateDatabase(name string) error { admin.go
118 > return mdb.Exec(fmt.Sprintf(createDatabaseQuery, name))
119 > }
120
121 // DropDatabase drops a database
122 > func (mdb *db) DropDatabase(name string) error { admin.go
123 > return mdb.Exec(fmt.Sprintf(dropDatabaseQuery, name))
124 > }
go.temporal.io/server/common/persistence/sql/sqlplugin/mysql/plugin.go 11 introduced LOC · 5 ranges

Open complete file

41 logger log.Logger,
42 metricsHandler metrics.Handler,
43 > ) (sqlplugin.GenericDB, error) { plugin.go
44 > connect := func() (*sqlx.DB, error) {
45 > if cfg.Connect != nil {
46 return cfg.Connect(cfg)
47 }
48 > return p.createDBConnection(dbKind, cfg, r) plugin.go
49 }
50 > handle := sqlplugin.NewDatabaseHandle(dbKind, connect, isConnNeedsRefreshError, logger, metricsHandler, clock.NewRealTimeSource()) plugin.go
51 > db := newDB(dbKind, cfg.DatabaseName, handle, nil, logger)
52 > return db, nil
53 }
54
61 cfg *config.SQL,
62 resolver resolver.ServiceResolver,
63 > ) (*sqlx.DB, error) { plugin.go
64 > mysqlSession, err := session.NewSession(dbKind, cfg, resolver)
65 > if err != nil {
66 return nil, err
67 }
68 > return mysqlSession.DB, nil plugin.go
69 }