From 1fe79ff934fad19debb1eecc84692b5f4b8451d1 Mon Sep 17 00:00:00 2001 From: Rongsong Shen Date: Thu, 7 May 2026 10:04:43 +0000 Subject: [PATCH] fix: check rotate_segment return value; use uint32_t for CRC fields - In persist_wal_async(), check rotate_segment() return value and propagate -EIO on failure (MEDIUM) - Change last_crc and last_replicated_crc fields from uint64_t to uint32_t to match CRC32 width (LOW) Both fixes address code review issues in commit b0a5fbb. --- src/controller/persist.c | 8 ++++++-- src/include/persist.h | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/controller/persist.c b/src/controller/persist.c index e39aad5..76e3e64 100644 --- a/src/controller/persist.c +++ b/src/controller/persist.c @@ -256,8 +256,12 @@ int persist_wal_async(persist_t* p, uint32_t type, p->last_replicated_crc = hdr.crc; /* Rotate segment when full */ - if (p->seg_offset >= WAL_SEGMENT_SIZE_BYTES) - rotate_segment(p); + if (p->seg_offset >= WAL_SEGMENT_SIZE_BYTES) { + if (rotate_segment(p) != 0) { + pthread_mutex_unlock(&p->lock); + return -EIO; + } + } pthread_mutex_unlock(&p->lock); return 0; diff --git a/src/include/persist.h b/src/include/persist.h index f139ad8..4d8af2b 100644 --- a/src/include/persist.h +++ b/src/include/persist.h @@ -89,8 +89,8 @@ struct persist_s { /* WAL state */ int wal_fd; uint64_t current_lsn; - uint64_t last_crc; - uint64_t last_replicated_crc; + uint32_t last_crc; + uint32_t last_replicated_crc; uint64_t term; uint32_t seg_offset; uint64_t checkpoint_lsn;