code wiki / _hdl_build / nx_store_janitor_beat.nx

nx_store_janitor_beat.nx

buildroot/runtime/_hdl_build/nx_store_janitor_beat.nx

7740 B179 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic store
docsdependenciesstructsconstsfunctions

about

nx_store_janitor_beat.nx -- standing reclamation of SUPERSEDED seg-store segment files. WHY A BEAT AND NOT A ONE-SHOT: on 2026-07-30 a single manual sweep moved 57,348 MB across 336 planes (14,585 live segment .docs down to 2,973). Within the SAME session debt- went from 1 segment back to 18 and down again as siblings wrote and compacted. The seg-store is append-only and every commit writes a NEW segment, so superseded files re-accumulate CONTINUOUSLY. A cleanup that has to be remembered is a workaround; the fix is a standing sweep row that keeps the property true without anyone noticing. SIBLING TO nx_store_fold_beat AND DELIBERATELY ORDERED AFTER IT: fold_beat MERGES a bloated plane (segment COUNT / scan cost), which by construction supersedes the segments it merged. This beat then reclaims those files (disk / directory hygiene). Fold makes garbage; janitor takes it out. Neither replaces the other. Forks the proven ./nx_store_janitor.elf per plane exactly as fold_beat forks nx_store_compact -- the worker owns the safety argument (manifest IS the definition of live, REFUSES on an unreadable manifest, moves aside into retired/ and never unlinks, and re-reads the manifest afterwards to restore anything a concurrent writer made live mid-walk). This beat adds discovery and aggregation ONLY; it must not re-implement policy. Sweep-row contract: exit 0 = every plane reclaimed or already clean; exit 1 = a plane REFUSED (unknown live set) or a live segment was moved and restored -- surfaced RED, never silent. license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_tool_run.nx nx_store_janitor_beat.nx

imports: nx_syscalls.nxnx_tool_run.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap sys_openat_rd jb_puts sys_write jb_len sys_getdents64 dirent_reclen dirent_name jb_ends_manifest jb_len ↻ jb_len ↻ tr_run_capture sys_mmap ↻ sys_pipe2 sys_fork sys_close sys_dup3 sys_execve_clean sys_close ↻ sys_execve sys_exit sys_read sys_wait4 wait_exit_code jb_field jb_len ↻ sys_munmap sys_close ↻ jb_putn sys_mmap ↻ sys_write ↻ sys_munmap ↻

structs

none

consts

24const JB_DIRBUF: i64 = 262144
25const JB_PATHCAP: i64 = 1024
26const JB_OUTCAP: i64 = 65536
27const JB_STORE: *u8 = "knowledge/store" as *u8
28const JB_JANITOR: *u8 = "./nx_store_janitor.elf" as *u8
29const JB_MANI: *u8 = "manifest.txt" as *u8
30const JB_MANILEN: i64 = 12
31const JB_STDOUT: i64 = 1
32const JB_NL: i64 = 10
33const JB_AVCAP: i64 = 40

functions

35func jb_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
36func jb_puts(s: *u8) -> i64 { sys_write(JB_STDOUT, s, jb_len(s)); return 0 }
called by 1: main calls 2: sys_writejb_len
37func jb_putn(v: i64) -> i64
called by 1: main calls 3: sys_mmapsys_writesys_munmap
54func jb_ends_manifest(nm: *u8) -> i64
called by 1: main calls 1: jb_len
73func jb_field(buf: *u8, n: i64, key: *u8) -> i64
called by 1: main calls 1: jb_len
106func main(argc: i64, argv: *i64) -> i64