Skip to content

Commit 996a50d

Browse files
authored
Add busy-timeout-interval setting (#620)
1 parent 2f22a4b commit 996a50d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

cmd/litestream/main.go

+4
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ type DBConfig struct {
287287
MetaPath *string `yaml:"meta-path"`
288288
MonitorInterval *time.Duration `yaml:"monitor-interval"`
289289
CheckpointInterval *time.Duration `yaml:"checkpoint-interval"`
290+
BusyTimeout *time.Duration `yaml:"busy-timeout"`
290291
MinCheckpointPageN *int `yaml:"min-checkpoint-page-count"`
291292
MaxCheckpointPageN *int `yaml:"max-checkpoint-page-count"`
292293

@@ -313,6 +314,9 @@ func NewDBFromConfig(dbc *DBConfig) (*litestream.DB, error) {
313314
if dbc.CheckpointInterval != nil {
314315
db.CheckpointInterval = *dbc.CheckpointInterval
315316
}
317+
if dbc.BusyTimeout != nil {
318+
db.BusyTimeout = *dbc.BusyTimeout
319+
}
316320
if dbc.MinCheckpointPageN != nil {
317321
db.MinCheckpointPageN = *dbc.MinCheckpointPageN
318322
}

db.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
const (
2929
DefaultMonitorInterval = 1 * time.Second
3030
DefaultCheckpointInterval = 1 * time.Minute
31+
DefaultBusyTimeout = 1 * time.Second
3132
DefaultMinCheckpointPageN = 1000
3233
DefaultMaxCheckpointPageN = 10000
3334
DefaultTruncatePageN = 500000
@@ -37,9 +38,6 @@ const (
3738
// If this index is reached then a new generation will be started.
3839
const MaxIndex = 0x7FFFFFFF
3940

40-
// BusyTimeout is the timeout to wait for EBUSY from SQLite.
41-
const BusyTimeout = 1 * time.Second
42-
4341
// DB represents a managed instance of a SQLite database in the file system.
4442
type DB struct {
4543
mu sync.RWMutex
@@ -103,6 +101,9 @@ type DB struct {
103101
// Frequency at which to perform db sync.
104102
MonitorInterval time.Duration
105103

104+
// The timeout to wait for EBUSY from SQLite.
105+
BusyTimeout time.Duration
106+
106107
// List of replicas for the database.
107108
// Must be set before calling Open().
108109
Replicas []*Replica
@@ -125,6 +126,7 @@ func NewDB(path string) *DB {
125126
TruncatePageN: DefaultTruncatePageN,
126127
CheckpointInterval: DefaultCheckpointInterval,
127128
MonitorInterval: DefaultMonitorInterval,
129+
BusyTimeout: DefaultBusyTimeout,
128130
Logger: slog.With("db", path),
129131
}
130132

@@ -411,7 +413,7 @@ func (db *DB) init() (err error) {
411413
db.dirInfo = fi
412414

413415
dsn := db.path
414-
dsn += fmt.Sprintf("?_busy_timeout=%d", BusyTimeout.Milliseconds())
416+
dsn += fmt.Sprintf("?_busy_timeout=%d", db.BusyTimeout.Milliseconds())
415417

416418
// Connect to SQLite database. Use the driver registered with a hook to
417419
// prevent WAL files from being removed.

0 commit comments

Comments
 (0)