pub async fn trim_change_log(
pool: &PgPool,
before: DateTime<Utc>,
) -> Result<u64>Expand description
Delete every change-log row with created_at < before. Returns the number
of rows deleted.
Run periodically from a background task; the reactor’s gap-recovery only
needs the recent tail. Default retention in the framework is 1 hour, set
by passing Utc::now() - chrono::Duration::hours(1).
Trimming is skipped when the total row count is at or below
[CHANGE_LOG_MIN_ROWS] (default 1 000). This prevents over-aggressive
cleanup on quiet systems where entries age past the window but the log
itself is small.
Uses pg_try_advisory_xact_lock with the LeaderRole::LogCompactor lock
ID so that only one node in the cluster runs the DELETE at a time. If
another node already holds the lock the function returns Ok(0) immediately
rather than blocking or racing.