plugin.go ×17

Frontier kind: Code frontier

unlabeled · c_3e0700106d8e

856 tests · 3023 LOC · 148 files · introduces 0 tests · 74 LOC · 4 files

Introduces — evidence that enters the hierarchy at this concept

Code
25 ranges74 lines · 4 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
468 ranges3023 lines · 148 files · Browse complete extent
All tests (intent)
856 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: 74 introduced LOC across 25 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/common/persistence/sql/sqlplugin/sqlite/plugin.go 47 introduced LOC · 17 ranges

Open complete file

61 logger log.Logger,
62 _ metrics.Handler,
63 > ) (sqlplugin.GenericDB, error) { plugin.go
64 > conn, err := p.connPool.Allocate(cfg, r, logger, p.createDBConnection)
65 > if err != nil {
66 return nil, err
67 }
68 > db := newDB(dbKind, cfg.DatabaseName, conn, nil, logger) plugin.go
69 > db.OnClose(func() { p.connPool.Close(cfg) }) // remove reference
70 > return db, nil
71 }
72
79 _ resolver.ServiceResolver,
80 logger log.Logger,
81 > ) (*sqlx.DB, error) { plugin.go
82 > dsn, err := buildDSN(cfg)
83 > if err != nil {
84 return nil, fmt.Errorf("error building DSN: %w", err)
85 }
86
87 > db, err := sqlx.Connect(goSQLDriverName, dsn) plugin.go
88 > if err != nil {
89 return nil, err
90 }
102 // respect the user's config values when set, otherwise default to 1 for
103 // backward compatibility and safety.
104 > walEnabled := strings.EqualFold(cfg.ConnectAttributes["journal_mode"], "wal") plugin.go
105 > if cfg.MaxConns > 0 {
106 if cfg.MaxConns > 1 && !walEnabled {
107 logger.Warn(
115 db.SetMaxOpenConns(1)
116 }
117 > if cfg.MaxIdleConns > 0 { plugin.go
118 db.SetMaxIdleConns(cfg.MaxIdleConns)
119 > } else { plugin.go
120 db.SetMaxIdleConns(1)
121 }
122 > if cfg.MaxConnLifetime > 0 { plugin.go
123 db.SetConnMaxLifetime(cfg.MaxConnLifetime)
124 }
126 // closes. Set ConnMaxIdleTime to 0 (infinite) to prevent idle connections
127 // from being reaped, which would destroy the database.
128 > if cfg.ConnectAttributes["mode"] == "memory" { plugin.go
129 db.SetConnMaxIdleTime(0)
130 }
131
132 // Maps struct names in CamelCase to snake without need for db struct tags.
133 > db.MapperFunc(strcase.ToSnake) plugin.go
134 >
135 > switch {
136 case cfg.ConnectAttributes["mode"] == "memory":
137 // creates temporary DB overlay in order to configure database and schemas
147 }
148
149 > return db, nil plugin.go
150 }
151
163 }
164
165 > func buildDSN(cfg *config.SQL) (string, error) { plugin.go
166 > if cfg.ConnectAttributes == nil {
167 cfg.ConnectAttributes = make(map[string]string)
168 }
169 > vals, err := buildDSNAttr(cfg) plugin.go
170 > if err != nil {
171 return "", err
172 }
173 > dsn := fmt.Sprintf( plugin.go
174 > "file:%s?%v",
175 > cfg.DatabaseName,
176 > vals.Encode(),
177 > )
178 > return dsn, nil
179 }
180
181 > func buildDSNAttr(cfg *config.SQL) (url.Values, error) { plugin.go
182 > parameters := url.Values{}
183 >
184 > // sort ConnectAttributes to get a deterministic order
185 > keys := expmaps.Keys(cfg.ConnectAttributes)
186 > sort.Strings(keys)
187 >
188 > for _, k := range keys {
189 > key := strings.TrimSpace(k)
190 > value := strings.TrimSpace(cfg.ConnectAttributes[k])
191 > if parameters.Get(key) != "" {
192 return nil, fmt.Errorf("duplicate connection attr: %v:%v, %v:%v",
193 key,
197 }
198
199 > if _, isValidQueryParameter := queryParameters[key]; isValidQueryParameter { plugin.go
200 > parameters.Set(key, value)
201 > continue
202 }
203
206 }
207 // set time format
208 > parameters.Add("_time_format", "sqlite") plugin.go
209 > return parameters, nil
210 }
go.temporal.io/server/common/persistence/sql/sqlplugin/sqlite/conn_pool.go 12 introduced LOC · 4 ranges

Open complete file

36 logger log.Logger,
37 create func(*config.SQL, resolver.ServiceResolver, log.Logger) (*sqlx.DB, error),
38 > ) (db *sqlx.DB, err error) { conn_pool.go
39 > cp.mu.Lock()
40 > defer cp.mu.Unlock()
41 >
42 > dsn, err := buildDSN(cfg)
43 > if err != nil {
44 return nil, err
45 }
46
47 > if entry, ok := cp.pool[dsn]; ok { conn_pool.go
48 entry.refCount++
49 return entry.db, nil
50 }
51
52 > db, err = create(cfg, resolver, logger) conn_pool.go
53 > if err != nil {
54 return nil, err
55 }
56
57 > cp.pool[dsn] = entry{db: db, refCount: 1} conn_pool.go
58 >
59 > return db, nil
60 }
61
go.temporal.io/server/common/persistence/sql/sqlplugin/sqlite/db.go 11 introduced LOC · 3 ranges

Open complete file

75 }
76
77 > func (mdb *db) OnClose(hook func()) { db.go
78 > mdb.mu.Lock()
79 > mdb.onClose = append(mdb.onClose, hook)
80 > mdb.mu.Unlock()
81 > }
82
83 // Close closes the connection to the sqlite db
84 > func (mdb *db) Close() error { db.go
85 > mdb.mu.RLock()
86 > defer mdb.mu.RUnlock()
87 >
88 > for _, hook := range mdb.onClose {
89 // de-registers the database from conn pool
90 hook()
92
93 // database connection will be automatically closed by the hook handler when all references are removed
94 > return nil db.go
95 }
96
go.temporal.io/server/common/persistence/sql/sqlplugin/sqlite/admin.go 4 introduced LOC · 1 range

Open complete file

95
96 // CreateDatabase creates a database if it doesn't exist
97 > func (mdb *db) CreateDatabase(name string) error { admin.go
98 > // SQLite does not need to create database
99 > return nil
100 > }
101
102 // DropDatabase drops a database