Commit Graph

3366 Commits

Author SHA1 Message Date
Preston Thorpe
a2aca1f747 Merge branch 'tursodatabase:main' into main 2025-03-16 21:47:20 -04:00
Pekka Enberg
9efcacc601 Merge 'Add jsonb bench and rewrite jsonb parser to use slice and cursor' from Ihor Andrianov
Added bench to see how far i am from SQLite. If ~~Cloude~~ I did benches
correct moving from iterator to slice and cursor gives crazy performance
bump where we are almost on par with SLQLite when we are not talking
about huge jsons, but i suspect SQLite do some trickery there.

Closes #1125
2025-03-15 08:49:49 +02:00
PThorpe92
8e4705d6c6 Fix read completion error in vfs 2025-03-14 18:08:49 -04:00
Ihor Andrianov
b366045cb7 Rewrite parser to use slice and cursor instead of iterator 2025-03-14 19:47:18 +02:00
Ihor Andrianov
37c2655b6f Add jsonb bench 2025-03-14 19:46:29 +02:00
Pekka Enberg
731fbaf3c7 Merge 'Jsonb implementation' from Ihor Andrianov
This PR implements a complete JSONB parser and serializer as current PR
draft looks stale.
Sorry for huge PR.
I've choose a recursive parsing approach because:
1. It's simpler to understand and maintain
2. It follows SQLite's implementation pattern, ensuring compatibility
3. It naturally maps to JSON's hierarchical structure
The implementation includes comprehensive test coverage for standard
JSON features and JSON5 extensions. All test cases pass successfully,
handling edge cases like nested structures, escape sequences, and
various number formats.
While the code is ready for review, I believe it would benefit from fuzz
testing in the future to identify any edge cases not covered by the
current tests.
Ready for review, proposals and feedback.

Closes #1114
2025-03-13 21:17:52 +02:00
Pekka Enberg
b1419ab434 Merge 'Initial pass on Virtual FileSystem extension module' from Preston Thorpe
This PR implements a `VFS` module for our extension library, allowing
extensions to be written that can introduce different I/O back-ends.
EDIT: there is an included plain external/sync vfs example for testing,
as mentioned in #996 they can be combined after they are both merged and
we can keep 1 extension crate just for testing that features can be
added to, without making a new extension just to test stuff.
This PR also adds the `.vfslist` dot command, and replaces the `--io`
CLI argument with `--vfs` to match sqlite.
In order to support building vfs modules at compile time, and to then
support opening a brand new db file using a staticly built-in extension
module, a new method was created `open_with_vfs` that will load any vfs
modules before a `Database` is created, and uses that `IO` to create the
initial file, and returns it: `Result<(Arc<dyn IO>, Arc<Database>)>`. in
keeping with the API of core.
When #1039 is merged, the vfs module can be specified in a query
parameter.

Closes #960
2025-03-13 21:16:52 +02:00
Pekka Enberg
9f641f17c6 Disable some B-Tree fuzzers
Fuzz testing is great for finding bugs, but until we fix the bugs,
failing CI runs out of the blue for unrelated PRs is not very
productive. Hopefully we can enable this soon again, but until then,
let's not fail the test suite all the time randomly.
2025-03-13 10:30:34 +02:00
PThorpe92
c638b64a59 Fix tests to use updated extension name 2025-03-12 21:55:50 -04:00
PThorpe92
64d8575ee8 Hide add_builtin_vfs_extensions from non fs feature 2025-03-12 21:52:52 -04:00
PThorpe92
c1f5537d39 Fix feature flagging static vfs modules 2025-03-12 21:52:52 -04:00
PThorpe92
b306cd416d Add debug logging to testing vfs extension 2025-03-12 21:52:52 -04:00
PThorpe92
216a8e7848 Update getrandom dependency in ext api crate 2025-03-12 21:52:52 -04:00
PThorpe92
f8455a6a3b feature flag register static vfs to fs feature 2025-03-12 21:52:51 -04:00
PThorpe92
2cc72ed9ab Feature flag vfs for fs feature/prevent wasm 2025-03-12 21:52:51 -04:00
PThorpe92
8e2c9367c0 add missing method to add builtin vfs to ext api 2025-03-12 21:52:51 -04:00
PThorpe92
89a08b7611 Add vfslist command and setup CLI with new db open api 2025-03-12 21:52:51 -04:00
PThorpe92
6cb9091dc8 Remove unused macro method 2025-03-12 21:52:51 -04:00
PThorpe92
35fc9df275 Rename and combine testing extension crate 2025-03-12 21:52:51 -04:00
PThorpe92
18537ed43e Add documentation/example to extensions/core README.md 2025-03-12 21:52:51 -04:00
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
Ihor Andrianov
ffa0b1aaca fix clippy 2025-03-12 16:08:16 +02:00
Ihor Andrianov
39c2481ce3 add e2e tests 2025-03-12 15:34:58 +02:00
Ihor Andrianov
8a2740ad8a cleanup 2025-03-12 15:34:36 +02:00
Ihor Andrianov
eb2d2fbd69 add tests 2025-03-12 15:03:41 +02:00
Ihor Andrianov
19e4bc8523 clippy 2025-03-12 15:03:41 +02:00
Ihor Andrianov
7bd10dd577 remove warnings and dead code 2025-03-12 15:03:40 +02:00