add WAL support for sqlite (#1752)
This commit is contained in:
parent
87239c62c1
commit
9b3ff82542
|
@ -22,6 +22,7 @@ type DatabaseCfg struct {
|
||||||
Flush *FlushDBCfg `yaml:"flush"`
|
Flush *FlushDBCfg `yaml:"flush"`
|
||||||
LogLevel *log.Level `yaml:"log_level"`
|
LogLevel *log.Level `yaml:"log_level"`
|
||||||
MaxOpenConns *int `yaml:"max_open_conns,omitempty"`
|
MaxOpenConns *int `yaml:"max_open_conns,omitempty"`
|
||||||
|
UseWal *bool `yaml:"use_wal,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuthGCCfg struct {
|
type AuthGCCfg struct {
|
||||||
|
|
|
@ -76,7 +76,16 @@ func NewClient(config *csconfig.DatabaseCfg) (*Client, error) {
|
||||||
return &Client{}, fmt.Errorf("unable to set perms on %s: %v", config.DbPath, err)
|
return &Client{}, fmt.Errorf("unable to set perms on %s: %v", config.DbPath, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drv, err := getEntDriver("sqlite3", dialect.SQLite, fmt.Sprintf("file:%s?_busy_timeout=100000&_fk=1", config.DbPath), config)
|
if config.UseWal == nil {
|
||||||
|
entLogger.Warn("you are using sqlite without WAL, this can have an impact of performance. If you do not store the database in a network share, set db_config.use_wal to true. Set explicitly to false to disable this warning.")
|
||||||
|
}
|
||||||
|
var sqliteConnectionStringParameters string
|
||||||
|
if config.UseWal != nil && *config.UseWal {
|
||||||
|
sqliteConnectionStringParameters = "_busy_timeout=100000&_fk=1&_journal_mode=WAL"
|
||||||
|
} else {
|
||||||
|
sqliteConnectionStringParameters = "_busy_timeout=100000&_fk=1"
|
||||||
|
}
|
||||||
|
drv, err := getEntDriver("sqlite3", dialect.SQLite, fmt.Sprintf("file:%s?%s", config.DbPath, sqliteConnectionStringParameters), config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &Client{}, errors.Wrapf(err, "failed opening connection to sqlite: %v", config.DbPath)
|
return &Client{}, errors.Wrapf(err, "failed opening connection to sqlite: %v", config.DbPath)
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,7 @@ config_generate() {
|
||||||
.config_paths.plugin_dir=strenv(PLUGIN_DIR) |
|
.config_paths.plugin_dir=strenv(PLUGIN_DIR) |
|
||||||
.crowdsec_service.acquisition_path=strenv(CONFIG_DIR)+"/acquis.yaml" |
|
.crowdsec_service.acquisition_path=strenv(CONFIG_DIR)+"/acquis.yaml" |
|
||||||
.db_config.db_path=strenv(DATA_DIR)+"/crowdsec.db" |
|
.db_config.db_path=strenv(DATA_DIR)+"/crowdsec.db" |
|
||||||
|
.db_config.use_wal=true |
|
||||||
.api.client.credentials_path=strenv(CONFIG_DIR)+"/local_api_credentials.yaml" |
|
.api.client.credentials_path=strenv(CONFIG_DIR)+"/local_api_credentials.yaml" |
|
||||||
.api.server.profiles_path=strenv(CONFIG_DIR)+"/profiles.yaml" |
|
.api.server.profiles_path=strenv(CONFIG_DIR)+"/profiles.yaml" |
|
||||||
.api.server.console_path=strenv(CONFIG_DIR)+"/console.yaml" |
|
.api.server.console_path=strenv(CONFIG_DIR)+"/console.yaml" |
|
||||||
|
|
Loading…
Reference in a new issue