From db458fc999d69a6e655b2cdb742b7e099fd1a2ff Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Fri, 11 Jul 2025 02:12:41 +0300 Subject: [PATCH] Allow to cancel compaction for unfinished writes --- src/blockstore/blockstore_heap.cpp | 12 ++++++++---- src/blockstore/blockstore_heap.h | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/blockstore/blockstore_heap.cpp b/src/blockstore/blockstore_heap.cpp index 3b431cef..f0e10c93 100644 --- a/src/blockstore/blockstore_heap.cpp +++ b/src/blockstore/blockstore_heap.cpp @@ -1249,7 +1249,7 @@ void blockstore_heap_t::mark_overwritten(uint64_t over_lsn, uint64_t inode, heap { if (wr->needs_compact(0)) { - mark_lsn_compacted(wr->lsn); + mark_lsn_compacted(wr->lsn, true); } if ((wr->flags & BS_HEAP_TYPE) == BS_HEAP_BIG_WRITE) { @@ -1676,8 +1676,12 @@ void blockstore_heap_t::erase_object(uint32_t block_num, heap_object_t *obj, uin if (!lsn) { for (auto wr = obj->get_writes(); wr; wr = wr->next()) + { if (wr->needs_compact(0)) - mark_lsn_compacted(wr->lsn); + { + mark_lsn_compacted(wr->lsn, true); + } + } free_object_space(obj->inode, obj->get_writes(), NULL); } else @@ -1979,11 +1983,11 @@ void blockstore_heap_t::mark_lsn_fsynced(uint64_t lsn) } } -void blockstore_heap_t::mark_lsn_compacted(uint64_t lsn) +void blockstore_heap_t::mark_lsn_compacted(uint64_t lsn, bool allow_undone) { assert(lsn >= first_inflight_lsn && lsn < first_inflight_lsn+inflight_lsn.size()); auto & item = inflight_lsn[lsn - first_inflight_lsn]; - assert(item.flags & HEAP_INFLIGHT_DONE); + assert((item.flags & HEAP_INFLIGHT_DONE) || allow_undone); if (!(item.flags & HEAP_INFLIGHT_COMPACTABLE)) return; item.flags -= HEAP_INFLIGHT_COMPACTABLE; diff --git a/src/blockstore/blockstore_heap.h b/src/blockstore/blockstore_heap.h index 31335dd4..adbac662 100644 --- a/src/blockstore/blockstore_heap.h +++ b/src/blockstore/blockstore_heap.h @@ -253,7 +253,7 @@ public: // inflight write tracking void mark_lsn_completed(uint64_t lsn); void mark_lsn_fsynced(uint64_t lsn); - void mark_lsn_compacted(uint64_t lsn); + void mark_lsn_compacted(uint64_t lsn, bool allow_undone = false); void mark_object_compacted(heap_object_t *obj, uint64_t max_lsn); void mark_lsn_trimmed(uint64_t lsn); uint64_t get_completed_lsn();