Commit Graph

3336 Commits

Author SHA1 Message Date
PThorpe92
68eca4feed Add demo vfs module to vtab kvstore 2025-03-12 21:52:51 -04:00
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
20f92fdacf Define API for vfs modules extensions 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
7ae1da0f3c Ignore some failing Rust SQLite test cases
...they fail on CI, but not locally so disable them until we got them sorted out.
2025-03-12 18:56:32 +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
Pekka Enberg
381b6f839f Merge 'Fix DumbLruPageCache, Connection::execute and page 1 read from wal' from Pere Diaz Bou
You might have guessed the `DumbLruCache` was dumb, but no, it was a
reference to myself. This PR fixes some dumb mistakes of detaching nodes
which failed to update `tail` and `head` properly.
Edit: This PR now fixes `Connection::execute` which funnily enough we
didn't notice it was returning successfully but in reality
`program.step` returned `IO` which made us think it was finished but not
really.
Edit 2: This PR fixes yet another thing! Pages read from WAL where being
initialized as if they were `id > 1`. By making it not this dumb thing
we can read `page 1` from `WAL` without failing catastrophically

Closes #1115
2025-03-12 18:50:48 +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
f7c8d4cc69 test_open_existing fix 2025-03-12 16:06:52 +01:00
Pere Diaz Bou
e65d76f51f fmt 2025-03-12 16:06:29 +01:00
Pere Diaz Bou
1af6dccc72 allow arc in tests 2025-03-12 16:02:04 +01:00
Pere Diaz Bou
40a78c32b6 fix sqlite3 lib db test path 2025-03-12 16:00:46 +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
Pekka Enberg
c660ac5c68 tests/integration: Ignore failing overflow tests
...let's add them back when the bugs are fixed.
2025-03-12 13:31:33 +02:00
Pekka Enberg
e2f26e79c5 Merge 'bindings/rust: Fix rust bindings so example runs' from yirt grek
Fixes the rust bindings so that `example.rs` is runnable

Closes #1113
2025-03-12 13:28:23 +02: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
a56be0a2af Silence overflow page tests for now 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
cb68b2ec1b sqlite3: cargo fmt 2025-03-10 12:22:01 +02:00
Pekka Enberg
bc30ca57e8 Merge 'sqlite3: Add Rust tests for SQLite3 API implementation' from Karan Janthe
This PR introduces test for SQLite3 API implementation, adding both unit
tests in Rust and maintaining existing C compatibility tests.
## Changes
- Added unit tests for core SQLite3 operations in `lib.rs`:
  - Database initialization and shutdown
  - Memory database operations
  - Error code handling and messages
  - Statement preparation and execution
  - Version information verification

Closes #1108
2025-03-08 09:03:18 +02:00
karan
58a12d0a51 Merge branch 'main' into sqlite3-tests 2025-03-08 09:58:27 +05:30
karan
34876c4711 fixing erro code for sqlite open
Signed-off-by: karan <karanjanthe@gmail.com>
2025-03-08 09:52:43 +05:30
karan
eba5e74a2c Cargo fmt
Signed-off-by: karan <karanjanthe@gmail.com>
2025-03-07 19:12:44 +05:30
karan
d7939f05c2 Added tests in sqlite3
Signed-off-by: karan <karanjanthe@gmail.com>
2025-03-07 19:09:58 +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
869bd5b363 Fix installer script URL
Fixes #1103
2025-03-06 14:34:51 +02:00
Pekka Enberg
ab8161c357 Merge 'Integrate MVCC' from Pekka Enberg
This pull request integrates MVCC with the VDBE.

The long term plan is to implement SQLite `BEGIN CONCURRENT` by
introducing a "MV store" abstraction (that implements the Hekaton in-
memory MVCC index) above the pager. Traditional SQLite transactions use
the pager and the WAL, but MV store has its own transaction path that
updates the in-memory multi-versioned index. If a key does not exist in
the MVCC index, we read records from the pager. When a MVCC transaction
commits, we emit WAL entries.

In this pull request, we wire up the MVCC transaction machinery to VDBE
and multi-version cursor to the b-tree cursor. Currently, the database
either runs in normal b-tree mode or in in-memory MVCC, but we need to
explore if we can make it a hybrid solution where you can read from both
MVCC index and B-Tree. Note that this pull request also does not add
logical logging to a file, which is something we'll defer for later.

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

Closes #917
2025-03-06 13:00:40 +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