Commit Graph

1812 Commits

Author SHA1 Message Date
PThorpe92
44f6054657 Impl copy + clone for io openflags 2025-03-12 21:52:51 -04:00
PThorpe92
8d3c44cf00 Impl IO trait for VfsMod type 2025-03-12 21:52:50 -04:00
PThorpe92
7d18b6b8b0 Create global vfs module registry 2025-03-12 21:52:50 -04:00
PThorpe92
b2748c61b2 Define API for registration of staticly linked vfs modules 2025-03-12 21:52:50 -04:00
PThorpe92
7c4f5d8df8 Add macros for generating FFI functions to support vfs 2025-03-12 21:52:50 -04:00
PThorpe92
25ed6a2985 Store dynamic ext libs in oncecell to prevent UB 2025-03-12 21:52:50 -04:00
Pekka Enberg
a2c40dd234 cargo fmt... 2025-03-12 18:59:08 +02:00
Pekka Enberg
b73df180cc Merge 'Fix various issues in insert_into_cell()' from Krishna Vishal
There are two bugs in #1085.
1. `find_free_cell` accesses non-existent free blocks and returns their
size to `allocate_space`. This is out of range access error. The fix is
to add a loop termination condition that stops it when we hit the end of
the blocks
2. This bug is caused by `find_free_cell` some how swallowing the blocks
with size `4 bytes`. So `compute_free_space` consistently undercounts by
`4 bytes`. I've refactored that part of the code to make sure 4 sized
block are not deleted.
I've also added a unit test which proves these fixes work and also added
a function called `debug_print_freelist` which prints all free blocks of
a page.
For now I've silenced the `overflow_page` tests.
Fixes #1085

Closes #1111
2025-03-12 18:51:19 +02:00
Pere Diaz Bou
aa4703c442 Fix read frame setting wrong offset
When I added frame reading support I thought, okay, who cares about the page id of this page it we read it from a frame because we don't need it to compute the offset to read from the file in this case. Fuck me, because it was needed in case we read `page 1` from WAL because it has a differnt `offset`.
2025-03-12 17:24:59 +01:00
Pere Diaz Bou
2fd790a055 make execute command loop until done 2025-03-12 16:26:29 +01: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
cc320a74ca few checkpoint result cleanup in vdbe 2025-03-12 15:48:22 +01:00
Pere Diaz Bou
f9916e8149 update max frame in case we got a read lock with outdated max frame 2025-03-12 15:48:22 +01:00
Pere Diaz Bou
825907bfac Invalidate cache entry after checkpoint of frame completes 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
Pere Diaz Bou
be3badc1f3 modify a few btree log level and add end_write_txn after checkpoint 2025-03-12 15:48:22 +01:00
Yirt Grek
bb68fbdd67 bindings/rust: Fix bindings so example runs 2025-03-12 00:54:18 -07:00
krishvishal
6093994bd2 Changed from using raw byte access methods to PageContent read/write methods
Added comments
2025-03-11 22:49:18 +05:30
krishvishal
91fa6a5fa3 Remove debug prints and make clippy happy 2025-03-11 20:30:09 +05:30
krishvishal
a1a63f621e Add a method that can help while debugging freelist blocks 2025-03-11 20:30:09 +05:30
krishvishal
d8210d79aa Add unit test to demonstrate that https://github.com/tursodatabase/limbo/issues/1085 is
fixed.
2025-03-11 20:30:09 +05:30
krishvishal
0f0d56b0e7 Refactor find_free_cell logic to make sure a freeblock with size 4 is not deleted.
Previously any block that has a size 4 is deleted resulting in the issue of computed free space
is less than 4 bytes when compared to expected free space.
2025-03-11 20:30:09 +05:30
krishvishal
77aeb889ae Add loop termination condition when pc = 0 in find_free_cell.
The issue is caused by the function try to read from non-existent free blocks.
2025-03-11 20:30:09 +05:30
Pekka Enberg
051d879db2 core: Fix btree test compilation 2025-03-06 19:14:48 +02:00
Pekka Enberg
b0636e4494 Merge 'Adds Drop Table' from Zaid Humayun
This PR adds support for `DROP TABLE` and addresses issue
https://github.com/tursodatabase/limbo/issues/894
It depends on https://github.com/tursodatabase/limbo/pull/785 being
merged in because it requires the implementation of `free_page`.
EDIT: The PR above has been merged.
It adds the following:
* an implementation for the `DropTable` AST instruction via a method
called `translate_drop_table`
* a couple of new instructions - `Destroy` and `DropTable`. The former
is to modify physical b-tree pages and the latter is to modify in-memory
structures like the schema hash table.
* `btree_destroy` on `BTreeCursor` to walk the tree of pages for this
table and place it in free list.
* state machine traversal for both `btree_destroy` and
`clear_overflow_pages` to ensure performant, correct code.
* unit & tcl tests
* modifies the `Null` instruction to follow SQLite semantics and accept
a second register. It will set all registers in this range to null. This
is required for `DROP TABLE`.
The screenshots below have a comparison of the bytecodes generated via
SQLite & Limbo.
Limbo has the same instruction set except for the subroutines which
involve opening an ephemeral table, copying over the triggers from the
`sqlite_schema` table and then re-inserting them back into the
`sqlite_schema` table.
This is because `OpenEphemeral` is still a WIP and is being tracked at
https://github.com/tursodatabase/limbo/pull/768
![Screenshot 2025-02-09 at 7 05 03 PM](https://github.com/user-
attachments/assets/1d597001-a60c-4a76-89fd-8b90881c77c9)
![Screenshot 2025-02-09 at 7 05 35 PM](https://github.com/user-
attachments/assets/ecfd2a7a-2edc-49cd-a8d1-7b4db8657444)

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #897
2025-03-06 18:27:41 +02:00
Pekka Enberg
ef180fa1cb core/mvcc: Improve tracing format
Suggested by Pere
2025-03-06 12:58:41 +02:00
Pekka Enberg
2c9d30cef4 core/vdbe: Don't commit MVCC on Halt if no autocommit
Spotted by Pere.
2025-03-06 12:52:03 +02:00
Pekka Enberg
d6c514c8d1 core: Integrate MVCC to B-Tree cursor 2025-03-06 10:16:42 +02:00
Pekka Enberg
bf3163c7fe core: Fix parse_schema() to use existing MVCC TX 2025-03-06 10:16:42 +02:00
Pekka Enberg
ef32a82941 core/vdbe: Integrate MVCC transactions 2025-03-06 10:16:42 +02:00
Pekka Enberg
461be0dc87 core: Add multi-version store to Database 2025-03-06 10:16:42 +02:00
Pekka Enberg
96175cccf7 cli: Add --experimental-mvcc option to enable MVCC 2025-03-06 10:16:42 +02:00
Pekka Enberg
5d0982f5db core/mvcc: Add RowID::new() and Row::new() helpers 2025-03-06 09:59:40 +02:00
Pekka Enberg
4247974f95 core/mvcc: Add insert() helper to Cursor 2025-03-06 09:32:48 +02:00
Pekka Enberg
b7382ffab1 core/mvcc: Switch Cursor to use Rc instead of lifetimes 2025-03-06 09:31:34 +02:00
Pekka Enberg
ff6d9465eb core/mvcc: Improve trace logging 2025-03-06 09:31:04 +02:00
Pere Diaz Bou
aa7391da50 fix halt return 2025-03-05 22:32:59 +01:00
Pere Diaz Bou
b555561aeb make Program::halt reentrant 2025-03-05 22:32:59 +01:00
Pere Diaz Bou
7aae885af4 add logs to wal locks 2025-03-05 22:32:59 +01:00
Pere Diaz Bou
feeb398e73 finish transaction and reset transaction state 2025-03-05 22:32:59 +01:00
Pekka Enberg
81b79bc833 core/mvcc: Eliminate row generic types
The logging code that writes out transactions to disk needs to write out
the byte array that we actually use. The code is less hairly without the
generics so drop them.
2025-03-05 19:17:16 +02:00
Pere Diaz Bou
262c4de548 add line number and thread id to tracing logs 2025-03-05 15:36:47 +01:00
Pere Diaz Bou
9a01e32c01 add tracing_subscriber and test_log::test
I don't know when and why we dropped log::* in favor of tracing but when it was done, it made relevant logs not appear any more while debugging so... I added test_log::test which helps by automatically adding info logs from trace package.
2025-03-05 15:36:06 +01:00
Pere Diaz Bou
5f5ca50c41 Move schema lock read to translate only 2025-03-05 14:07:48 +01:00
Pere Diaz Bou
b63f541150 impl Send Sync for GenericFile 2025-03-05 14:07:48 +01:00
Pere Diaz Bou
d1e7f0826b impl Send Sync for WindowsFile 2025-03-05 14:07:48 +01:00
Pere Diaz Bou
3d3cdbeb0c fix generic and windows sync compilation 2025-03-05 14:07:48 +01:00
Pere Diaz Bou
ab2fc3fb13 fix clippy arc warnings for now 2025-03-05 14:07:48 +01:00
Pere Diaz Bou
d1c7d758c4 fix uring Sync,Sync unsafe impl 2025-03-05 14:07:48 +01:00