mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 06:32:30 +02:00
LibSQL: Redesign heap storage to support arbitrary amounts of data
Previously, `Heap` would store serialized data in blocks of 1024 bytes regardless of the actual length. Data longer than 1024 bytes was silently truncated causing database corruption. This changes the heap storage to prefix every block with two new fields: the total data size in bytes, and the next block to retrieve if the data is longer than what can be stored inside a single block. By chaining blocks together, we can store arbitrary amounts of data without needing to change anything of the logic in the rest of LibSQL. As part of these changes, the "free list" is also removed from the heap awaiting an actual implementation: it was never used. Note that this bumps the database version from 3 to 4, and as such invalidates (deletes) any database opened with LibSQL that is not version 4.
This commit is contained in:
committed by
Tim Flynn
parent
194f846f12
commit
6601ff9d65
Notes:
sideshowbarker
2024-07-16 22:51:10 +09:00
Author: https://github.com/gmta Commit: https://github.com/SerenityOS/serenity/commit/6601ff9d65 Pull-request: https://github.com/SerenityOS/serenity/pull/18476 Reviewed-by: https://github.com/trflynn89 ✅
@@ -51,7 +51,7 @@ void DownPointer::deserialize(Serializer& serializer)
|
||||
{
|
||||
if (m_node || !m_pointer)
|
||||
return;
|
||||
serializer.get_block(m_pointer);
|
||||
serializer.read_storage(m_pointer);
|
||||
m_node = serializer.make_and_deserialize<TreeNode>(m_owner->tree(), m_owner, m_pointer);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ TreeNode::TreeNode(BTree& tree, TreeNode* up, DownPointer& left, u32 pointer)
|
||||
m_down.append(DownPointer(this, left));
|
||||
m_is_leaf = left.pointer() == 0;
|
||||
if (!pointer)
|
||||
set_pointer(m_tree.new_record_pointer());
|
||||
set_pointer(m_tree.request_new_block_index());
|
||||
}
|
||||
|
||||
TreeNode::TreeNode(BTree& tree, TreeNode* up, TreeNode* left, u32 pointer)
|
||||
@@ -271,7 +271,7 @@ void TreeNode::just_insert(Key const& key, TreeNode* right)
|
||||
m_entries.insert(ix, key);
|
||||
VERIFY(is_leaf() == (right == nullptr));
|
||||
m_down.insert(ix + 1, DownPointer(this, right));
|
||||
if (length() > Heap::BLOCK_SIZE) {
|
||||
if (length() > Block::DATA_SIZE) {
|
||||
split();
|
||||
} else {
|
||||
dump_if(SQL_DEBUG, "To WAL");
|
||||
@@ -283,7 +283,7 @@ void TreeNode::just_insert(Key const& key, TreeNode* right)
|
||||
m_entries.append(key);
|
||||
m_down.empend(this, right);
|
||||
|
||||
if (length() > Heap::BLOCK_SIZE) {
|
||||
if (length() > Block::DATA_SIZE) {
|
||||
split();
|
||||
} else {
|
||||
dump_if(SQL_DEBUG, "To WAL");
|
||||
|
||||
Reference in New Issue
Block a user