Background jobs and housekeeping

Release status: 3.0.0 and develop
Released 3.0.0 has the maintenance operation list, /v1/freshness/status and the backup status. relata_stat_jobs, the relata_job_* series, pause, resume and cancel, the clean-up debt view, history compaction and eviction, the index check and the freshness-lag series are on develop. "On develop" means merged in the product repository but not in a release yet.

The jobs view

relata_stat_jobs has one row per job kind: compaction, vector_compaction, reindex, vector_index_rebuild, vector_index_cutover, gdpr_purge, wal_prune, generation_rollover, backup, restore, history_compaction, mv_refresh, retention and diagnostics_snapshot.

SELECT kind, state, progress_pct, started_ns FROM relata_stat_jobs WHERE state = 'running'
SELECT kind, last_error, failures FROM relata_stat_jobs WHERE state = 'failed'
SELECT kind, runs, last_duration_seconds FROM relata_stat_jobs ORDER BY runs DESC
ColumnMeaning
kindThe job kind.
staterunning, paused, failed (the last run failed) or idle.
runningRuns of this kind in progress now.
job_idId of the latest run, when it has one. This is the id the pause, resume and cancel routes take.
request_idRequest id of the call that started the latest run, when one did.
started_ns, finished_nsStart and end of the latest run, nanoseconds UTC.
progress_done, progress_total, progress_unit, progress_pct, last_progress_nsProgress, where the job reports it: compaction and history compaction in types, vector compaction in buckets, reindex and vector rebuild in rows.
last_result, last_errorok, error or cancelled, and the last error (at most 512 bytes).
last_duration_seconds, last_success_nsWall time of the latest run, and the end of the latest success.
runs, failures, cancelled, bytes_freedTotals since start. bytes_freed is reported by compaction only.

Also the jobs key of GET /v1/system/stats. Operator, oversight and no-tenant keys only. Blob GC runs only in the offline relata blob-gc command, so it has no row on a serving node.

Pause, resume and cancel

curl -s -X POST -H "Authorization: Bearer $RELATA_ADMIN_TOKEN" \
  http://127.0.0.1:9091/admin/jobs/<job_id>/pause      # or /resume, /cancel

These routes act on a running job by its job_id. A job stops only at a checkpoint between units, never inside a write, and holds no store lock while it waits. A cancelled job leaves the data consistent, and running it again finishes the work.

KindCheckpointAfter cancel
compactionBefore each typeTypes not started are skipped
history_compactionAt checkpoints during the passA later run resumes the work
vector_compactionBefore each vector bucketRemaining buckets wait for the next sweep
reindexBefore each batch of 512 rowsA rerun completes it
vector_index_rebuildBefore the bucket is dropped, then between batchesCancel works only before the drop; after it, pause still works
gdpr_purgeBefore the history rewrite and before the generation retirementPending erasures stay hidden from reads and run in the next window

A pause holds the job for at most 15 minutes, then it resumes by itself. A finished job answers 409 job-finished; a job that cannot be controlled, such as a vector cutover, answers 409 job-not-controllable. Every action is audited. A cancelled maintenance run answers its starting request with 409 job-cancelled.

Maintenance operations you start

These admin routes share one contract: POST /admin/compact, /admin/compact-history (on develop, see below), /admin/compact-vectors, /admin/reindex, /admin/vector-index/rebuild, /admin/vector-index/cutover and /admin/vector-index/retire-model-tag.

  • One runs at a time per node. A second request is refused with 409 maintenance-in-progress.
  • Every run gets an id, returned as operation_id and in the Relata-Operation-Id header.
  • A client that disconnects does not cancel the work.
curl -s -H "Authorization: Bearer $RELATA_ADMIN_TOKEN" \
  http://127.0.0.1:9091/admin/maintenance/operations | jq .

A record has id, kind, target, status (running, succeeded, failed, cancelled or abandoned), start and end times, error and result. The node keeps the last 64 finished runs in memory; the audit log keeps the permanent record.

Clean-up debt

On develop, relata_stat_cleanup shows what clean-up the node still owes, like PostgreSQL's n_dead_tup and last_autovacuum. It has one row per object type (scope = 'type') and one node row (scope = 'node') for retained WAL.

SELECT object_type, dead_versions, tombstones, dead_bytes_estimate
FROM relata_stat_cleanup WHERE scope = 'type' ORDER BY dead_versions DESC LIMIT 10
 
SELECT object_type, segments, last_compaction_ns FROM relata_stat_cleanup WHERE compaction_due = true

Other columns include versions, live_rows, dead_ratio, history_retention_seconds, last_compaction_kind (segments or history), evicted_versions, evicted_bytes, wal_retained_bytes and complete. Several figures are estimates. The read never waits for a writer; complete = false marks partial figures. Node-wide callers only. Also the cleanup key of GET /v1/system/stats.

History compaction and eviction

Both are on develop, off by default, and act only on rows already in remote storage.

SettingDefaultEffect
RELATA_HISTORY_COMPACTION_ENABLEDfalseAllows POST /admin/compact-history[?type=T]. It removes from memory what segment compaction would drop: the originals of correction pairs, and closed versions and delete tombstones past a type's retention window. AS OF answers inside the window do not change. Off, the route answers 503 history-compaction-disabled.
RELATA_HISTORY_COMPACTION_SCHEDULEfalseAlso runs a time-budgeted slice on every auto-compaction tick.
RELATA_HISTORY_EVICTION_ENABLEDfalseThe same pass then moves closed versions out of memory while keeping them readable from remote storage. Live rows, rows under legal hold, WORM types and governance types stay.
RELATA_HISTORY_EVICTION_MIN_AGE_SECS300How long a version must have been closed before eviction may move it.

With eviction on, an AS OF read that can see an evicted version fetches it first. It gives the same answer or a retryable 503 (REL_STORAGE_UNAVAILABLE, or REL_HISTORY_READ_TOO_LARGE past RELATA_HISTORY_OVERLAY_MAX_MB, default 256), never a short one. Read the compaction guide before turning either on.

Metrics and alerts

QuestionSeries
Runs and outcomes per kindrelata_job_runs_total{kind,result}
How long a run takesrelata_job_duration_seconds{kind}
When the last success wasrelata_job_last_success_timestamp_seconds{kind}
Bytes freed by compactionrelata_job_bytes_freed_total{kind="compaction"}
Is compaction being paced?relata_compaction_throttled_seconds_total, relata_compaction_io_limit_bytes_per_second
Did a worker die?relata_dead_workers, relata_background_task_panics_total
Is the ingest queue backing up?relata_ingest_queue_depth_ratio
When did the last backup finish?relata_last_backup_age_seconds, GET /admin/backup/status

Alerts RelataJobNotSucceeding (last success older than three times the kind's period), RelataJobLooping (too many runs per hour), RelataBackgroundWorkerDead, RelataBackupStale and RelataBackupFailed ship with the chart. Each has a runbook section. Compaction pace is tuned with RELATA_COMPACTION_IO_MIB_PER_SEC and RELATA_COMPACTION_MAX_INFLIGHT_MIB.

Index health and freshness

relata check-indexes, or POST /admin/indexes/check, compares the full-text, vector, graph and identity indexes with their rows and lists mismatches. It is read-only.

relata_freshness_lag_seconds{index} grows while an index backlog (lexical, secondary, vector, graph or extraction) is stuck. It is 0 while the backlog is empty or draining. The alert RelataFreshnessLag fires after 300 seconds for 5 minutes. GET /v1/freshness/status names the stalled index and why.

See also Backup and restore and Jobs, workflows and detection.

What is coming

Further housekeeping items are tracked in #7849.