code wiki / (root) / nx_crdt_sync.nx

nx_crdt_sync.nx

buildroot/runtime/nx_crdt_sync.nx

2692 B60 linesdepth 3pulls 4 transitivereach 1 importersview sourcekind librarytopic crdt
docsdependenciesstructsconstsfunctions

about

nx_crdt_sync.nx -- CRDT SYNC op-log: the rung that makes two replicas MERGE instead of collide. Each edit is recorded as an op record (kind, id, value, ref) in an append-only log; a replica APPLIES any op-log (its own or a peer's) into a sequence-CRDT doc. Because apply is idempotent + order-independent (the CRDT property), two actors that each make edits, then exchange logs and apply the union, CONVERGE to the identical document -- with BOTH sets of edits present. This is the operational answer to "two Claude sessions edited the same file": no lock, no rejection, no lost edit. Composes nx_crdt_seq + nx_lamport_clock. 100% integer. license_tier: ORIGINAL

dependencies 3 imports · 1 importers

nx_syscalls.nx nx_crdt_seq.nx nx_lamport_clock.nx nx_crdt_sync.nx nx_crdt_sync_gate.nx

imports: nx_syscalls.nxnx_crdt_seq.nxnx_lamport_clock.nx

imported by: nx_crdt_sync_gate.nx

structs

none

consts

11const OPLOG_MAX: i64 = 1024

functions

14func op_rec(log: *i64, i: i64) -> *i64 { return (log as i64 + (1 + i*6)*8) as *i64 }
16func oplog_new() -> *i64
called by 1: main calls 1: sys_mmap
21func oplog_count(log: *i64) -> i64 { return log[0] }
23func oplog_append(log: *i64, kind: i64, idc: i64, ida: i64, value: i64, refc: i64, refa: i64) -> i64
called by 2: sync_insertsync_delete calls 1: op_rec
34func sync_insert(doc: *i64, log: *i64, clk: *i64, value: i64, refc: i64, refa: i64) -> i64
41func sync_delete(doc: *i64, log: *i64, clk: *i64, idc: i64, ida: i64) -> i64
49func sync_apply_log(doc: *i64, clk: *i64, log: *i64) -> i64