nx_mvault_reclaim.nx source
↩ module page · 55 lines · 2388 B
1// nx_mvault_reclaim.nx -- storage VALUE / RECLAMATION engine.
2//
3// WHY (operator 2026-07-17): "i saved too much large media so we want to see
4// if there is value or if we can recover terabytes."
5//
6// The CID content-address gives EXACT DEDUP for free: two saved copies of the
7// same bytes => the same nxc1-sha256 CID. During the in-place migrate the
8// reindexer asks the seg-store whether a CID already exists (mv_store_get); if
9// so the second copy is a DUPLICATE whose bytes are RECLAIMABLE (keep one).
10// This is the streaming accumulator over that signal + a large-file surfacer
11// for value review. It only MEASURES -- actual reclamation is a separate,
12// confirmed, soft-delete/quarantine op (rule 13 never-lose; nothing auto-deletes).
13//
14// license_tier: ORIGINAL
15import "nx_syscalls.nx"
16
17const RC_TOTAL: i64 = 0 // items seen
18const RC_UNIQUE: i64 = 1 // distinct CIDs (kept)
19const RC_DUP: i64 = 2 // duplicate copies (reclaimable)
20const RC_TOTBYTES: i64 = 3 // bytes of the kept/unique set
21const RC_RECLAIM: i64 = 4 // bytes recoverable (duplicate copies)
22const RC_LARGE: i64 = 5 // kept items >= large_thresh
23const RC_LARGEBYTES: i64 = 6 // bytes held in large kept items
24const RC_NFIELDS: i64 = 7
25
26func mv_reclaim_new() -> *i64 {
27 let st: *i64 = sys_mmap(8 * RC_NFIELDS) as *i64
28 var i: i64 = 0
29 while i < RC_NFIELDS { st[i] = 0; i = i + 1 }
30 return st
31}
32
33// account one item. is_dup=1 when its CID already exists in the store.
34func mv_reclaim_add(st: *i64, size: i64, is_dup: i64, large_thresh: i64) -> i64 {
35 st[RC_TOTAL] = st[RC_TOTAL] + 1
36 if is_dup == 1 {
37 st[RC_DUP] = st[RC_DUP] + 1
38 st[RC_RECLAIM] = st[RC_RECLAIM] + size
39 return 0
40 }
41 st[RC_UNIQUE] = st[RC_UNIQUE] + 1
42 st[RC_TOTBYTES] = st[RC_TOTBYTES] + size
43 if size >= large_thresh {
44 st[RC_LARGE] = st[RC_LARGE] + 1
45 st[RC_LARGEBYTES] = st[RC_LARGEBYTES] + size
46 }
47 return 0
48}
49
50func mv_reclaim_total(st: *i64) -> i64 { return st[RC_TOTAL] }
51func mv_reclaim_unique(st: *i64) -> i64 { return st[RC_UNIQUE] }
52func mv_reclaim_dupcount(st: *i64) -> i64 { return st[RC_DUP] }
53func mv_reclaim_reclaimable(st: *i64) -> i64 { return st[RC_RECLAIM] }
54func mv_reclaim_large(st: *i64) -> i64 { return st[RC_LARGE] }
55func mv_reclaim_largebytes(st: *i64) -> i64 { return st[RC_LARGEBYTES] }