1# @ajax/mesh-blobd
23The blob thread's logic, sans threads: this member's blob store (`@ajax/mesh-blobs-store`), the blob
4frames on the peer links (`@ajax/mesh-blobs-frame`), and the image assemblies
5(`@ajax/mesh-assemble`).
67- **Own payloads.** The jobs thread hands over this member's payloads. Each is reserved in the store
8 and written by the writers (`.tmp`, fsync, rename, then one directory fsync per batch). It is kept
9 in memory until its copies are durable, and those bytes are counted so jobd can stop taking leases
10 past `BLOB_MEM_MAX`.
11- **Pushes.** `F_BLOB_PUT` goes through the link's bulk queue, with at most `PUT_WINDOW`
12 unacknowledged per member. `F_BLOB_ACK` comes back once the receiver's copy is durable, or refused
13 when its store is full.
14- **Every copy is a job's.** A push, an own payload or a kept fetch makes that job's reference, even
15 when the same bytes are already here for another job.
16- **Fetches.** These serve the leader's parked results and an assembly's next passes. Each blob is
17 asked of one holder at a time (else any member up), and the next is tried on a refusal, a timeout or
18 a blob that doesn't hash to its name. At most `FETCH_MAX` are in flight.
19- **Assemblies.** These cover the jobs a viewer asked for (`render`), and on the leader every active
20 pathtrace job. Each tile's passes are read here or fetched, and folded in pass order. `render`
21 answers with the status text, a PPM, a BMP, or the raw tiles for mesh-top.
2223The world is an `mbd_io`: the peer links, jobd, the writers, the clock. `@ajax/mesh-blobd-run` runs
24it as meshd's blob thread.
2526## Ported from
2728[alpha-rust-mesh](https://github.com/rsafier/alpha-rust-mesh) (Richard Safier, MIT):
29`crates/mesh-host/src/blobd.rs`: the constants, `JobInfo`, `News`, `Why`, `Fetch`, `Asm`, `Blobd`
30(`keep`, `ensure`, `event`, `ack`, `frame`, `news`, `watch`, `tick`, `render`, `resolve`), `fold`,
31and the writers' batch.
3233## Differences
3435- The Rust's fetches are a `HashMap`, so their order is arbitrary. Here they go in hash order.
36- In `render raw` the words are written in host byte order, which is little-endian on every member
37 the mesh runs on.
3839## Tests
4041`tests/blobd.c`: three blobd's over a fake network:
42- an own payload kept, counted, pushed once and acknowledged;
43- a full store refusing a push;
44- a fetch from a holder;
45- a corrupt push dropped;
46- a forget removing references, and a push for a forgotten job refused;
47- on-disk writes through the writers;
48- `render` (status, ppm, an unknown job) of an image assembled from a committed result.
4950## Licence
5152MIT. See the repository's LICENSE.