Commit graph

110 commits

Author SHA1 Message Date
PThorpe92
33b52bfb84 Replace refcel in wal sync, add counter timeout to conn close shutdown 2025-06-13 11:12:42 +03:00
PThorpe92
9f966910bc Add manual wal sync before checkpoint in connection Drop 2025-06-13 11:11:30 +03:00
Jussi Saurio
ace1e02fc0 Remove leftover info trace 2025-06-10 16:51:34 +03:00
Jussi Saurio
a5aeff9a3d Fix index insert accidentally double-inserting after balance 2025-06-10 14:16:26 +03:00
Zaid Humayun
e994adfb40 Persisting database header and pointer map page to cache
This commit ensures that the metadata in the database header and the pointer map pages allocated are correctly persisted to the page cache. This was not being done earlier.
2025-06-06 23:14:25 +05:30
Zaid Humayun
e7d09edf09 fix clippy warnings 2025-06-06 23:14:25 +05:30
Zaid Humayun
1f5025541c addresses comment https://github.com/tursodatabase/limbo/pull/1600#discussion_r2115796655 by @jussisaurio
this commit ensures that ptrmap operations return a CursorResult so operation can be suspended & later retried
2025-06-06 23:14:25 +05:30
Zaid Humayun
8efbce5980 Fixes tests after asserting MIN_PAGE_SIZE
this commit fixes tests that broke after addding the MIN_PAGE_SIZE assertion
2025-06-06 23:14:25 +05:30
Zaid Humayun
6e87761a34 Addresses comment https://github.com/tursodatabase/limbo/pull/1600#discussion_r2115842804 by @jussisaurio
this commit adds an assert into ptrmap_page_cycle_length
2025-06-06 23:14:25 +05:30
Zaid Humayun
20e20b8a32 Larger compiler directive. Addresses https://github.com/tursodatabase/limbo/pull/1600#discussion_r2115820195
this commit places all pointer map functionality within a module called ptrmap guarded by a compiler directive
2025-06-06 23:14:25 +05:30
Zaid Humayun
33fc60232c removed unnecessary comment 2025-06-06 23:14:25 +05:30
Zaid Humayun
8e6fb1d28f addresses comments by @jussisaurio 2025-06-06 23:14:25 +05:30
Zaid Humayun
0b5338ec7e fixed off by one error 2025-06-06 23:14:25 +05:30
Zaid Humayun
51a1b01ed9 removed comment 2025-06-06 23:14:25 +05:30
Zaid Humayun
7c83086eed removed inferred types 2025-06-06 23:14:25 +05:30
Zaid Humayun
275548e991 adds comment 2025-06-06 23:14:25 +05:30
Zaid Humayun
b9ae5e7ce9 removed omit_autovacuum from flags and fixed tests 2025-06-06 23:14:25 +05:30
Zaid Humayun
4b9ab35012 fixed clippy warnings 2025-06-06 23:14:25 +05:30
Zaid Humayun
5827a33517 Beginnings of AUTOVACUUM
This commit introduces AUTOVACUUM to Limbo. It introduces the concept of ptrmap pages and also adds some additional instructions that are required to make AUTOVACUUM PRAGMA work
2025-06-06 23:14:22 +05:30
meteorgan
1554c54f2b restore comments 2025-06-03 22:06:08 +08:00
meteorgan
f2bf6251cd write database header via normal pager route 2025-06-03 22:06:08 +08: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
Pekka Enberg
3250560eb8 sqlite3: Add libsql_wal_get_frame() API 2025-05-27 13:47:40 +03:00
Jussi Saurio
3ba9f2ab97 Small cleanups to pager/wal/vdbe - mostly naming
- Instead of using a confusing CheckpointStatus for many different things,
  introduce the following statuses:
    * PagerCacheflushStatus - cacheflush can result in either:
      - the WAL being written to disk and fsynced
      - but also a checkpoint to the main BD file, and fsyncing the main DB file

      Reflect this in the type.
    * WalFsyncStatus - previously CheckpointStatus was also used for this, even
      though fsyncing the WAL doesn't checkpoint.
    * CheckpointStatus/CheckpointResult is now used only for actual checkpointing.

- Rename HaltState to CommitState (program.halt_state -> program.commit_state)
- Make WAL a non-optional property in Pager
  * This gets rid of a lot of if let Some(...) boilerplate
  * For ephemeral indexes, provide a DummyWAL implementation that does nothing.
- Rename program.halt() to program.commit_txn()
- Add some documentation comments to structs and functions
2025-05-26 10:37:34 +03:00
Pere Diaz Bou
a69f85be84 cacheflush clear cache 2025-05-21 14:20:11 +02:00
Pere Diaz Bou
591c674e86 Introduce PageRef wrapper BTreePage.
One problem we have with PageRef, is that this Page reference can be
unloaded, this means if we read the page again instead of loading the
page onto the same reference, we will have split brain of references.

To solve this we wrap PageRef in `BTreePage` so that if a page is seen
as unloaded, we will replace BTreePage::page with the newest version of
the page.
2025-05-21 14:19:41 +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
35e2088b7e cacheflush move dirty page to new snapshot
After inserting a page into the wal, we dispose of the modified page.
This is unnecessary as we can simply move new page to the newest
snapshot where this page can be read.
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
e808a28c98 WIP (squash) adapt pager and btree to page cache error handling 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
Pekka Enberg
524a523036 sqlite3: Add libsql_wal_frame_count() API 2025-05-15 11:43:44 +03:00
meteorgan
d2dce740f7 fix some issues about page_size 2025-04-28 16:13:07 +08:00
Jussi Saurio
9d553c50cc Merge 'allow index entry delete' from Pere Diaz Bou
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #1341
2025-04-18 15:26:05 +03:00
Jussi Saurio
5628cc27a6 btree: move allocate_overflow_page to Pager impl 2025-04-14 15:25:15 +03:00
Pere Diaz Bou
651c00b4a8 allow index entry delete 2025-04-14 11:02:17 +02:00
Diego Reis
135330b736 core/pager: Fix page handling issue due change in wal type 2025-04-13 11:10:06 -03:00
Diego Reis
66e12e1c2d core/vdbe: Create OpenEphemeral bytecode
"Open a new cursor P1 to a transient table. The cursor is always opened read/write even if the main database is read-only. The ephemeral table is deleted automatically when the cursor is closed.

If the cursor P1 is already opened on an ephemeral table, the table is cleared (all content is erased)."

There is still some work to do, but this is a basic setup
2025-04-13 11:10:06 -03:00
Diego Reis
65d4c68cf2 core/pager: Wrap wal with Option 2025-04-13 11:10:05 -03:00
Diego Reis
51eb2af06a core(refactor): Add CreateBTreeFlags
Passing 1s and 0s with comments is not rustacean, and since we already follow the pattern of struct flags in other sections of the codebase it's better use it here too.
2025-04-13 01:46:30 -03:00
Pekka Enberg
53633e8b6f core/btree: Add PageContent::new() helper 2025-04-10 13:14:38 +03:00
Pekka Enberg
ed1854c8de Merge 'Request load page on insert_into_page' from Pere Diaz Bou
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.

Closes #1138
2025-04-02 18:52:25 +03: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
e2d00a9f96 inline start transactions from pager and wal
Execute `SELECT 1`/limbo_execute_select_1
                        time:   [30.543 ns 30.585 ns 30.632 ns]
2025-04-02 16:18:36 +02:00
Pere Diaz Bou
141303e330 Validate cells inside a page after each operation
We need to ensure an operation doesn't transform the cells inside a page
to an invalid state. In debug mode we can enable a
`debug_validate_cells` with `#[cfg(debug_assertions)]` so that it is
skipped on release mode.

Modify pager logs
2025-04-01 11:19:23 +02:00
Daniel Boll
5fc9ccdc8c Update checkpoint result initialization and WAL frame handling
- Use `CheckpointResult::default()` instead of `CheckpointResult::new()`
- Correct WAL frame header salt and checksum handling
- Ensure frame ID is 1-based and adjust frame offset calculation
- Add `Default` implementation for `CheckpointResult`
- Use random values for WAL header salts
2025-03-25 21:38:12 -03:00
Pekka Enberg
df6af6ed79 core: Rename FileStorage to DatabaseFile 2025-03-25 11:15:16 +02:00
Pekka Enberg
52ccc36061 Merge 'Impl Copy on some types in the pager to prevent explicit clones' from Preston Thorpe
Tried to keep this as small and focused as possible, just a few that I
ran into while debugging the page cache

Closes #1107
2025-03-21 18:40:14 +02:00