mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-27 21:14:21 +01:00
Problem: A very easy source of bugs is to mistakenly use e.g. PageContent::read_u16() instead of PageContent::read_u16_no_offset(). The difference between the two is that `read_u16()` adds 100 bytes to the requested byte offset if and only if the page in question is page 1, which contains a 100-byte database header. Case in point: see #2491. Observation: In all of the cases where we want to read from or write to a page "header-sensitively", those reads/writes are to so-called "well known offsets", e.g. specific bytes in a btree page header. In all other cases, the "no-offset" versions, i.e. the ones taking the absolute byte offset as parameter, should be used. Solution: 1. Make all the offset-sensitive versions (read_u16() and friends) private methods of `PageContent`. 2. Expose dedicated methods for things like updating rightmost pointer, updating fragmented bytes count and so on, and use them instead of the plain read/write methods universally.