Skip to content

Commit

Permalink
Merge pull request containers#20850 from Luap99/v4.8-backports
Browse files Browse the repository at this point in the history
[v4.8] backport sqlite fixes
  • Loading branch information
openshift-merge-bot[bot] authored Dec 1, 2023
2 parents 0c606ef + 9c9d2fc commit 1c434e3
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions libpod/sqlite_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ 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 retying 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
sqliteOptionTXLock +
sqliteOptionBusyTimeout
)

// NewSqliteState creates a new SQLite-backed state database.
Expand Down Expand Up @@ -374,10 +378,6 @@ func (s *SQLiteState) ValidateDBConfig(runtime *Runtime) (defErr error) {
return fmt.Errorf("retrieving DB config: %w", err)
}

if err := tx.Commit(); err != nil {
return fmt.Errorf("committing database validation row: %w", err)
}

checkField := func(fieldName, dbVal, ourVal string) error {
if dbVal != ourVal {
return fmt.Errorf("database %s %q does not match our %s %q: %w", fieldName, dbVal, fieldName, ourVal, define.ErrDBBadConfig)
Expand Down Expand Up @@ -408,6 +408,12 @@ func (s *SQLiteState) ValidateDBConfig(runtime *Runtime) (defErr error) {
return err
}

if err := tx.Commit(); err != nil {
return fmt.Errorf("committing database validation row: %w", err)
}
// Do not return any error after the commit call because the defer will
// try to roll back the transaction which results in an logged error.

return nil
}

Expand Down Expand Up @@ -1698,6 +1704,10 @@ func (s *SQLiteState) RemovePodContainers(pod *Pod) (defErr error) {
return err
}

if err := tx.Commit(); err != nil {
return fmt.Errorf("committing pod containers %s removal transaction: %w", pod.ID(), err)
}

return nil
}

Expand Down

0 comments on commit 1c434e3

Please sign in to comment.