Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add busy-timeout-interval setting #620

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading