jonnify·echd /echd/bus/jobs/batches-and-locks

echd — Echo on Encore · E3.3 · dive

Batches and Locks

A batch is claimed together and settled apart — many jobs in one round trip, their leases renewed as one, but each finished on its own verdict, so one poison job never drags its batch down.

Vision · real substrate

echd speaks in the present tense over a build ladder. Every module, verb, key, and port named on this page is real; the composition into one standing platform is the vision the ladder builds.

§1

The dive

docs/echo_mq/specs/emq2/emq.5/emq.5.md · specs/emq.commands/emq.commands.md

Claiming one job at a time is correct but slow: every claim is a round trip. @bclaim claims a whole batch in a single move — claim_batch/4 and the BatchConsumer shape it by a min_size and a timeout, and @gbclaim keeps a batch inside one group's lane — so throughput rises without loosening the lease discipline that protects each job. A batch is not a looser claim; it is many claims made at once.

The word lock on this bus is not a separate primitive — the lock is the lease. A claimed job is locked to its worker for the duration of its lease; extendLock renews one, extendLocks renews a whole batch together, releaseLock frees it, and a stalled-job sweep reclaims the locks of a worker that died. That pairing is what makes batches safe: the batch holds many locks and renews them as one, so a slow run keeps its whole batch, and yet the partitioned finish settles each job on its own verdict — these acked, those returned to retry — so one poison job in a batch of fifty never drags the other forty-nine back.

§2

Claimed together, settled apart

docs/echo_mq/specs/emq2/emq.5/emq.5.md
Claimed together, settled apart · the batch and its locks · hover to read
claim many at once, hold their leases together, finish per item @bclaim(n) one round trip J1 J2 J3 J4 the lock is the lease — extendLocks renews the batch, releaseLock frees a stalled-job sweep reclaims a dead worker's locks the partitioned finish — a per-item verdict some acked, some returned to retry — settled item by item
Claim many, once. @bclaim takes a whole batch of jobs in a single round trip — claim_batch/4 and the BatchConsumer shape it by min_size and a timeout, and @gbclaim keeps a batch within one group's lane. Fewer round trips, more throughput, the same lease discipline per job.
The lock is the lease. A claimed job is locked to its worker by its lease; extendLock renews one, extendLocks renews a whole batch at once, and releaseLock frees it. Nothing is a separate mutex — holding the job is holding the lock — and a stalled-job sweep reclaims the locks of a worker that died.
Finish per item. A batch does not succeed or fail as a lump. The partitioned finish carries a per-item verdict — these acked, those returned to retry — so one poison job in a batch of fifty does not drag the other forty-nine back. Claimed together, settled individually.

Hover or focus a part to read it; click to pin. Without scripting, all three read in sequence.

§3

The tension the batch resolves

docs/echo_mq/specs/emq2/emq.5/emq.5.md · specs/emq.commands/emq.commands.md

A batch has to hold two things that pull against each other: efficiency wants the jobs treated as one, correctness wants them treated as many. Treat them purely as one — claim, run, ack the lump — and a single bad job fails the whole batch, forcing fifty retries for one fault. Treat them purely as many — a round trip each — and the throughput win is gone. The bus keeps both by splitting the join along the right seam: claimed together, locked together, settled apart.

The lease is where "together" lives. @bclaim takes the batch atomically, and extendLocks renews every lease in it in one move, so a batch that runs long does not lose a job to an expired lock halfway through. The verdict is where "apart" lives. EchoMQ.BatchFinish carries a per-member result, so the finish acks the jobs that succeeded and returns the ones that failed to retry, each on its own attempts clock. The stalled-job sweep backs the whole thing: if the worker dies holding the batch, its locks are reclaimed and the jobs return to be claimed again. Bulk where bulk is safe, individual where individuality matters.

§4

The rule

one line to carry

The batch rule — a batch is claimed together and settled apart: many locks renewed as one, verdicts rendered per item. @bclaim takes many in one round trip and extendLocks renews their leases together, but the partitioned finish acks and retries each on its own — so one poison job never drags its batch down, and a dead worker's locks are reclaimed for the whole batch.

§5

Doors

batches and locks, in depth
§6

References

sources · related

Sources

Related