From 856ad79a02ba7d63ab582920da08923581d4db26 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 2 Nov 2025 12:58:10 +0300 Subject: [PATCH] Fix mark_completed_lsns for enabled fsyncs --- src/blockstore/blockstore_heap.cpp | 12 +++++++----- src/blockstore/blockstore_heap.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/blockstore/blockstore_heap.cpp b/src/blockstore/blockstore_heap.cpp index 11965a69..1cfc7041 100644 --- a/src/blockstore/blockstore_heap.cpp +++ b/src/blockstore/blockstore_heap.cpp @@ -1501,7 +1501,7 @@ void blockstore_heap_t::complete_block_write(uint32_t block_num) assert(!(it->flags & HEAP_INFLIGHT_DONE)); it->flags |= HEAP_INFLIGHT_DONE; } - mark_completed_lsns(); + mark_completed_lsns(mod_lsn); } } @@ -1938,7 +1938,7 @@ void blockstore_heap_t::push_inflight_lsn(uint64_t lsn, heap_entry_t *wr, uint64 } } -void blockstore_heap_t::mark_completed_lsns() +void blockstore_heap_t::mark_completed_lsns(uint64_t mod_lsn) { if (dsk->disable_meta_fsync && dsk->disable_journal_fsync) { @@ -1956,10 +1956,11 @@ void blockstore_heap_t::mark_completed_lsns() first_inflight_lsn++; } } - else + else if (mod_lsn == completed_lsn+1) { - // Only advanced completed_lsn - for (auto it = inflight_lsn.begin(); it != inflight_lsn.end() && (it->flags & HEAP_INFLIGHT_DONE); it++) + // Only advance completed_lsn + assert(inflight_lsn.size() > mod_lsn-first_inflight_lsn); + for (auto it = inflight_lsn.begin()+(mod_lsn-first_inflight_lsn); it != inflight_lsn.end() && (it->flags & HEAP_INFLIGHT_DONE); it++) { completed_lsn++; } @@ -1974,6 +1975,7 @@ void blockstore_heap_t::mark_lsn_fsynced(uint64_t lsn) assert(lsn <= completed_lsn); while (lsn >= first_inflight_lsn) { + assert(inflight_lsn.size() > 0); apply_inflight(inflight_lsn.front()); inflight_lsn.pop_front(); first_inflight_lsn++; diff --git a/src/blockstore/blockstore_heap.h b/src/blockstore/blockstore_heap.h index 470e6034..c2387144 100644 --- a/src/blockstore/blockstore_heap.h +++ b/src/blockstore/blockstore_heap.h @@ -207,7 +207,7 @@ class blockstore_heap_t void mark_garbage_up_to(heap_entry_t *wr); void mark_garbage(uint32_t block_num, heap_entry_t *prev_wr, uint32_t used_big); void push_inflight_lsn(uint64_t lsn, heap_entry_t *wr, uint64_t flags); - void mark_completed_lsns(); + void mark_completed_lsns(uint64_t mod_lsn); void apply_inflight(heap_inflight_lsn_t & inflight); public: blockstore_heap_t(blockstore_disk_t *dsk, uint8_t *buffer_area, int log_level = 0);