1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:48:11 +00:00

LibSQL: Implement freeing heap storage

This allows us to free entire chains of blocks in one go.
This commit is contained in:
Jelle Raaijmakers 2023-05-24 15:48:53 +02:00 committed by Tim Flynn
parent d7bbb8d64a
commit c58c87d7ef
3 changed files with 40 additions and 5 deletions

View file

@ -154,11 +154,8 @@ ErrorOr<void> Heap::write_storage(Block::Index index, ReadonlyBytes data)
}
// Free remaining blocks in existing chain, if any
while (existing_next_block_index > 0) {
auto existing_block = TRY(read_block(existing_next_block_index));
existing_next_block_index = existing_block.next_block();
TRY(free_block(existing_block));
}
if (existing_next_block_index > 0)
TRY(free_storage(existing_next_block_index));
return {};
}
@ -235,6 +232,19 @@ ErrorOr<void> Heap::write_block(Block const& block)
return write_raw_block_to_wal(block.index(), move(heap_data));
}
ErrorOr<void> Heap::free_storage(Block::Index index)
{
dbgln_if(SQL_DEBUG, "{}({})", __FUNCTION__, index);
VERIFY(index > 0);
while (index > 0) {
auto block = TRY(read_block(index));
TRY(free_block(block));
index = block.next_block();
}
return {};
}
ErrorOr<void> Heap::free_block(Block const& block)
{
auto index = block.index();