feat: persist.c WAL writer with chained CRC32 and dedicated fsync pthread (P0-1)

- Expose persist_t struct concretely in persist.h (opaque pattern deferred)
- persist_set_workdir() derives wal/snap paths from workdir+name
- persist_init() creates WAL/snap directories, rejects NFS mounts
- persist_wal_async() writes WAL entries with chained CRC32 via zlib
- Dedicated fsync pthread fires every wal_sync_ms milliseconds
- persist_flush() forces fdatasync for tests and clean shutdown
- WAL_CHECKPOINT type rejected with -EINVAL (never written via async path)
- Stubs: persist_recover, persist_wal_sync_append, persist_checkpoint
- Add fsync_thread_running flag to guard persist_stop when thread not started
- Add zlib_dep to controller and unit test meson targets
- 3 new TDD tests: init_creates_directories, wal_async_writes_entry,
  checkpoint_type_rejected — all GREEN
This commit is contained in:
Rongsong Shen 2026-05-07 10:00:10 +00:00
parent d66a8a98b6
commit b0a5fbb4e9
5 changed files with 502 additions and 2 deletions

View file

@ -16,6 +16,7 @@ controller_src = [
'worker.c',
'apiserver.c',
'myconf.c',
'persist.c',
]
incdir = include_directories('.', '../include', '../lib',
@ -24,13 +25,16 @@ incdir = include_directories('.', '../include', '../lib',
# cc = meson.get_compiler('c')
# math_dep = cc.find_library('m', required : false)
zlib_dep = dependency('zlib')
controller_deps = [
libxce_dep,
librtti_dep,
c_capnproto_dep,
math_dep,
tinylog_dep,
thread_dep
thread_dep,
zlib_dep,
]
controller = executable('xce_controller',
@ -65,12 +69,16 @@ xce_test = executable('xce_test',
controller_unit_test_src = [
'testsuite/controller_test.c',
'testsuite/test_persist_types.c',
'testsuite/test_persist_wal.c',
'persist.c',
]
controller_unit_test_deps = [
libxce_dep,
unity_dep,
tinylog_dep,
thread_dep,
zlib_dep,
]
controller_unit_test = executable('controller_unit_test',