Add a SQLite job store that opens, checks and locks its file
Jobs are to survive a restart in a SQLite database, jobs.db in the state directory, through modernc.org/sqlite v1.64.0 (SQLite 3.54.1), the latest release, which is pure Go and builds with CGO_ENABLED=0. It requires modernc.org/libc at exactly v1.80.1, older than libc's latest; the owner accepted that pin as the one exception to taking dependencies at their latest stable release, and CLAUDE.md and design.md record it here. The other modules it brings are mathutil, memory, go-humanize, go-strftime and bigfft, at the versions it asks for; bigfft has no tagged release. The new package internal/pkg/jobstore opens the database in this order: - It creates the file 0600 if it is missing, since SQLite gives its log the database's mode. An existing file is never opened outside SQLite, since closing any descriptor of it would drop the locks the process holds. - The connection runs its pragmas, in this order: exclusive locking before the first read, so the log's index stays in memory and no -shm file is made; auto_vacuum NONE; WAL; synchronous NORMAL; temporary tables in memory; a 4 MiB journal_size_limit; secure_delete FAST. A connector runs them, since the driver's own _pragma list sorts them by name and would set the locking mode only after the first read, leaving a mapped -shm file on every open but the first. - PRAGMA quick_check reads every page, so a damaged file fails at start rather than when a statement meets the page mid-run. - A user_version newer than the binary's is refused, naming both. - Each schema step runs in one synced transaction that also sets user_version. Version 1 creates jobs, deliveries, content and refs. - It writes once, so a store that cannot be written fails at start and the file stays locked; a second Open of the directory, from any process, fails at once with SQLITE_BUSY. Every error from Open names the file. The URI escapes the path, so a directory with a space, "#", "?" or "%" in its name works. The store syncs with fdatasync where the platform has it, as on Linux. The lock test runs the second Open in a child process, the test binary run again, so the lock tested is the file system's. A test reopens the store three times and finds no -shm file and exclusive locking each time. Nothing uses the store yet. Part of stage 1d of docs/plans/job-store.md (decisions 1, 3 and 13). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
60baa843ef
commit
6e47cb713e
8 files changed
+648
No files matched your search
@@ -297,6 +297,11 @@ client ─HTTPS─▶ Caddy ─▶ server ── validate ──▶ printqueue (
|
||||
and in the file a name with a dot or a nested table is an unknown key.
|
||||
- `go.mod`'s go line is the latest Go release, with no separate toolchain
|
||||
line.
|
||||
- **Stack choices (owner, 2026-12-01):**
|
||||
- `modernc.org/libc` is the one module held below its latest release. It
|
||||
stays at the exact version `modernc.org/sqlite` requires, since the
|
||||
driver is C transpiled to Go against that libc and works with it alone,
|
||||
and moves only with the driver.
|
||||
- **Packaging.** The daemon serves no TLS itself and binds 127.0.0.1 by
|
||||
default; a reverse proxy in front terminates HTTPS and sets `X-Real-IP`.
|
||||
- The release tarballs are built for linux amd64, armv6, armv7 and arm64.
|
||||
|
||||
@@ -99,6 +99,7 @@ internal/pkg/raster/ Image decoding, scaling and dithering
|
||||
internal/pkg/safehttp/ SSRF-guarded image fetching
|
||||
internal/pkg/printer/ TCP printer client (port 9100) and status queries
|
||||
internal/pkg/printqueue/ Job queue, worker and status history
|
||||
internal/pkg/jobstore/ The job store on disk: one SQLite database, through modernc.org/sqlite
|
||||
configs/ Example configuration
|
||||
examples/ Example jobs, such as the block calibration receipt
|
||||
packaging/ systemd unit
|
||||
|
||||
Reference in new issue
Block a user