Skip to content

Commit

Permalink
Add busy-timeout-interval setting (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkgnotic authored Dec 10, 2024
1 parent 2f22a4b commit 996a50d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions cmd/litestream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ type DBConfig struct {
MetaPath *string `yaml:"meta-path"`
MonitorInterval *time.Duration `yaml:"monitor-interval"`
CheckpointInterval *time.Duration `yaml:"checkpoint-interval"`
BusyTimeout *time.Duration `yaml:"busy-timeout"`
MinCheckpointPageN *int `yaml:"min-checkpoint-page-count"`
MaxCheckpointPageN *int `yaml:"max-checkpoint-page-count"`

Expand All @@ -313,6 +314,9 @@ func NewDBFromConfig(dbc *DBConfig) (*litestream.DB, error) {
if dbc.CheckpointInterval != nil {
db.CheckpointInterval = *dbc.CheckpointInterval
}
if dbc.BusyTimeout != nil {
db.BusyTimeout = *dbc.BusyTimeout
}
if dbc.MinCheckpointPageN != nil {
db.MinCheckpointPageN = *dbc.MinCheckpointPageN
}
Expand Down
10 changes: 6 additions & 4 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
const (
DefaultMonitorInterval = 1 * time.Second
DefaultCheckpointInterval = 1 * time.Minute
DefaultBusyTimeout = 1 * time.Second
DefaultMinCheckpointPageN = 1000
DefaultMaxCheckpointPageN = 10000
DefaultTruncatePageN = 500000
Expand All @@ -37,9 +38,6 @@ const (
// If this index is reached then a new generation will be started.
const MaxIndex = 0x7FFFFFFF

// BusyTimeout is the timeout to wait for EBUSY from SQLite.
const BusyTimeout = 1 * time.Second

// DB represents a managed instance of a SQLite database in the file system.
type DB struct {
mu sync.RWMutex
Expand Down Expand Up @@ -103,6 +101,9 @@ type DB struct {
// Frequency at which to perform db sync.
MonitorInterval time.Duration

// The timeout to wait for EBUSY from SQLite.
BusyTimeout time.Duration

// List of replicas for the database.
// Must be set before calling Open().
Replicas []*Replica
Expand All @@ -125,6 +126,7 @@ func NewDB(path string) *DB {
TruncatePageN: DefaultTruncatePageN,
CheckpointInterval: DefaultCheckpointInterval,
MonitorInterval: DefaultMonitorInterval,
BusyTimeout: DefaultBusyTimeout,
Logger: slog.With("db", path),
}

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

dsn := db.path
dsn += fmt.Sprintf("?_busy_timeout=%d", BusyTimeout.Milliseconds())
dsn += fmt.Sprintf("?_busy_timeout=%d", db.BusyTimeout.Milliseconds())

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

0 comments on commit 996a50d

Please sign in to comment.