nx_dms_catalog_store.nx source
↩ module page · 41 lines · 1743 B
1// nx_dms_catalog_store.nx -- durability for the consent-gated media catalog.
2//
3// Mirrors nx_rights_ledger_store (rung 2): snapshot the fixed-size asset rows
4// through nx_seg_store (append-only, rename-commit crash safety) so the catalog
5// SURVIVES restart -- including soft-remove flags. Row count is derived from
6// the snapshot value length (no header).
7//
8// HONEST: the SEARCH index (nx_dms_search) holds text POINTERS, so persisting
9// it needs text-byte serialization -- a separate rung (flagged). The catalog
10// is the source of truth; search can be rebuilt from it + a metadata store.
11// license_tier: ORIGINAL
12
13import "nx_syscalls.nx"
14import "nx_dms_catalog.nx"
15import "nx_seg_store.nx"
16
17// Save the whole catalog as one append-only snapshot segment.
18func nx_dms_catalog_save(c: *NxDmsCatalog, prefix: *u8, segid: i64) -> i64 {
19 let w: *i64 = ss_begin()
20 let vbytes: i64 = (c.count as i64) * NX_DMS_ASSET_BYTES
21 ss_add(w, 1, "dms:catalog" as *u8, (c.assets as i64) as *u8, vbytes)
22 return ss_commit(prefix, w, segid)
23}
24
25// Reload the catalog from the store (simulated restart). Absent store -> empty.
26func nx_dms_catalog_load(prefix: *u8) -> *NxDmsCatalog {
27 let h: *i64 = ss_open(prefix)
28 let ptrout: *i64 = sys_mmap(16) as *i64
29 let lenout: *i64 = sys_mmap(16) as *i64
30 let rc: i64 = ss_hget(h, "dms:catalog" as *u8, ptrout, lenout)
31 if rc != 1 { return nx_dms_catalog_new(16) }
32 let blob: *u8 = ptrout[0] as *u8
33 let vbytes: i64 = lenout[0]
34 let n: nx_size = vbytes / NX_DMS_ASSET_BYTES
35 let c: *NxDmsCatalog = nx_dms_catalog_new(n + 16)
36 let dst: *u8 = (c.assets as i64) as *u8
37 var i: i64 = 0
38 while i < vbytes { dst[i] = blob[i]; i = i + 1 }
39 c.count = n
40 return c
41}