libpod: add hidden env to set sqlite timeout

Some users want to experiment with different timeout values.

Fixes #23236

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2024-07-19 16:58:21 +02:00
parent d62ef3fb21
commit b6b61a6a49

View File

@ -39,17 +39,13 @@ const (
sqliteOptionForeignKeys = "&_foreign_keys=1"
// Make sure that transactions happen exclusively.
sqliteOptionTXLock = "&_txlock=exclusive"
// Make sure busy timeout is set to high value to keep retrying when the db is locked.
// Timeout is in ms, so set it to 100s to have enough time to retry the operations.
sqliteOptionBusyTimeout = "&_busy_timeout=100000"
// Assembled sqlite options used when opening the database.
sqliteOptions = "db.sql?" +
sqliteOptionLocation +
sqliteOptionSynchronous +
sqliteOptionForeignKeys +
sqliteOptionTXLock +
sqliteOptionBusyTimeout
sqliteOptionTXLock
)
// NewSqliteState creates a new SQLite-backed state database.
@ -71,7 +67,18 @@ func NewSqliteState(runtime *Runtime) (_ State, defErr error) {
return nil, fmt.Errorf("creating root directory: %w", err)
}
conn, err := sql.Open("sqlite3", filepath.Join(basePath, sqliteOptions))
// Make sure busy timeout is set to high value to keep retrying when the db is locked.
// Timeout is in ms, so set it to 100s to have enough time to retry the operations.
// Some users might want to experiment with different timeout values (#23236)
// DO NOT DOCUMENT or recommend PODMAN_SQLITE_BUSY_TIMEOUT outside of testing.
busyTimeout := "100000"
if env, ok := os.LookupEnv("PODMAN_SQLITE_BUSY_TIMEOUT"); ok {
logrus.Debugf("PODMAN_SQLITE_BUSY_TIMEOUT is set to %s", env)
busyTimeout = env
}
sqliteOptionBusyTimeout := "&_busy_timeout=" + busyTimeout
conn, err := sql.Open("sqlite3", filepath.Join(basePath, sqliteOptions+sqliteOptionBusyTimeout))
if err != nil {
return nil, fmt.Errorf("initializing sqlite database: %w", err)
}