Fix iterate_compaction for commit with non-latest version

This commit is contained in:
Vitaliy Filippov
2025-12-02 01:52:12 +03:00
parent b772a3cd04
commit 4e0b203552
4 changed files with 65 additions and 9 deletions
+47
View File
@@ -470,6 +470,52 @@ void test_compact(bool csum, bool stable)
printf("OK test_compact %s %s\n", stable ? "stable" : "unstable", csum ? "csum" : "no_csum");
}
void test_iterate_compaction()
{
int res;
blockstore_disk_t dsk;
_test_init(dsk, false);
std::vector<uint8_t> buffer_area(dsk.journal_device_size);
{
blockstore_heap_t heap(&dsk, buffer_area.data());
heap.finish_load();
// Case: BIG_STABLE(v1 l1) -> SMALL(v2 l2) -> SMALL(v3 l3) -> SMALL(v4 l4) -> COMMIT(v2 l5) -> SMALL(v5 l6) -> COMMIT(v5 l7)
uint32_t mblock = 0;
_test_big_write(heap, dsk, 1, 0, 1, 0, true, 0, 4096, buffer_area.data());
_test_small_write(heap, dsk, 1, 0, 2, 0, 4096, 0, false, buffer_area.data(), false);
_test_small_write(heap, dsk, 1, 0, 3, 4*1024, 4096, 4096, false, buffer_area.data(), false);
_test_small_write(heap, dsk, 1, 0, 4, 8*1024, 4096, 8*1024, false, buffer_area.data(), false);
object_id oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 0 };
auto obj = heap.read_entry(oid);
res = heap.add_commit(obj, 2, &mblock);
assert(res == 0);
heap.start_block_write(mblock);
heap.complete_block_write(mblock);
_test_small_write(heap, dsk, 1, 0, 5, 12*1024, 4096, 12*1024, false, buffer_area.data(), false);
obj = heap.read_entry(oid);
res = heap.add_commit(obj, 5, &mblock);
assert(res == 0);
heap.start_block_write(mblock);
heap.complete_block_write(mblock);
assert(heap.get_fsynced_lsn() == 7);
int small_writes = 0;
obj = heap.read_entry(oid);
auto compact_info = heap.iterate_compaction(obj, heap.get_fsynced_lsn(), false, [&](heap_entry_t *wr)
{
small_writes++;
});
assert(compact_info.compact_lsn == 7);
assert(compact_info.compact_version == 5);
assert(compact_info.clean_wr->lsn == 1);
assert(small_writes == 4);
}
printf("OK test_iterate_compaction\n");
}
void test_modify_bitmap()
{
blockstore_disk_t dsk;
@@ -1167,6 +1213,7 @@ int main(int narg, char *args[])
test_compact(true, false);
test_compact(false, true);
test_compact(false, false);
test_iterate_compaction();
test_modify_bitmap();
test_recheck(false, true, false);
test_recheck(false, false, false);