Commit graph

27 commits

Author SHA1 Message Date
Pere Diaz Bou
dd15b7df7f remove dumb comment from pagecachekey 2025-05-29 14:12:16 +02:00
Pere Diaz Bou
93161e9fce remove lru size > 0 check on page cache fuzz 2025-05-29 14:12:16 +02:00
Pere Diaz Bou
37e834b092 remove unnecessary test 2025-05-29 14:12:16 +02:00
Pere Diaz Bou
44007075d9 remove frame_id from PageCacheKey
After reading sqlite a bit, it isn't needed because we have RWlock for
each table in the database file.
2025-05-29 14:12:16 +02:00
Pere Diaz Bou
28bd24b7d4 clear page cache on transaction failure
This is the first step towards rollback, since we still don't spill
pages with WAL, we can simply invalidate page cache in case of failure.
2025-05-28 15:54:28 +02:00
Pere Diaz Bou
7143e43dd4 clippy 2025-05-21 15:27:15 +02:00
Pere Diaz Bou
a69f85be84 cacheflush clear cache 2025-05-21 14:20:11 +02:00
Pere Diaz Bou
ddb166f0f0 custom hashmap for page cache 2025-05-21 14:19:56 +02:00
Pere Diaz Bou
c365d79cb1 minimum capacity 10 in page cache 2025-05-21 14:19:56 +02:00
Pere Diaz Bou
35f7317724 add default page cache 2025-05-21 14:11:21 +02:00
Pere Diaz Bou
adf72f2bf8 allow updating a page id in page cache 2025-05-21 14:09:39 +02:00
Pere Diaz Bou
9677997c63 fix page cache fuzz
to test whether a key is in the cache, we must use peek without touching
the value in order to not promote and change the order of values in lru
cache
2025-05-21 14:09:39 +02:00
Pere Diaz Bou
67e260ff71 allow delete of dirty page in cacheflush
Dirty pages can be deleted in `cacheflush`. Furthermore, there could be
multiple live references in the stack of a cursor so let's allow them to
exist while deleting.
2025-05-21 14:09:39 +02:00
Alecco
e2f99a1ad2 page_cache: implement resize 2025-05-21 14:09:39 +02:00
Alecco
4ef3c1d04d page_cache: fix insert and evict logic
insert() fails if key exists (there shouldn't be two) and panics if
it's different pages, and also fails if it can't make room for the page.

Replaced the limited pop_if_not_dirty() function with make_room_for().
It tries to evict many pages as requested spare capacity. It should come
handy later by resize() and Pager. make_room_for() tries to make room or
fails if it can't evict enough entries.

For make_room_for() I also tried with an all-or-nothing approach, so if
say a query requests a lot more than possible to make room for, it
doesn't evict a bunch of pages from the cache that might be useful. But
implementing this approach got very complicated since it needs to keep
exclusive PageRefs and collecting this caused segfaults. Might be worth
trying again in the future. But beware the rabbit hole.

Updated page cache test logic for new insert rules.

Updated Pager.allocate_page() to handle failure logic but needs further
work. This is to show new cache insert handling. There are many places
to update.

Left comments on callers of pager and page cache needing to update
error handling, for now.
2025-05-21 14:09:39 +02:00
Alecco
bdf427c329 page_cache: proper error handling for deletions
Add error handling and results for insert(), delete(), _delete(),
_detach(), pop_if_not_dirty(), and clear.

Now these functions fail if a page is dirty, locked, or has other
references.

insert() makes room with pop_if_not_dirty() beforehand to handle
cache full and un-evictable, else it would evict this page
silently.

_delete() returns Ok when key is not present in cache and it tries
first to detach the cache entry and clean its page *before*
removing the entry from the map.

detach() checks firstt if it's possible to evict the page and if
there are no other references to the page before taking its
contents.

test_detach_via_delete() and test_detach_via_insert() fixed by
properly checking before and after dropping the page reference.

test_page_cache_fuzz() fixed by reordering and moving reference to
the page into insert.

Other page cache tests fixed to check new function results.

All page cache tests pass.

Error handling and test fixes for Pager and BTree will be added in
a subsequent commit.
2025-05-21 14:09:39 +02:00
Alecco
c8beddab09 page_cache: split unlink() out of detach()
The unlink function removes an entry from the LRU.

The detach function removes an entry in the cache and clears page
contents.
2025-05-21 14:09:39 +02:00
Alecco
6763aa0cd5 page_cache: tests: helper functions and more tests
test_detach_via_insert fails as it repros insert not removing duplicate
page entries with same cache key (id, frame) issue #1348
2025-05-21 14:09:39 +02:00
Alecco
7e898eb8ca page_cache: tests: move helper function up 2025-05-21 14:09:39 +02:00
Pere Diaz Bou
e85fb86ff4 Request load page on insert_into_page
We assumed page was loaded because before inserting we would move there. `NewRowId` unfortunately moves cursor to the rightmost page causing eviction of root page -- this arose the issue with `insert_into_page` not loading the page we were supposed to have loaded so I added `return_if_locked_maybe_load` which is a utility macro to check if the page is locked and if not, load it if needed.
2025-04-02 16:24:53 +02:00
Pere Diaz Bou
6b05dbddb0 remove unnecessary code while building count old and size old balancing 2025-04-01 13:11:55 +02:00
Pere Diaz Bou
1af6dccc72 allow arc in tests 2025-03-12 16:02:04 +01:00
Pere Diaz Bou
8127927775 remove modulo by 1 error 2025-03-12 15:48:22 +01:00
Pere Diaz Bou
deaff6c1ec Fix detachment of nodes in lru cache. 2025-03-12 15:48:22 +01:00
Doug Anderson444
0aa5de6d9f
rm log, switch all to tracing 2025-02-11 09:03:36 -04:00
sonhmai
fcd893284b chore: fix typos 2025-01-23 11:25:01 +07:00
Pere Diaz Bou
39a75147d4 Page cache by page_number and frame_number
Since page cache is now shared by default, we need to cache pages by
page number and something else. I chose to go with max_frame of
connection, because this connection will have a max_frame set until from
the start of a transaction until the end of it.

With key pairs of (pgno, max_frame) we make sure each connection is
caching based on the snapshot it is at as two different connections
might have the same pageno being using but a different frame. If both
have same max_frame then they will share same page.
2024-12-13 21:57:27 +01:00