sqldb: wire up BusyTimeout config for SQLite store
The SqliteConfig.BusyTimeout field existed but was never used — the busy_timeout pragma was hardcoded to 5000ms. Add a busyTimeoutMs() helper that returns the configured value or falls back to the 5000ms default, and use it when constructing the SQLite DSN.
This commit is contained in:
2 files changed
+17
-1
No files matched your search
@@ -31,6 +31,22 @@ type SqliteConfig struct {
|
||||
QueryConfig `group:"query" namespace:"query"`
|
||||
}
|
||||
|
||||
const (
|
||||
// defaultBusyTimeoutMs is the default busy_timeout value in
|
||||
// milliseconds, used when no BusyTimeout is configured.
|
||||
defaultBusyTimeoutMs = 5000
|
||||
)
|
||||
|
||||
// busyTimeoutMs returns the busy_timeout value in milliseconds. If
|
||||
// BusyTimeout is not set, it returns the default value.
|
||||
func (s *SqliteConfig) busyTimeoutMs() int64 {
|
||||
if s.BusyTimeout > 0 {
|
||||
return s.BusyTimeout.Milliseconds()
|
||||
}
|
||||
|
||||
return defaultBusyTimeoutMs
|
||||
}
|
||||
|
||||
// Validate checks that the SqliteConfig values are valid.
|
||||
func (p *SqliteConfig) Validate() error {
|
||||
if err := p.QueryConfig.Validate(true); err != nil {
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ func NewSqliteStore(cfg *SqliteConfig, dbPath string) (*SqliteStore, error) {
|
||||
},
|
||||
{
|
||||
name: "busy_timeout",
|
||||
value: "5000",
|
||||
value: fmt.Sprintf("%d", cfg.busyTimeoutMs()),
|
||||
},
|
||||
{
|
||||
// With the WAL mode, this ensures that we also do an
|
||||
|
||||
Reference in new issue
Block a user