Ingestion queue (lxs)
Ingestion requests — dbmx.data.store, dbmx.structure.store and
dbmx.data.transfer — are consumed by the loader capacity and turned into
durable ingestion records stored in the MongoDB ingestions collection of
the sxs database.
The queue decouples AMQP delivery from processing: the message is acknowledged
as soon as the request is stored, then a worker processes it at its own pace.
This makes ingestion durable (a request survives a restart), restart-safe and
safe to run on several lxs replicas.
An ingestion is the sxs-side work item. It is not a Confy job: the Confy job
identifier is stored as confyJobId (also ctx.jobId on older records) and is
used for progress, logs and the job link.
See sxs, lxs and wxs for how ingestion capacity is isolated from the query fleet.
Lifecycle and statuses
A record also carries attempts, currentStepId, createdAt/updatedAt, the
payload (ref, name, format, mode, storage, paths) and the request
ctx (memberId, spaceId, type, userEmail).
Claim, lease and heartbeat
Processing is coordinated by a single-document atomic claim, so several replicas can compete safely:
claim()is onefindOneAndUpdatethat moves the oldestpendingrecord toprocessingand stampsworkerId,startedAt,leaseUntilandattempts + 1. Only one caller can match a given record.leaseUntilis computed by the database clock ($$NOW), so pod clock skew cannot cause premature reclaims.- While a worker is processing, it renews the lease (roughly every
lease / 3). Every write is scoped to the owner (workerId+attempts), so a worker that lost its lease cannot overwrite the state of the new owner.
Restart and crash recovery
At startup, and periodically afterwards (INGESTION_LEASE_SWEEP_MS), each
replica runs recoverStale():
- Only records whose
leaseUntilhas expired are reclaimed — their owner is gone. A live replica's in-flight ingestion is never touched. - A reclaimed record has its previous steps rolled back and is set back to
pending, so it is processed again. OnceattemptsreachesINGESTION_MAX_ATTEMPTSit is failed (error) instead of retried.
Guarantees:
- At most one active processor at a time (mutual exclusion through the atomic claim) and at-least-once execution.
- End-to-end "exactly once" additionally requires idempotent loader steps: a crash after an irreversible side effect (for example a completed ClickHouse insert) but before the record is updated will re-run that step after the lease expires.
Running multiple lxs replicas
It is safe to run more than one lxs replica:
- AMQP uses the shared
dbmx.sxs.queue, so messages are distributed across replicas (competing consumers). - The MongoDB claim is atomic, so no two replicas process the same ingestion.
- Each replica processes up to
INGESTION_PER_INSTANCEingestions concurrently (default1); total concurrency is replicas ×INGESTION_PER_INSTANCE. - A cancellation (
dbmx.job.cancel) setscancelRequestedAt. The owning replica aborts and finalizes; other replicas never roll back a job they do not own.
Authorization
Ingestion authorization is resolved from the message $ctx using an apiKey
(preferred) or a token. If neither is present — or if the lookup fails —
the message is acknowledged and a Wrong credential for … message warning is
logged (it is not retried). userEmail may be present in the payload but is used
for audit/trace only and does not authenticate.
Monitoring
- Confy exposes an Ingestions page (menu, above Jobs) with a member
selector and a period filter, listing status, member/space, loader, step,
attempts, worker and a link to the related Confy job, plus queue stat cards
(pending / processing / completed / errors / cancelled / oldest pending). It
requires
jobs:list(list) andjobs:read(detail). - sxs RPC exposes read-only methods used by that page:
ingestions.loadAll(filters:memberIds,spaceId,status,from,to,limit),ingestions.loadOneandingestions.stats. Responses are projected so credentials (ctx.token,ctx.credential) are never returned. - Healthcheck includes an
ingestionsblock with the same stats.
What to watch:
Configuration
These are global-only settings; see Configuration and settings for the full reference.
Migrating from mom_jobs
Before 4.1.0 the queue was stored in the MongoDB mom_jobs collection
(one loaderId-driven job per message). The multi-instance model renamed it to
ingestions. The new queue only reads ingestions, so an existing
deployment must copy the old collection across, otherwise:
- any
pending/processingdocument would be orphaned (another queue would never pick it up), and - the Confy Ingestions page and its job links would show nothing for the
history that still lives in
mom_jobs.
The document shape is compatible — the new-only fields (attempts,
workerId, leaseUntil, startedAt, cancelRequestedAt, confyJobId) are
additive, currentStepId is unchanged, and the job id is resolved as
confyJobId ?? ctx.jobId.
Run the migration inside an sxs/lxs pod (it reads the same
MONGODB_URL / MONGODB_DATABASE). It is idempotent (documents are copied by
_id with upsert) and dry-run by default:
A pending/processing document is requeued as pending (its stale lease is
cleared); terminal documents are copied as-is. Deploy the new code in a single
rollout — never leave old (mom_jobs) and new (ingestions) worker code running
side by side, as that would run two independent queues.
See also
- sxs, lxs and wxs — deployment and
MODES - Asynchronous exports — a similar lease-based queue
- Configuration and settings
