Commit Graph

9067 Commits

Author SHA1 Message Date
Preston Thorpe
ec79a9063d Merge 'remove io.blocks from btree balancing code' from Nikita Sivukhin
This PR removes `io.block` usage from B-Tree balancing code (similarly
as in the #3179)

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #3194
2025-09-18 07:24:51 -04:00
Pekka Enberg
6c48cb7043 Merge 'core: Use sequential consistency for atomics by default' from Pekka Enberg
We use relaxed ordering in a lot of places where we really need to
ensure all CPUs see the write. Switch to sequential consistency, unless
acquire/release is explicitly used. If there are places that can be
optimized, we can switch to relaxed case-by-case, but have a comment
explaning *why* it is safe.

Closes #3193
2025-09-18 14:19:54 +03:00
Pekka Enberg
f731efdc35 Merge 'core/storage: Use AtomicU32 for Pager::page_size' from Pekka Enberg
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3191
2025-09-18 13:40:57 +03:00
Pekka Enberg
8337e86794 core: Use sequential consistency for atomics by default
We use relaxed ordering in a lot of places where we really need to
ensure all CPUs see the write. Switch to sequential consistency, unless
acquire/release is explicitly used. If there are places that can be
optimized, we can switch to relaxed case-by-case, but have a comment
explaning *why* it is safe.
2025-09-18 13:38:13 +03:00
Nikita Sivukhin
1e0fb143f6 remove io.blocks from btree balancing code 2025-09-18 14:28:53 +04:00
Pekka Enberg
36071c0436 Merge 'stress: Retry sync on error to avoid a panic, take 2' from Pekka Enberg
Commit eeab6d5ce ("stress: Retry sync on error to avoid a panic") only
enabled sync retry in the schema creation path. Let's add it to the
stress test loop too.
Spotted during Antithesis runs.

Closes #3192
2025-09-18 13:17:25 +03:00
Jussi Saurio
c9d7cf77b8 Merge 'Fix C API compatibility tests and add a minimal CI' from Andrea Peruffo
Hi 👋 and thanks for the great project!
Related to my comment on #85
Here I implemented 3 missing APIs and added a GH Action job to verify
the results.
Let me know if I missed anything and if this is aligned with the
direction of the project.

Reviewed-by: Nikita Sivukhin (@sivukhin)

Closes #2982
2025-09-18 13:14:34 +03:00
andreatp
4c74ab10f4 fix c compat tests and add a minimal CI 2025-09-18 10:13:31 +01:00
Pekka Enberg
31ff7d196b stress: Retry sync on error to avoid a panic, take 2
Commit eeab6d5ce ("stress: Retry sync on error to avoid a panic") only
enabled sync retry in the schema creation path. Let's add it to the
stress test loop too.

Spotted during Antithesis runs.
2025-09-18 11:38:11 +03:00
Pekka Enberg
2a5284afb9 core/storage: Use AtomicU32 for Pager::page_size 2025-09-18 11:33:32 +03:00
Pekka Enberg
0799273d24 Merge 'Convert more Pager fields towards being Send' from Pekka Enberg
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3177
2025-09-18 11:21:20 +03:00
Pekka Enberg
e6d994dee0 core/storage: Wrap Pager::allocate_page_state with RwLock 2025-09-18 10:55:55 +03:00
Pekka Enberg
365f606cce core/storage: Use AtomicU8 for Pager::auto_vacuum_mode 2025-09-18 10:55:55 +03:00
Pekka Enberg
2215cccebb core/storage: Wrap Pager::syncing in Arc<AtomicBool> 2025-09-18 10:55:54 +03:00
Jussi Saurio
202490289e Merge 'More async' from Nikita Sivukhin
This PR eliminates blocking IO calls (`io.block` /
`io.wait_for_completion`) from common execution paths
I need this because I am trying to make turso in browser work smoothly
and current paradigm doesn't work well as it use same connection from
different threads. But, in order to run DB on main thread only (expect
IO) - we need to eliminate all blocking calls (they block main thread
and it can't exit from this state).
This PR eliminates blocking behaviour from following places:
1. `append_frames` now fully async but `prepare_wal_start` /
`prepare_wal_finish` must be called before it in order to ensure that
WAL header is initialized
2. `op_transaction` is non-blocking and read db header async
3. `op_sorter_open` is non-blocking and read db header async in the
beginnig of execution
4. `op_open_ephemeral` is non-blocking and read db header async in the
beginning of execution (note, that I am also removed weird logic which
read page size from the empty ephemeral DB file)
5. `op_checkpoint` is non blocking and checkpoint itself now have more
complex state machine to handle previously blocking behaviour

Closes #3179
2025-09-18 10:31:25 +03:00
Pekka Enberg
84cf3640cb Merge 'Enable encryption option in Whopper ' from Avinash Sajjanshetty
If encryption is arg is passed, then we run whopper tests with
encryptions. We randomly generate cipher and key, and run whopper. They
are also printed for debugging and analysis.
Also, updated the corresponding scripts. So now you can do:
```bash
./whopper/bin/run --enable-encryption

or 

./whopper/bin/explore --enable-encryption
```

Closes #3183
2025-09-18 10:03:13 +03:00
Nikita Sivukhin
ed819c9865 Merge branch 'main' into more-async 2025-09-18 10:48:54 +04:00
Jussi Saurio
1d2b461a2a Merge 'Compat: Translate the 2nd argument of group_concat / string_agg' from Iaroslav Zeigerman
Fixes #3140

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3155
2025-09-18 09:23:05 +03:00
Jussi Saurio
0d37ac2519 Merge 'translate: couple fixes from testing with Gorm' from Preston Thorpe
Ongoing tests for [turso-go](https://github.com/tursodatabase/turso-go)
have unearthed a couple more issues
closes #3187
### Number 1:
We were getting something like:
```sql
sqlite_autoindex_`databases`_2
```
when creating autoindex for table in Gorm (gorm is notorious for
backticks everywhere), because of not normalizing the column name when
creating autoindex.
### Number 2:
When creating table with `PRIMARY KEY AUTOINCREMENT`, we were still
creating the index, but it wasn't properly handled in
`populate_indices`, because we are doing the following:
```rust
                if column.primary_key && unique_set.is_primary_key {
                    if column.is_rowid_alias {
                        // rowid alias, no index needed
                        continue; // continues, but doesn't consume it..
                    }
```
So if we created such an index entry for the AUTOINCREMENT... we would
trip this:
```rust
assert!(automatic_indexes.is_empty(), "all automatic indexes parsed from sqlite_schema should have been consumed, but {} remain", automatic_indexes.len());
```

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3186
2025-09-18 09:21:41 +03:00
Jussi Saurio
498293658e Merge 'Reduce allocations needed for break_predicate_at_and_boundaries' from Lâm Hoàng Phúc
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3188
2025-09-18 09:21:24 +03:00
Jussi Saurio
91ef4e5e9d Merge 'Introduce instruction VTABLE' from Lâm Hoàng Phúc
this PR improves 3-6% for `prepare` benchmark without slowing down
others.  After this PR we don't have to store `InsnFunction`  in
`Program` and `ProgramBuilder` anymore, because `to_function` will
return result without matching.

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #3098
2025-09-18 09:18:48 +03:00
Jussi Saurio
26f56d794e Merge 'Simulator Multiple Connections' from Pedro Muniz
This is the start of the work to add transactional properties to the
Simulator. Before this PR, we only executed the queries on one
connection, now the default is to run with 10 connections. Each
connection is selected at random to run the database queries.
A lot of the code was hardcoded to work with 1 connection only, so most
of the refactor came from me adjusting the `Interaction` and
`Interactions` structs to hold a connection index. As I had to refactor
a lot of code, I took the opportunity to deduplicate code that across
`run_simulation_default`, `watch::run_simulation`,
`differential::run_simulation`, `doublecheck::run_simulation`.
In my next PR, I intend to add transaction isolation checking which will
involve some more refactoring to ensure the simulator correctly tracks
transaction state and table visibility.
And in a future PR, we can extend this further with concurrent
transactions as well

Closes #3163
2025-09-18 09:10:01 +03:00
Pekka Enberg
d2376a239a Merge 'core/mvcc: introduce with_header for MVCC header update tracking' from Pere Diaz Bou
Currently header changes are tracked through pager by reading page 1.
MVCC has it's own layer to track changes during txn so this commit makes
it so that headers are tracked by each txn separately.
On commit we update the _global_ header which is used to update
`database_size` because pager commits require it to be up to date. This
also makes it _simpler_ to keep track of header updates and update
pager's header accordingly.
This PR is needed in order to make logical log work because we don't
want to rely on pager as much as possible!

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3156
2025-09-18 08:13:14 +03:00
TcMits
88119888d0 reduce allocation needed for break_predicate_at_and_boundaries 2025-09-18 10:52:29 +07:00
PThorpe92
5aa07eb826 Use normalized table name for autoindex creation 2025-09-17 20:51:22 -04:00
PThorpe92
45fcadbf20 Fix formatting of autoindex 2025-09-17 16:07:11 -04:00
PThorpe92
faa3113c77 Add regression test for table creation pk autoincrement constraint with backticks 2025-09-17 15:53:35 -04:00
PThorpe92
cfc6ec4ee5 Normalize more idents 2025-09-17 15:53:06 -04:00
PThorpe92
c57545d504 Avoid panicking when we create autoindex for AUTOINCREMENT primary key 2025-09-17 15:52:42 -04:00
Nikita Sivukhin
bf5397dade fix op_sorter 2025-09-17 21:30:40 +04:00
PThorpe92
dde8a49f4e normalize identifier for creating autoindex to prevent e.g. sqlite_autoindextable_2 2025-09-17 13:25:33 -04:00
PThorpe92
4e71524e42 normalize identifier for ID::Name in upsert expr rewriting 2025-09-17 13:24:06 -04:00
Avinash Sajjanshetty
94e7f6defc Update whopper run and explore scripts 2025-09-17 21:58:54 +05:30
Avinash Sajjanshetty
10137ffaa4 run whopper with encryption if arg is passed 2025-09-17 21:58:27 +05:30
Avinash Sajjanshetty
f9a6cde79a Make encryption::CipherMode public 2025-09-17 21:55:23 +05:30
Preston Thorpe
8c53d7f024 Merge 'translation: rewrite expressions and properly handle quoted identifiers in UPSERT' from Preston Thorpe
This PR fixes bugs found in the [turso-
go](https://github.com/tursodatabase/turso-go) driver with UPSERT clause
earlier, where `Gorm` will (obviously) use Expr::Variable's as well as
use quotes for `Expr::Qualified` in the tail end of an UPSERT statement.
Example:
```sql
INSERT INTO users (a,b,c) VALUES (?,?,?) ON CONFLICT (`users`.`a`) DO UPDATE SET b = `excluded`.`b`, a = ?;
```
and previously we were not properly calling `rewrite_expr`, which was
not properly setting the anonymous `Expr::Variable` to `__param_N` named
parameter, so it would ignore it completely, then return the wrong # of
parameters.
Also, we didn't handle quoted "`excluded`.`x`", so it would panic in the
optimizer that Qualified should have been rewritten earlier.

Closes #3157
2025-09-17 11:25:13 -04:00
Nikita Sivukhin
c1176356f7 small fixes 2025-09-17 19:20:42 +04:00
Nikita Sivukhin
93e4dfbd69 remove one more unnecessary io.block 2025-09-17 19:16:51 +04:00
Nikita Sivukhin
f1764d9f76 fix test 2025-09-17 19:09:55 +04:00
Nikita Sivukhin
b5d12b79cd reset commit_state when commit_dirty_pages is done 2025-09-17 19:09:55 +04:00
Nikita Sivukhin
d16d86b85d fix blocking ensure_header_if_needed implementation 2025-09-17 19:09:55 +04:00
Nikita Sivukhin
5c4d8aa10b fix bug after making checkpoint async 2025-09-17 19:09:54 +04:00
Nikita Sivukhin
dea041b7c0 fix after rebase 2025-09-17 19:06:07 +04:00
Nikita Sivukhin
b2afdb8d29 fix comment 2025-09-17 19:06:07 +04:00
Nikita Sivukhin
a8bc06ea9c fix clippy 2025-09-17 19:06:07 +04:00
Nikita Sivukhin
2c09d17dfe make checkpoint async 2025-09-17 19:06:07 +04:00
Nikita Sivukhin
c4c9d409c9 remove io.block from op_checkpoint 2025-09-17 19:06:07 +04:00
Nikita Sivukhin
27627bdb8d remove IOExt import from execute 2025-09-17 19:06:07 +04:00
Nikita Sivukhin
85b671997e remove io.block from op_open_ephemeral 2025-09-17 19:06:07 +04:00
Nikita Sivukhin
18feacf824 remove io.block from op_sorter_open 2025-09-17 19:06:07 +04:00