mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:37:45 +00: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:
parent
194f846f12
commit
6601ff9d65
13 changed files with 246 additions and 180 deletions
|
@ -82,7 +82,7 @@ private:
|
|||
HashIndex(Serializer&, NonnullRefPtr<TupleDescriptor> const&, u32);
|
||||
|
||||
void expand();
|
||||
void write_directory_to_write_ahead_log();
|
||||
void write_directory();
|
||||
HashBucket* append_bucket(u32 index, u32 local_depth, u32 pointer);
|
||||
HashBucket* get_bucket_for_insert(Key const&);
|
||||
[[nodiscard]] HashBucket* get_bucket_by_index(u32 index);
|
||||
|
@ -104,7 +104,7 @@ public:
|
|||
void serialize(Serializer&) const;
|
||||
[[nodiscard]] u32 number_of_pointers() const { return min(max_pointers_in_node(), m_hash_index.size() - m_offset); }
|
||||
[[nodiscard]] bool is_last() const { return m_is_last; }
|
||||
static constexpr size_t max_pointers_in_node() { return (Heap::BLOCK_SIZE - 3 * sizeof(u32)) / (2 * sizeof(u32)); }
|
||||
static constexpr size_t max_pointers_in_node() { return (Block::DATA_SIZE - 3 * sizeof(u32)) / (2 * sizeof(u32)); }
|
||||
|
||||
private:
|
||||
HashIndex& m_hash_index;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue