Record the job store's measurements on leil-rig
The owner has no ARM boards and no Pi-class host, so stage 1a ran its probe on leil-test-1, an x86_64 AlmaLinux VM on leil-rig with a virtual disk, on his word. Decision 2 now says so: no build of the store runs on ARM hardware, and the CHANGELOG will say that the ARM builds ship it untested. Stage 1d, and the remote-printers plan, which counted on stage 1a measuring an SD card, say the same. On that disk, with the schema under RECORDS and 1000 jobs of history, a text job cost 1.04 flushes, 53.8 KiB of device writes and 11.46 WAL frames, and its synced commit took 5.0 ms, or 2.9 ms with fdatasync. Every call the store makes passed the unit's syscall filter, with SELinux enforcing. The numbers are at or below the earlier estimates, so none of them argues against decision 1. An SD card, ext4 and ARM remain unmeasured. The probe was built on modernc.org/sqlite v1.64.0, released on 2026-12-01, with the same SQLite and libc pin as v1.63.0. It lives outside the repository, and the rig was left as it was found. Part of stage 1a of docs/plans/job-store.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
709e7904e9
commit
c548833656
2 files changed
+57
-28
No files matched your search
+55
-26
@@ -1,6 +1,6 @@
|
||||
# Plan: persistent job store and image previews
|
||||
|
||||
Status: **planned; nothing is built.** The owner accepted every proposed default on 2026-12-01 (Decisions), and design.md's Planned next item 1 records them. Each stage runs in its own session, briefed from its section: stage 1a follows decisions 1-3, stage 1b decision 4, stage 1c decisions 5-12, stage 1d decisions 13-15, phase 2 decision 16, phase 2b decisions 17 and 18, phase 3 decision 19 and phase 4 decision 20; phase 5 holds decisions 21-23. Phases 3a-3c need nothing from phases 1 and 2, so they can come first if the owner wants previews sooner. Phase 2b needs phase 1 but not phase 2, so it can come before phase 2. Every check on the live printer needs the owner's OK.
|
||||
Status: **planned; stage 1a's measurements are done (Investigation findings), and nothing is built.** The owner accepted every proposed default on 2026-12-01 (Decisions), and design.md's Planned next item 1 records them. Each stage runs in its own session, briefed from its section: stage 1a follows decisions 1-3, stage 1b decision 4, stage 1c decisions 5-12, stage 1d decisions 13-15, phase 2 decision 16, phase 2b decisions 17 and 18, phase 3 decision 19 and phase 4 decision 20; phase 5 holds decisions 21-23. Phases 3a-3c need nothing from phases 1 and 2, so they can come first if the owner wants previews sooner. Phase 2b needs phase 1 but not phase 2, so it can come before phase 2. Every check on the live printer needs the owner's OK.
|
||||
|
||||
## Decisions (owner, 2026-11-30)
|
||||
|
||||
@@ -42,7 +42,7 @@ For stage 1a:
|
||||
- Not GORM, though it writes the same bytes and fsyncs as plain SQL (measured). Its pure-Go dialector, `github.com/glebarez/sqlite` v1.11.0, has had no release since 2024-03-14 and asks for maintainers (issue #152). A plain `go get` of it pulls in SQLite 3.41.2, and it cannot share a binary with `modernc.org/sqlite`. GORM's default logger prints SQL with its values, which would log print contents. It adds about 10 MB to the daemon against 4 MB, because one reflective call in GORM stops the linker dropping unused methods anywhere in the binary; Expr makes the same call (docs/plans/printers.md, Investigation findings, EXPR), so once Expr is in the binary (docs/plans/templates.md, decision 1) that part of the gap goes.
|
||||
- Trade-off: on the measures alone the home-grown journal wins: the fewest bytes and syncs, no dependency, the same behaviour on every platform. At the device the gap is smaller than the logical bytes suggest, because each sync also rewrites a 4 KiB block and roughly 12-20 KiB of ext4 journal: SQLite writes about 3-5× the journal's bytes, not about 30× (estimates, COMPARED). At 500 jobs a day the candidates write between about 8 and 120 MiB a day.
|
||||
- The store comes in at its latest stable release.
|
||||
2. **Hardware for the measurements.** The owner runs stage 1a's probe on one Pi-class host with an SD card, and on an ARMv6 board if he has one. modernc's own CI names no ARMv6 target, and there are old SIGSEGV reports for linux/arm. Without an ARMv6 run, the armv6 tarball ships the store untested on hardware, and the CHANGELOG says so.
|
||||
2. **Hardware for the measurements.** The owner has no ARM boards and no Pi-class host, so stage 1a ran its probe on leil-test-1, an x86_64 VM on leil-rig with a virtual disk (Investigation findings, MEASURED ON LEIL-TEST-1). That measured Linux, device writes and flushes, and the unit's sandbox, but not an SD card or ARM. No build of the store runs on ARM hardware: modernc's own CI names no ARMv6 target, and there are old SIGSEGV reports for linux/arm. So the armv6, armv7 and arm64 tarballs ship the store untested on hardware, and the CHANGELOG says so.
|
||||
3. **SQLite's locking mode.** `locking_mode=EXCLUSIVE` and one connection. There is no `-shm` file and no mmap, and a second daemon on the same directory fails at start. Trade-off: reads wait behind writes and their fsyncs, and no other process, the `sqlite3` CLI or a later read-only `uberbringer` command included, can read the database while the daemon runs. Statuses stay in memory, so only the worker and previews by ID read the database.
|
||||
|
||||
For stage 1b:
|
||||
@@ -130,7 +130,7 @@ For phase 5, later:
|
||||
|
||||
## Investigation findings
|
||||
|
||||
Four research tracks ran on 2026-11-30: SQLite, key-value stores, a build of each candidate and Epson's print acknowledgement, with a map of the repository; a review of the plan added a race-detector run. Runs were light and on the Windows workstation (NVMe SSD, NTFS), so latencies are not those of an SD card. Nothing ran against the printer or on a Pi; stage 1a measures there. Versions are the latest on 2026-11-30, from proxy.golang.org.
|
||||
Four research tracks ran on 2026-11-30: SQLite, key-value stores, a build of each candidate and Epson's print acknowledgement, with a map of the repository; a review of the plan added a race-detector run. Runs were light and on the Windows workstation (NVMe SSD, NTFS), so latencies are not those of an SD card. Nothing ran against the printer, on a Pi or on an SD card. Stage 1a then ran a probe on leil-test-1, a Linux VM (MEASURED ON LEIL-TEST-1). Versions are the latest on 2026-11-30, from proxy.golang.org; stage 1a used `modernc.org/sqlite` v1.64.0, released on 2026-12-01.
|
||||
|
||||
THE ONE WRITE THAT MATTERS
|
||||
- A TCP write returns when the kernel has the bytes, not when they print. No store can record "printed" at the moment of sending.
|
||||
@@ -151,7 +151,7 @@ SQLITE IN WAL MODE
|
||||
|
||||
- **Checkpoints.** One runs (PASSIVE) on the commit that takes the WAL to 1000 pages, about 4 MB, and one when the last connection closes. It runs on the committing thread, so it can delay that commit. It costs 2 fsyncs, the WAL then the database, and a third for the WAL header when the log restarts. It copies only the latest version of each page. The WAL is reused from the start, not truncated, unless `journal_size_limit` is set.
|
||||
- **Sync levels can be mixed.** `synchronous` belongs to the connection, is not persisted, and cannot change inside a transaction. The worker can run `PRAGMA synchronous=FULL`, commit the `sending` mark, then return to NORMAL, all between transactions. The WAL is one append-only file, so that sync also makes every earlier NORMAL commit durable.
|
||||
- **So SQLite can record `sending` durably before the bytes go out, for one fsync per job**, plus about 0.04 per job in checkpoints. On the workstation's NVMe, a FULL commit took about 1.1 ms and a NORMAL one 0.02-0.05 ms. An SD card's flush time is unmeasured.
|
||||
- **So SQLite can record `sending` durably before the bytes go out, for one fsync per job**, plus about 0.04 per job in checkpoints. On the workstation's NVMe, a FULL commit took about 1.1 ms and a NORMAL one 0.02-0.05 ms. On leil-test-1's virtual disk, a FULL commit took 5.0 ms (median), or 2.9 ms with fdatasync, and a NORMAL one about 0.6 ms. An SD card's flush time is unmeasured.
|
||||
- fsyncs per job, with `done` and the pruning in one commit:
|
||||
|
||||
| Policy | fsyncs per job |
|
||||
@@ -166,7 +166,7 @@ SQLITE IN WAL MODE
|
||||
- An image job (50 KB of JSON) appends 28 frames (112.8 KiB), and the file levels off at 48 MiB.
|
||||
- Page 1 changes in almost every commit, because it holds the database size and the free-page count.
|
||||
- The spike, with a small table and no pruning, measured 2.67 frames for an insert of 1 KiB and 1 frame for an update: about 15 KB for an insert and one change.
|
||||
- Frame counts shift by about ±2 with the schema, so stage 1a measures the schema under RECORDS. Every run here kept a job's status in one table; RECORDS splits it into `jobs` and `deliveries`.
|
||||
- Frame counts shift with the schema. Every run here kept a job's status in one table. The schema under RECORDS, which splits it into `jobs` and `deliveries`, appended 11.46 frames (46.1 KiB) per text job on leil-test-1.
|
||||
- At 100 text jobs a day that is about 5.6 MiB of WAL; at 1000, about 56 MiB.
|
||||
- NORMAL saves flush barriers and ext4 journal commits, not bytes, since the kernel still writes the WAL within about 30-35 s. An fsync that changes a file's size or mtime also commits roughly 12-20 KiB of ext4 journal (an estimate, not measured).
|
||||
- The rollback journal (`journal_mode=DELETE`) is worse: 2.4× the bytes per insert, 23 file-control calls and about 4 ms per commit (spike).
|
||||
@@ -180,6 +180,29 @@ SQLITE IN WAL MODE
|
||||
- `secure_delete=FAST` scrubs b-tree pages at no extra IO, but not free overflow pages, where image bodies end up. `ON` costs extra writes.
|
||||
- WAL does not work over a network filesystem, and Docker Desktop bind mounts pass through a VM file share.
|
||||
|
||||
MEASURED ON LEIL-TEST-1 (stage 1a, 2026-12-01)
|
||||
- **The host.** leil-test-1, the test node of leil-rig: an AlmaLinux 9.8 VM (kernel 5.14, x86_64, 16 cores) under KVM on pve-1. The store's directory was on xfs on a virtual QEMU SCSI disk, with `write_cache` "write back" and FUA on; what pve-1's storage does with a flush is unknown. So the times are a VM's, not an SD card's, and nothing ran on ARM (decision 2). The node was idle: load average 0.1 on 16 cores, no build running.
|
||||
- **The probe.** `jobprobe`, built with `CGO_ENABLED=0` and Go 1.27.4 on `modernc.org/sqlite` v1.64.0 (SQLite 3.54.1, libc v1.80.1, the same pin as v1.63.0). It sets the pragmas and creates the schema under RECORDS. It stores 1000 finished jobs, then runs 200 text jobs of 1,500 bytes, one delivery each: the insert at NORMAL, the `sending` mark at FULL, then `done` and the pruning of the oldest job in one commit at NORMAL. Device counters come from `/sys/dev/block`, read after a `syncfs`, less an idle baseline taken over a minute first.
|
||||
- **The sandbox allows the store.** Both runs ran as transient units with the unit's sandbox: `DynamicUser`, `ProtectSystem=strict`, `PrivateDevices`, `MemoryDenyWriteExecute`, `SystemCallFilter=@system-service` with `SystemCallErrorNumber=EPERM`, and `SystemCallArchitectures=native`. SELinux was enforcing, and both runs finished without an error. `@system-service` takes in `@sync` (`fsync`, `fdatasync`, `syncfs`), `@file-system` (`fcntl`, `ftruncate`, `openat`, `unlink`) and `@basic-io` (`pread64`, `pwrite64`). The database and the WAL were 0600, and there was no `-shm` file.
|
||||
|
||||
| Per job | fsync | fdatasync |
|
||||
|---|---|---|
|
||||
| Device writes, less the baseline | 53.8 KiB in 2.37 requests | 53.4 KiB in 2.38 requests |
|
||||
| Device flushes | 1.04 | 1.04 |
|
||||
| `write_bytes` in `/proc/self/io` | 52.6 KiB | 52.6 KiB |
|
||||
| WAL frames | 11.46 (46.1 KiB) | 11.46 (46.1 KiB) |
|
||||
| FULL commit (`sending`): median, p99, max | 4.98, 8.36, 9.87 ms | 2.89, 6.15, 6.76 ms |
|
||||
| NORMAL commit: median, p99, max | 0.55, 1.06, 15.12 ms | 0.61, 1.09, 24.01 ms |
|
||||
|
||||
- **Checkpoints.** Two automatic checkpoints ran in 200 jobs, about one every 87 jobs, and both ran inside an insert's commit. The slowest inserts, those that ran a checkpoint or restarted the log and synced its header, took 10-24 ms. The other NORMAL commits took about 1 ms or less. The final PASSIVE checkpoint, of 291 frames, took 6-7 ms and wrote 109.5 KiB to the device with 2 flushes. The database levelled off at 2.12 MiB and the WAL file at 3.93 MiB, within `journal_size_limit`.
|
||||
- **The baseline.** The node's own services wrote about 2 MiB a minute, in about 250 write requests and 85 flushes. Over a run of about 1.5 s that is about 0.3 KiB and 0.01 flushes per job. The baseline takes out steady writes, not a burst.
|
||||
- **Against the estimates above:**
|
||||
- Flushes: 1.04 per job, as predicted: one for the `sending` mark and about 0.04 for checkpoints and restarts of the log.
|
||||
- WAL frames: 11.46 per text job, against 14.35 in the SQLite track's runs with one table.
|
||||
- Device writes: 53.8 KiB per job, against the 75-80 KiB estimated for ext4. The device wrote about 8 KiB per job beyond the WAL frames: the xfs log of each sync and the job's share of the checkpoints. At 500 jobs a day that is about 26 MiB a day.
|
||||
- `fdatasync` left the writes and flushes the same and cut the synced commit's median by about 40%.
|
||||
- None of this argues against decision 1: the writes and flushes are at or below the findings' figures. An SD card's flush time and wear, ext4, and ARM remain unmeasured.
|
||||
|
||||
PURE-GO SQLITE: DRIVERS AND LAYERS
|
||||
|
||||
| | `modernc.org/sqlite` | `github.com/glebarez/sqlite` with GORM | `github.com/ncruces/go-sqlite3` |
|
||||
@@ -201,7 +224,7 @@ PURE-GO SQLITE: DRIVERS AND LAYERS
|
||||
- Its CPU cost is 1.3-2.0× that of C SQLite, which does not matter at this workload.
|
||||
- Downstream go.mod files must pin its exact libc (cznic issue #177).
|
||||
- Historical SIGSEGV reports exist for linux/arm (GitLab #132), and a 32-bit `va_list` overrun was fixed around v1.53.
|
||||
- v1.63.0 passed `go test -race` (with checkptr) on windows/amd64: 50 jobs with WAL, exclusive locking, one connection and `synchronous` switched between FULL and NORMAL between commits. The race detector does not run on 32-bit ARM, so armv6 and armv7 rest on stage 1a.
|
||||
- v1.63.0 passed `go test -race` (with checkptr) on windows/amd64: 50 jobs with WAL, exclusive locking, one connection and `synchronous` switched between FULL and NORMAL between commits. The race detector does not run on 32-bit ARM, and nothing has run the store on ARM hardware (decision 2).
|
||||
- ncruces fixed WAL-mode corruption in two optional VFSes in v0.37.0. Its v0.38.2 go.mod has no wazero, so it should run under `MemoryDenyWriteExecute=true` (an inference).
|
||||
|
||||
BBOLT (`go.etcd.io/bbolt` v1.5.0, 2026-06-03)
|
||||
@@ -240,7 +263,7 @@ COMPARED (per job: accepted, sending, done with pruning; a 1.5 KB body; 1000 job
|
||||
| 32-bit ARM | builds; ARMv6 not in upstream's tests | builds; CI cross-builds arm | no issue | not built by upstream's CI |
|
||||
| Queries | SQL | key order; TypeIDs sort by time | our own maps | key order |
|
||||
|
||||
- The device estimates add, for each sync, a rewritten 4 KiB block and roughly 12-20 KiB of ext4 journal to the logical bytes; stage 1a measures them. On that measure SQLite writes about 3-5× the journal's bytes, where the logical bytes differ about 30×.
|
||||
- The device estimates add, for each sync, a rewritten 4 KiB block and roughly 12-20 KiB of ext4 journal to the logical bytes. On that measure SQLite writes about 3-5× the journal's bytes, where the logical bytes differ about 30×. On xfs on leil-test-1, SQLite's device writes came to 53.8 KiB per job, below its estimate (MEASURED ON LEIL-TEST-1); ext4 and the other columns are unmeasured.
|
||||
- At 500 jobs a day, fsyncs a day: SQLite with decision 5's policy about 520, plus failures and ntfy jobs; the journal 500-1,500; SQLite with FULL for everything about 1,500 plus checkpoints; bbolt 2,000-3,000. For scale, saving every ntfy keepalive would have cost about 1,900 synced writes a day per subscription, which is why that cursor is saved at most every 10 minutes.
|
||||
|
||||
DOES KEEPING DATA IN MEMORY CUT IO?
|
||||
@@ -260,11 +283,11 @@ PRINT ACKNOWLEDGEMENT ON EPSON PRINTERS
|
||||
- A side finding: the UB-E02 and UB-E03 boards turn automatic status on at power-on, and the `ESC @` that starts each job turns it off, as Epson's guides confirm (docs/plans/printers.md, Investigation findings). Until the first job after a power-on, the printer may send unrequested 4-byte status frames, which `printer.Client.Status`, reading one byte per request, could take as "status unsupported". Whether the frames reach a port 9100 client is unverified.
|
||||
|
||||
WHERE THE REPORTS DISAGREE OR ARE UNSURE
|
||||
- WAL bytes per job: about 15 KB (spike: small table, no pruning), 20-40 KiB (the key-value track's estimate) and 57.7 KiB (SQLite track: full history with pruning). The setups differ; stage 1a measures the schema under RECORDS.
|
||||
- WAL bytes per job: about 15 KB (spike: small table, no pruning), 20-40 KiB (the key-value track's estimate) and 57.7 KiB (SQLite track: full history with pruning). The setups differ. The schema under RECORDS appended 46.1 KiB (11.46 frames) on leil-test-1.
|
||||
- Badger's size: +5.6-6.0 MB on a small test program, +7.9-8.4 MB in the daemon.
|
||||
- modernc's size: +3.8 MB (v1.60.1, SQLite track) and +4.0 MB (v1.63.0, spike).
|
||||
- An acknowledgement on the TM-T88IV: design.md ("The queue lives in memory, on purpose") says ESC/POS gives none; Epson documents one (`GS ( H` fn 48). It is unverified on this printer.
|
||||
- Stage 1a measures what no track could: Linux, an SD card and ARM hardware, device writes and flushes, and whether `SystemCallFilter=@system-service` allows what the store calls. Not measured by any track: ncruces' size, Pebble, and fsync counts by strace (they come from SQLite's docs and bbolt's code).
|
||||
- Stage 1a measured on Linux what no track could: device writes and flushes, and whether `SystemCallFilter=@system-service` allows what the store calls. Not measured by anything: an SD card, ARM hardware, ext4, ncruces' size, Pebble, and fsync counts by strace (they come from SQLite's docs and bbolt's code).
|
||||
|
||||
SOURCES
|
||||
- SQLite: sqlite.org/wal.html, /pragma.html, /fileformat2.html, /atomiccommit.html, /howtocorrupt.html.
|
||||
@@ -292,7 +315,7 @@ SOURCES
|
||||
## Overview
|
||||
|
||||
WHAT SHIPS WHEN
|
||||
1. Stages 1a-1d: measurements on the owner's hardware, the `[state] dir` key, the state machine without a database, then the SQLite store. Every job is stored when it is accepted. The worker renders, connects, commits a synced `sending` mark, then writes. After a restart, queued jobs print in order, and a job caught mid-send shows `uncertain` and is never resent.
|
||||
1. Stages 1a-1d: measurements on leil-rig, the `[state] dir` key, the state machine without a database, then the SQLite store. Every job is stored when it is accepted. The worker renders, connects, commits a synced `sending` mark, then writes. After a restart, queued jobs print in order, and a job caught mid-send shows `uncertain` and is never resent.
|
||||
2. The API: `GET /api/v1/jobs` lists the history, job status shows `ref`, and `/healthz` counts the jobs found `uncertain` at the latest start. Phase 2b, cancelling, needs phase 1 but not phase 2: `DELETE /api/v1/jobs/{id}` cancels each delivery of a job that has not reached `sending`, and an ntfy `message_delete` cancels the waiting jobs of its notification and drops its held digest rows. A delivery that has reached `sending` goes on.
|
||||
3. Stages 3a-3c, the image preview: the preview routes answer `Accept: image/png` with a picture of the paper, drawn from the bytes the job renders to. They need nothing from phases 1 and 2.
|
||||
4. Previews of stored jobs: `GET /api/v1/jobs/{id}/preview` as text, JSON or PNG.
|
||||
@@ -435,7 +458,7 @@ type Store interface {
|
||||
- Restore before start: serve.go opens the store, which takes its lock, and the queue loads it before `group.Go` starts the worker, the server and the subscribers. So restored jobs go ahead of new ones, the sequence continues from the highest stored, restored statuses answer at once, and a second instance on the same directory fails before it reads the `ntfy-<name>.json` files.
|
||||
- `Load` returns no content, so a backlog of up to `queue.size` × 4 MiB is not read into memory at start; the worker reads each job's content when it takes it. A stored job that no longer passes strict `DecodeJob` (after a downgrade or a field change) then fails with an error, logged by `job_id`, and is never dropped silently. Its content is never logged.
|
||||
- `Durable()` decides shutdown: with a durable store, waiting jobs and a job that has not reached `sending` stay queued; with the memory store, shutdown is as today.
|
||||
- With SQLite's single connection, a `Submit` waits for its insert and may wait behind the worker's synced commit or a checkpoint. On an SD card that wait is unmeasured until stage 1a.
|
||||
- With SQLite's single connection, a `Submit` waits for its insert and may wait behind the worker's synced commit or a checkpoint. On leil-test-1's virtual disk, a synced commit took at most about 10 ms, and an insert that ran a checkpoint 10-24 ms. On an SD card that wait is unmeasured.
|
||||
- The `State` constants stay in queue.go, the one file printqueue's schema test parses; `StoredState` is a separate type in store.go.
|
||||
|
||||
RECORDS (SQLite, decision 1)
|
||||
@@ -475,7 +498,7 @@ CREATE TABLE refs ( -- unique jobs, for the duplicate check
|
||||
|
||||
- A job's own fields live in `jobs`, and each delivery's, those of one printer, in `deliveries`. Until the printers plan lands, every job has exactly one delivery, for the printer `default`. A multicast or broadcast job later gets one row per printer; an anycast job has one, whose `printer` the `sending` mark sets to the printer used (DELIVERIES AND SEVERAL PRINTERS).
|
||||
- The `jobs` row is written once, with its deliveries and its content in the insert's commit, and is deleted at pruning. A status update rewrites only its delivery's row.
|
||||
- IO: the split costs one more small row per job at insert, in the same commit. `deliveries` is a b-tree of its own, so an insert can change one page more than with one table. The findings' numbers were measured with one table; stage 1a's probe measures this schema.
|
||||
- IO: the split costs one more small row per job at insert, in the same commit. `deliveries` is a b-tree of its own, so an insert can change one page more than with one table. On leil-test-1 this schema appended 11.46 WAL frames per text job, against 14.35 in the SQLite track's runs with one table (Investigation findings).
|
||||
- Statuses are looked up in memory, so neither table needs an index on `id`, `state` or `job_seq`, and updates go by a delivery's `seq`. Each index left out is a b-tree fewer per insert. Pruning deletes a job's row and its deliveries' rows by their `seq`s, which the queue passes to `Finish`.
|
||||
- `Load` reads `deliveries` in `seq` order and attaches each row to its job by `job_seq` in memory.
|
||||
- `sequence` lets an ntfy `message_delete` find a waiting job after a restart too (phase 2b). It holds the topic and the sequence ID as `<topic>/<sequence ID>`, since ntfy's sequence IDs are per topic (`DELETE /<topic>/<sequence_id>`) and one subscription reads several topics; a topic name cannot hold `/`. It is written from stage 1d, so phase 2b needs no schema step and can cancel a job stored before it.
|
||||
@@ -490,7 +513,7 @@ CREATE TABLE refs ( -- unique jobs, for the duplicate check
|
||||
- A synced commit runs `PRAGMA synchronous=FULL`, commits, and restores NORMAL in a defer, so a failed statement never leaves the connection at FULL. `Sending`, `failed`, inserts of unique jobs and, from phase 2b, `cancelled` commit this way.
|
||||
- Open, in order: create the file 0600 if it is missing; set the pragmas; run `PRAGMA quick_check`, which only reads (the whole file, 2-48 MiB at the sizes in the findings), since SQLite otherwise finds a damaged page only when a statement reads it, mid-run; refuse a `user_version` newer than the binary knows, naming both; run each schema step in one synced transaction that also sets `user_version`; write once, so a second instance fails at once.
|
||||
- `Idle` runs `PRAGMA wal_checkpoint(PASSIVE)`.
|
||||
- `sqlite.Fdatasync(true)` on Linux, once stage 1a has shown that the unit's syscall filter allows `fdatasync`.
|
||||
- `sqlite.Fdatasync(true)` on Linux. The unit's syscall filter allows `fdatasync`, and on leil-test-1 it cut a synced commit's median from 5.0 to 2.9 ms with the same device writes and flushes (stage 1a).
|
||||
- Nothing else in the process opens the file, since any close drops SQLite's locks.
|
||||
- A test hook, an unexported function the package's own tests set, runs inside each commit and reads `PRAGMA synchronous`, so tests see which commits ran at FULL.
|
||||
|
||||
@@ -563,11 +586,13 @@ THE PREVIEW IMAGE (phase 3)
|
||||
|
||||
## Phases
|
||||
|
||||
### Stage 1a: Measurements on the owner's hardware
|
||||
### Stage 1a: Measurements on leil-rig
|
||||
|
||||
**Goal.** Measure on a Pi-class host with an SD card what the workstation cannot: device writes and flushes per job, the time of a synced commit and of a checkpoint, whether ARMv6 runs the store, and whether the unit's sandbox allows the calls the store makes.
|
||||
Done on 2026-12-01. The numbers are under Investigation findings, MEASURED ON LEIL-TEST-1.
|
||||
|
||||
**Work.** Nothing in the repository changes. The session writes a probe under the scratch directory, cross-compiles it, and gives the owner the binaries and the commands. The owner runs them, with his OK, never on the workstation.
|
||||
**Goal.** Measure on Linux what the workstation cannot: device writes and flushes per job, the time of a synced commit and of a checkpoint, and whether the unit's sandbox allows the calls the store makes. The owner has no ARM boards, so nothing runs on ARM hardware (decision 2).
|
||||
|
||||
**Work.** Nothing in the repository changes but this plan. The session writes a probe under the scratch directory and cross-compiles it. On the owner's word, it runs the probe itself on leil-test-1, leil-rig's test node, under the rig's lease (leil-rig's CLAUDE.md, The lease), never on the workstation.
|
||||
|
||||
The probe, `jobprobe`, one Go module outside the repository:
|
||||
- The store decision 1 chose, at the version stage 1d will pin. For SQLite: `modernc.org/sqlite` with its pinned libc, one connection, and the pragmas and schema under RECORDS (`jobs`, `deliveries`, `content` and `refs`), created fresh in `-dir`.
|
||||
@@ -578,19 +603,23 @@ The probe, `jobprobe`, one Go module outside the repository:
|
||||
- per job, the device's sectors written and flush requests, from `/sys/dev/block/<major>:<minor>/stat` for the device of `-dir`, read before and after, less an idle baseline taken over a minute first; this counts ext4's journal, which `/proc/self/io` misses;
|
||||
- `/proc/self/io` `write_bytes` per job;
|
||||
- the time of each FULL and each NORMAL commit: median, 99th percentile and maximum (the slowest include the automatic checkpoints);
|
||||
- the time of the final checkpoint, and the sizes of the database and the WAL.
|
||||
- Built with `CGO_ENABLED=0` for linux/arm (GOARM=6 and 7) and linux/arm64.
|
||||
- the time of the final checkpoint, and the sizes of the database and the WAL;
|
||||
- the WAL frames per job, read from the frame headers after each commit.
|
||||
- `-device` names the block device where the probe cannot find it, as on btrfs; behind LVM or dm-crypt it follows the device down to the disk, where the kernel counts flushes.
|
||||
- Built with `CGO_ENABLED=0` for linux/amd64.
|
||||
|
||||
On the owner's host, otherwise idle, since the device counters include every process's writes:
|
||||
1. Run it as a transient unit with the unit's sandbox, once with and once without `-fdatasync`: `systemd-run --wait --pipe -p DynamicUser=yes -p StateDirectory=jobprobe -p ProtectSystem=strict -p PrivateTmp=yes -p PrivateDevices=yes -p MemoryDenyWriteExecute=yes -p SystemCallFilter=@system-service -p SystemCallErrorNumber=EPERM -p SystemCallArchitectures=native ./jobprobe -dir /var/lib/jobprobe`. A call the filter refuses fails the run with EPERM, so this tests `fdatasync`, the file locks, `pwrite` and `ftruncate` for real.
|
||||
2. As a cross-check, `systemd-analyze syscall-filter @system-service` lists `fsync`, `fdatasync`, `fcntl`, `pwrite64` and `ftruncate`.
|
||||
3. The same on an ARMv6 board, if he has one (decision 2).
|
||||
On leil-test-1, otherwise idle, since the device counters include every process's writes:
|
||||
1. Install the binary as `/usr/local/bin/jobprobe`: `DynamicUser` cannot reach a home directory, and `PrivateTmp` hides `/tmp`.
|
||||
2. Run it as a transient unit with the unit's sandbox, once with and once without `-fdatasync`: `systemd-run --wait --pipe -p DynamicUser=yes -p StateDirectory=jobprobe -p ProtectSystem=strict -p PrivateTmp=yes -p PrivateDevices=yes -p MemoryDenyWriteExecute=yes -p SystemCallFilter=@system-service -p SystemCallErrorNumber=EPERM -p SystemCallArchitectures=native /usr/local/bin/jobprobe -dir /var/lib/jobprobe`. A call the filter refuses fails the run with EPERM, so this tests `fdatasync`, the file locks, `pwrite` and `ftruncate` for real.
|
||||
3. As a cross-check, `systemd-analyze syscall-filter` lists `fsync`, `fdatasync`, `fcntl`, `pwrite64` and `ftruncate` in the groups `@system-service` takes in (`@sync`, `@file-system`, `@basic-io`).
|
||||
4. `lsblk` and `systemd-detect-virt` record the disk.
|
||||
5. Remove the binary and `/var/lib/private/jobprobe`, and release the lease.
|
||||
|
||||
**Tests.** A 20-job run on the workstation (Windows, without device counters) shows that the probe works. Nothing heavier runs there.
|
||||
|
||||
**Done when.**
|
||||
- The owner has run the probe and reported its output, and the numbers are in Investigation findings.
|
||||
- If ARMv6 fails, or the numbers differ much from the findings, the owner has looked at decision 1 again.
|
||||
- The probe has run on leil-test-1, and its numbers are in Investigation findings.
|
||||
- If a call fails with EPERM, or the numbers differ much from the findings, the owner has looked at decision 1 again.
|
||||
|
||||
### Stage 1b: `[state] dir`
|
||||
|
||||
@@ -742,7 +771,7 @@ Docs
|
||||
- docs/configuration.md: a downgrade note.
|
||||
- docs/development.md: the layout (`internal/pkg/jobstore`, `tools/libcpin`), the `make check` steps, and "CI and releases", which says test.yml builds no binaries.
|
||||
- docs/api.md: job status (what survives a restart) and the `job_not_found` row.
|
||||
- CHANGELOG: under Added, jobs survive a restart; under **Breaking**, that with a state directory waiting jobs print after a restart instead of failing, and the Docker image's store (decision 14); the downgrade note.
|
||||
- CHANGELOG: under Added, jobs survive a restart, and the armv6, armv7 and arm64 builds ship the store untested on hardware (decision 2); under **Breaking**, that with a state directory waiting jobs print after a restart instead of failing, and the Docker image's store (decision 14); the downgrade note.
|
||||
- CLAUDE.md: the layout and the imports (jobstore → printqueue; internal/app → jobstore); the gate's new steps, and line 75's "It builds no binaries"; the libc exception beside the rule that dependencies are at their latest stable release.
|
||||
- docs/swagger.json regenerated, if anything changed.
|
||||
|
||||
@@ -767,7 +796,7 @@ internal/app/uberbringer
|
||||
Crash tests use fault injection like the above, never kill loops or soaks on the workstation.
|
||||
|
||||
**Done when.**
|
||||
- design.md records the owner's store choice, the sync policy and stage 1a's numbers, and armv6 ran on hardware, or the owner accepted it untested. If the owner agrees, the jobstore tests, cross-compiled with `go test -c` for GOARCH=arm GOARM=6, ran on his Pi.
|
||||
- design.md records the owner's store choice, the sync policy and stage 1a's numbers, and that the ARM builds ship the store untested on hardware (decision 2).
|
||||
- Paper, with the owner's OK, one short receipt at a time, waiting for his report after each:
|
||||
1. A receipt prints through the store and reads `done`, and still reads `done` after a restart.
|
||||
2. With the printer switched off, a receipt is sent, and the daemon is stopped while the log still shows `send failed, retrying`. With the printer on again, the daemon starts, and the receipt prints once.
|
||||
|
||||
Reference in new issue
Block a user