Expose additional DB configuration settings
This commit exposes the monitor interval, checkpoint interval, minimum checkpoint page count, and maximum checkpoint page count via the YAML configuration file.
This commit is contained in:
@@ -208,7 +208,12 @@ func ReadConfigFile(filename string) (_ Config, err error) {
|
|||||||
|
|
||||||
// DBConfig represents the configuration for a single database.
|
// DBConfig represents the configuration for a single database.
|
||||||
type DBConfig struct {
|
type DBConfig struct {
|
||||||
Path string `yaml:"path"`
|
Path string `yaml:"path"`
|
||||||
|
MonitorInterval *time.Duration `yaml:"monitor-interval"`
|
||||||
|
CheckpointInterval *time.Duration `yaml:"checkpoint-interval"`
|
||||||
|
MinCheckpointPageN *int `yaml:"min-checkpoint-page-count"`
|
||||||
|
MaxCheckpointPageN *int `yaml:"max-checkpoint-page-count"`
|
||||||
|
|
||||||
Replicas []*ReplicaConfig `yaml:"replicas"`
|
Replicas []*ReplicaConfig `yaml:"replicas"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,6 +227,20 @@ func NewDBFromConfig(dbc *DBConfig) (*litestream.DB, error) {
|
|||||||
// Initialize database with given path.
|
// Initialize database with given path.
|
||||||
db := litestream.NewDB(path)
|
db := litestream.NewDB(path)
|
||||||
|
|
||||||
|
// Override default database settings if specified in configuration.
|
||||||
|
if dbc.MonitorInterval != nil {
|
||||||
|
db.MonitorInterval = *dbc.MonitorInterval
|
||||||
|
}
|
||||||
|
if dbc.CheckpointInterval != nil {
|
||||||
|
db.CheckpointInterval = *dbc.CheckpointInterval
|
||||||
|
}
|
||||||
|
if dbc.MinCheckpointPageN != nil {
|
||||||
|
db.MinCheckpointPageN = *dbc.MinCheckpointPageN
|
||||||
|
}
|
||||||
|
if dbc.MaxCheckpointPageN != nil {
|
||||||
|
db.MaxCheckpointPageN = *dbc.MaxCheckpointPageN
|
||||||
|
}
|
||||||
|
|
||||||
// Instantiate and attach replicas.
|
// Instantiate and attach replicas.
|
||||||
for _, rc := range dbc.Replicas {
|
for _, rc := range dbc.Replicas {
|
||||||
r, err := NewReplicaFromConfig(rc, db)
|
r, err := NewReplicaFromConfig(rc, db)
|
||||||
|
|||||||
5
db.go
5
db.go
@@ -260,6 +260,11 @@ func (db *DB) PageSize() int {
|
|||||||
|
|
||||||
// Open initializes the background monitoring goroutine.
|
// Open initializes the background monitoring goroutine.
|
||||||
func (db *DB) Open() (err error) {
|
func (db *DB) Open() (err error) {
|
||||||
|
// Validate fields on database.
|
||||||
|
if db.MinCheckpointPageN <= 0 {
|
||||||
|
return fmt.Errorf("minimum checkpoint page count required")
|
||||||
|
}
|
||||||
|
|
||||||
// Validate that all replica names are unique.
|
// Validate that all replica names are unique.
|
||||||
m := make(map[string]struct{})
|
m := make(map[string]struct{})
|
||||||
for _, r := range db.Replicas {
|
for _, r := range db.Replicas {
|
||||||
|
|||||||
Reference in New Issue
Block a user