nx_index_wr_decouple.nx source
↩ module page · 15 lines · 1494 B
1// nx_index_wr_decouple.nx -- LIB: WRITE-READ DECOUPLING (LSM/Lucene near-real-time model). The ingest (WRITE) path
2// builds NEW immutable segments and advances a GENERATION; the query (READ) path serves a pinned generation SNAPSHOT.
3// Because segments are append-only + immutable (nx_seg_store), a reader pinned at generation G sees exactly the
4// segments committed <= G, UNAFFECTED by concurrent writers adding gen G+1, G+2... So ingest never blocks or corrupts
5// in-flight queries -- the property that lets the NAS ingest Common Crawl continuously while the site keeps serving.
6// Models the seg_store manifest/generation semantics; live concurrency + seg_store wiring is the scale step. No float.
7// license_tier: ORIGINAL
8import "nx_syscalls.nx"
9
10// commit one immutable segment -> advance the generation. nseg_box[0] = committed count = current generation.
11func wr_commit(nseg_box: *i64) -> i64 { nseg_box[0] = nseg_box[0] + 1; return nseg_box[0] }
12// segment ids VISIBLE to a reader pinned at snapshot_gen (append-only -> segments 0..gen-1). returns count.
13func wr_visible(snapshot_gen: i64, out: *i64) -> i64 { var i: i64 = 0; while i < snapshot_gen { out[i] = i; i = i + 1 } return snapshot_gen }
14// snapshot-consistent read: aggregate over ONLY the segments visible at snapshot_gen (later commits are invisible).
15func wr_query(seg_doccount: *i64, snapshot_gen: i64) -> i64 { var s: i64 = 0; var i: i64 = 0; while i < snapshot_gen { s = s + seg_doccount[i]; i = i + 1 } return s }