blotus 2 лет назад
Родитель
Сommit
9b3ff82542
3 измененных файлов с 12 добавлено и 1 удалено
  1. 1 0
      pkg/csconfig/database.go
  2. 10 1
      pkg/database/database.go
  3. 1 0
      tests/lib/config/config-local

+ 1 - 0
pkg/csconfig/database.go

@@ -22,6 +22,7 @@ type DatabaseCfg struct {
 	Flush        *FlushDBCfg `yaml:"flush"`
 	LogLevel     *log.Level  `yaml:"log_level"`
 	MaxOpenConns *int        `yaml:"max_open_conns,omitempty"`
+	UseWal       *bool       `yaml:"use_wal,omitempty"`
 }
 
 type AuthGCCfg struct {

+ 10 - 1
pkg/database/database.go

@@ -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)
 			}
 		}
-		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 {
 			return &Client{}, errors.Wrapf(err, "failed opening connection to sqlite: %v", config.DbPath)
 		}

+ 1 - 0
tests/lib/config/config-local

@@ -81,6 +81,7 @@ config_generate() {
     .config_paths.plugin_dir=strenv(PLUGIN_DIR) |
     .crowdsec_service.acquisition_path=strenv(CONFIG_DIR)+"/acquis.yaml" |
     .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.server.profiles_path=strenv(CONFIG_DIR)+"/profiles.yaml" |
     .api.server.console_path=strenv(CONFIG_DIR)+"/console.yaml" |