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

StatusMeaning
pendingQueued, waiting for a worker.
processingClaimed by a worker; carries workerId, startedAt, leaseUntil.
doneCompleted.
errorFailed, or abandoned after INGESTION_MAX_ATTEMPTS.
cancelledCancelled before or during processing.
rejectedNo loader is registered for the request type.

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 one findOneAndUpdate that moves the oldest pending record to processing and stamps workerId, startedAt, leaseUntil and attempts + 1. Only one caller can match a given record.
  • leaseUntil is 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 leaseUntil has 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. Once attempts reaches INGESTION_MAX_ATTEMPTS it 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_INSTANCE ingestions concurrently (default 1); total concurrency is replicas × INGESTION_PER_INSTANCE.
  • A cancellation (dbmx.job.cancel) sets cancelRequestedAt. 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) and jobs:read (detail).
  • sxs RPC exposes read-only methods used by that page: ingestions.loadAll (filters: memberIds, spaceId, status, from, to, limit), ingestions.loadOne and ingestions.stats. Responses are projected so credentials (ctx.token, ctx.credential) are never returned.
  • Healthcheck includes an ingestions block with the same stats.

What to watch:

SignalMeaningAction
pending rising, processing flatlxs under-provisioned or a stuck ingestionscale lxs replicas, or raise INGESTION_PER_INSTANCE
stale > 0 beyond INGESTION_LEASE_SWEEP_MSrecovery not running (instance wedged)check the lxs loop; restart
failed / cancelled climbingfailing loads / cancellationswiden the period, open the detail
maxAttempts reachedrepeated crash/retryinvestigate the step; ensure it is idempotent
oldestPendingAgeMs largebacklogscale out

Configuration

VariableDefaultDescription
INGESTION_LEASE_SECONDS300Lease duration for a claimed ingestion
INGESTION_LEASE_SWEEP_MS15000How often expired ingestion leases are recovered
INGESTION_POLL_MS1000Ingestion queue polling interval
INGESTION_CANCEL_CHECK_MS5000How often a running ingestion checks for cancellation
INGESTION_MAX_ATTEMPTS3Attempts before an ingestion is failed
INGESTION_PER_INSTANCE1Ingestions processed concurrently per process

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/processing document 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:

# 0. nothing may be in flight
kubectl -n dbmx-prod exec mongo1-0 -- mongosh --quiet mongodb://localhost:27017/sxs \
  --eval 'print(db.mom_jobs.countDocuments({status:{$in:["pending","processing"]}}))'

# 1. dry-run, then apply
kubectl -n dbmx-prod cp src/scripts/migrateMomJobsToIngestions.js <lxs-pod>:/opt/src/scripts/
kubectl -n dbmx-prod exec <lxs-pod> -- node src/scripts/migrateMomJobsToIngestions.js
kubectl -n dbmx-prod exec <lxs-pod> -- node src/scripts/migrateMomJobsToIngestions.js --apply

# 2. verify, then the old collection can be dropped
kubectl -n dbmx-prod exec mongo1-0 -- mongosh --quiet mongodb://localhost:27017/sxs \
  --eval 'print(db.ingestions.countDocuments({}))'

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