mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-09-10 02:25:56 +00:00
metrics: skip checkpoint when freelist empty in reclaimFreePages
Follow-up to 2b8ce06c0: that commit's contract update states reclaim skips
the WAL checkpoint entirely when the freelist is empty, but the prior commit
captured the pre-refinement store.go (the re-stage was lost to a .git/index.lock
race). Make the code match the contract: return early on a freelist_count read
error and when freelist == 0, so a steady-state no-op cycle does not run an
extra hourly wal_checkpoint(TRUNCATE).
This commit is contained in:
+12
-9
@@ -1760,16 +1760,19 @@ func (s *Store) reclaimFreePages() {
|
||||
var freelist int64
|
||||
if err := s.db.QueryRow(`PRAGMA freelist_count`).Scan(&freelist); err != nil {
|
||||
log.Debug().Err(err).Msg("Failed to read freelist_count")
|
||||
freelist = maxReclaimPages // fall back to a bounded reclaim
|
||||
return
|
||||
}
|
||||
if freelist > 0 {
|
||||
pages := freelist
|
||||
if pages > maxReclaimPages {
|
||||
pages = maxReclaimPages
|
||||
}
|
||||
if _, err := s.db.Exec(fmt.Sprintf(`PRAGMA incremental_vacuum(%d)`, pages)); err != nil {
|
||||
log.Debug().Err(err).Msg("Incremental vacuum failed")
|
||||
}
|
||||
if freelist == 0 {
|
||||
// Nothing to reclaim: skip the checkpoint too so steady-state WAL
|
||||
// cadence is no more aggressive than before this drained every cycle.
|
||||
return
|
||||
}
|
||||
pages := freelist
|
||||
if pages > maxReclaimPages {
|
||||
pages = maxReclaimPages
|
||||
}
|
||||
if _, err := s.db.Exec(fmt.Sprintf(`PRAGMA incremental_vacuum(%d)`, pages)); err != nil {
|
||||
log.Debug().Err(err).Msg("Incremental vacuum failed")
|
||||
}
|
||||
if _, err := s.db.Exec(`PRAGMA wal_checkpoint(TRUNCATE)`); err != nil {
|
||||
log.Debug().Err(err).Msg("WAL checkpoint failed")
|
||||
|
||||
Reference in New Issue
Block a user