code wiki / _hdl_build / nx_hr_migrate.nx

nx_hr_migrate.nx source

↩ module page · 46 lines · 2980 B

1// nx_hr_migrate.nx -- the LOSSLESS migrator the torrent/HR teams need for THEIR base-nx_hr cutover (operator: "if they 2// dont have the capabilities work with them to build them from the hardware rung up"). Reads an existing nx_hr TAB-log 3// (cred_id<TAB>handle<TAB>level<TAB>family<TAB>status<TAB>ts<TAB>actor, append-only) and replays EVERY line through 4// hrs_migrate into a sovereign nx_seg_store -- so ALL versions (history) survive and latest-wins is preserved. Pure 5// library (no main -> no duplicate-symbol when a gate/tool imports it). IDEMPOTENT (hrs_migrate auto-segids by content, 6// re-running a record is a no-op). This is the de-risking tool: prove it lossless (nx_hr_migrate_gate), hand it to the 7// team, they flip base nx_hr -> seg_store + run this on their live roles store at cutover. [[feedback-no-3rd-party-tsv-sovereign-store]] 8import "nx_hr.nx" // hr_read / hr_line_end / hr_field_end / hr_intrange (parse the TAB-log) 9import "nx_hr_sov.nx" // hrs_migrate (write the seg_store) 10import "nx_syscalls.nx" 11 12const HRM_BUF: i64 = 1048576 13 14func hrm_dup(buf: *u8, start: i64, len: i64, out: *u8) -> i64 { var i: i64=0; while i<len { out[i]=buf[start+i]; i=i+1 } out[len]=0 as u8; return len } 15 16// migrate every record in the nx_hr TAB-log at logpath into the seg_store at prefix; returns the count migrated. 17func hrm_migrate(logpath: *u8, prefix: *u8) -> i64 { 18 let buf: *u8 = sys_mmap(HRM_BUF); let n: i64 = hr_read(logpath, buf, HRM_BUF) 19 var migrated: i64 = 0; var i: i64 = 0 20 let cred: *u8=sys_mmap(96); let handle: *u8=sys_mmap(128); let family: *u8=sys_mmap(128) 21 let status: *u8=sys_mmap(32); let actor: *u8=sys_mmap(128) 22 while i < n { 23 let le: i64 = hr_line_end(buf, i, n) 24 let f0e: i64 = hr_field_end(buf, i, le) // cred_id 25 if (f0e - i) == 64 { 26 let f1s: i64=f0e+1; let f1e: i64=hr_field_end(buf, f1s, le) // handle 27 let f2s: i64=f1e+1; let f2e: i64=hr_field_end(buf, f2s, le) // level 28 let f3s: i64=f2e+1; let f3e: i64=hr_field_end(buf, f3s, le) // family 29 let f4s: i64=f3e+1; let f4e: i64=hr_field_end(buf, f4s, le) // status 30 let f5s: i64=f4e+1; let f5e: i64=hr_field_end(buf, f5s, le) // ts 31 let f6s: i64=f5e+1; var f6e: i64=le // actor (to EOL) 32 if f6e > f6s { if buf[f6e-1]==(13 as u8) { f6e=f6e-1 } } // strip a trailing CR 33 hrm_dup(buf, i, 64, cred) 34 hrm_dup(buf, f1s, f1e-f1s, handle) 35 let level: i64 = hr_intrange(buf, f2s, f2e) 36 hrm_dup(buf, f3s, f3e-f3s, family) 37 hrm_dup(buf, f4s, f4e-f4s, status) 38 let ts: i64 = hr_intrange(buf, f5s, f5e) 39 hrm_dup(buf, f6s, f6e-f6s, actor) 40 hrs_migrate(prefix, cred, handle, level, family, status, ts, actor) 41 migrated = migrated + 1 42 } 43 i = le + 1 44 } 45 return migrated 46}