From 4dfb80e6a11e2dc634ed28b1bb1fab46efdcebe0 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sat, 19 Jul 2025 23:12:48 +0300 Subject: [PATCH] Collapse intent_writes on other write types too --- src/blockstore/blockstore_heap.cpp | 8 +++++--- src/test/test_heap.cpp | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/blockstore/blockstore_heap.cpp b/src/blockstore/blockstore_heap.cpp index e89890d3..de1c96e7 100644 --- a/src/blockstore/blockstore_heap.cpp +++ b/src/blockstore/blockstore_heap.cpp @@ -1391,12 +1391,14 @@ int blockstore_heap_t::update_object(uint32_t block_num, heap_object_t *obj, hea used_delta -= free_writes(first_wr, NULL); new_wr->next_pos = 0; } - else if ((wr->flags & BS_HEAP_TYPE) == BS_HEAP_INTENT_WRITE && - (first_wr->flags & BS_HEAP_TYPE) == BS_HEAP_INTENT_WRITE) + else if ((first_wr->flags & BS_HEAP_TYPE) == BS_HEAP_INTENT_WRITE && + first_wr->can_be_collapsed(this)) { - // FIXME: All other types of writes should also purge&merge the intent write auto second_wr = first_wr->next(); second_wr->version = first_wr->version; + second_wr->len = (first_wr->offset+first_wr->len > second_wr->offset+second_wr->len ? first_wr->offset+first_wr->len : second_wr->offset+second_wr->len); + second_wr->offset = first_wr->offset < second_wr->offset ? first_wr->offset : second_wr->offset; + second_wr->len -= second_wr->offset; bitmap_set(second_wr->get_int_bitmap(this), first_wr->offset, first_wr->len, dsk->bitmap_granularity); if (dsk->csum_block_size) { diff --git a/src/test/test_heap.cpp b/src/test/test_heap.cpp index ba54a440..b053ffa2 100644 --- a/src/test/test_heap.cpp +++ b/src/test/test_heap.cpp @@ -1536,6 +1536,8 @@ void test_intent_write(bool csum) assert(obj); assert(count_writes(obj) == 2); // intent overwrites previous intent assert(obj->get_writes()->lsn == 3); + assert(obj->get_writes()->next()->offset == 0); + assert(obj->get_writes()->next()->len == 12288); uint8_t ref_int_bitmap[dsk.clean_entry_bitmap_size]; memset(ref_int_bitmap, 0, dsk.clean_entry_bitmap_size);