Commit graph

6587 commits

Author SHA1 Message Date
Jussi Saurio
e1f10bb09e mark attach as experimental 2025-12-22 09:40:22 +02:00
Pekka Enberg
f598dfa13d
Merge 'core/mvcc: set_null_flag(false) when seek is called' from Pere Diaz Bou
Some checks are pending
Build & publish @tursodatabase/database / db-bindings-x86_64-pc-windows-msvc - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / db-bindings-x86_64-unknown-linux-gnu - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-aarch64-apple-darwin - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-aarch64-unknown-linux-gnu - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-wasm32-wasip1-threads - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-x86_64-pc-windows-msvc - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-x86_64-unknown-linux-gnu - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / Test DB bindings on Linux-x64-gnu - node@20 (push) Blocked by required conditions
Build & publish @tursodatabase/database / Test DB bindings on browser@20 (push) Blocked by required conditions
Build & publish @tursodatabase/database / Publish (push) Blocked by required conditions
Python / configure-strategy (push) Waiting to run
Python / test (push) Blocked by required conditions
Python / lint (push) Waiting to run
Python / linux (x86_64) (push) Waiting to run
Python / macos-arm64 (aarch64) (push) Waiting to run
Python / sdist (push) Waiting to run
Python / Release (push) Blocked by required conditions
Rust / cargo-fmt-check (push) Waiting to run
Rust / build-native (blacksmith-4vcpu-ubuntu-2404) (push) Waiting to run
Rust / build-native (macos-latest) (push) Waiting to run
Rust / build-native (windows-latest) (push) Waiting to run
Rust / clippy (push) Waiting to run
Rust / simulator (push) Waiting to run
Rust / test-limbo (push) Waiting to run
Rust / test-sqlite (push) Waiting to run
Rust Benchmarks+Nyrkiö / tpc-h (push) Waiting to run
Rust Benchmarks+Nyrkiö / vfs-bench-compile (push) Waiting to run
Rust Benchmarks+Nyrkiö / bench (push) Waiting to run
Rust Benchmarks+Nyrkiö / clickbench (push) Waiting to run
Rust Benchmarks+Nyrkiö / tpc-h-criterion (push) Waiting to run
## Description
BTreeCursor sets null flag to false once `seek` is called. This PR does
the same for MVCC
## Motivation and context
join.test failed with some cases due to this bug
## Description of AI Usage
I asked AI to find the issue but I ended showing the agent why he did
things wrong and that he should be ashamed

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

Closes #4296
2025-12-22 09:15:24 +02:00
Pekka Enberg
d3714f4120
Merge 'Mark triggers as experimental' from Jussi Saurio
Closes #4022

Closes #4318
2025-12-22 09:08:54 +02:00
Preston Thorpe
d6ceda8dcb
Merge 'fix(core/translate): apply affinity conversion to hash join build and probe keys' from Nuno Gonçalves
## Description
This PR adds missing affinity conversion to hash joins by applying
affinity conversion to build and probe keys before hashing.
```
turso> CREATE TABLE x(a INTEGER);
turso> CREATE TABLE y(b TEXT);
turso> INSERT INTO x VALUES (2),(3);
turso> INSERT INTO y VALUES ('02'),('2'),('2.0'),('3x'),('3.5');
turso> SELECT a, b
  FROM x JOIN y ON a = b
  ORDER BY a, b;
┌───┬─────┐
│ a │ b   │
├───┼─────┤
│ 2 │ 02  │
├───┼─────┤
│ 2 │ 2   │
├───┼─────┤
│ 2 │ 2.0 │
└───┴─────┘
```
## Motivation and context
Fixes #3482.
Currently, Turso returns an empty result set:
```
turso> CREATE TABLE x(a INTEGER);
turso> CREATE TABLE y(b TEXT);
turso> INSERT INTO x VALUES (2),(3);
turso> INSERT INTO y VALUES ('02'),('2'),('2.0'),('3x'),('3.5');
turso> SELECT a, b
  FROM x JOIN y ON a = b
  ORDER BY a, b;
turso>
```
Expected behavior:
```
sqlite> CREATE TABLE x(a INTEGER);
sqlite> CREATE TABLE y(b TEXT);
sqlite> INSERT INTO x VALUES (2),(3);
sqlite> INSERT INTO y VALUES ('02'),('2'),('2.0'),('3x'),('3.5');
sqlite> SELECT a, b
   ...>   FROM x JOIN y ON a = b
   ...>   ORDER BY a, b;
2|02
2|2
2|2.0
```
## Description of AI Usage
This PR was developed with assistance from Claude Sonnet 4.5 through
code completions.

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

Closes #4317
2025-12-21 21:08:29 -05:00
Jussi Saurio
2bf7ec5136 mark triggers as experimental 2025-12-21 21:18:15 +02:00
Nuno Gonçalves
734ba9a1bf chore(format): cargo fmt 2025-12-21 17:15:11 +00:00
Nuno Gonçalves
1b386147c1 fix(core/translate): apply affinity conversion to hash join build and probe keys 2025-12-21 16:59:46 +00:00
Jussi Saurio
6e58378471 rename with_shared_mut to with_shared_mut_dangerous 2025-12-21 18:38:01 +02:00
Jussi Saurio
acc1a89872 fix/wal: use with_shared() instead of with_shared_mut() for lock ops
using shared_mut() is unnecessary because the locks use atomics, and
in fact using shared_mut() can cause a deadlock, example:

- Thread 1 calls with_shared_mut() at in try_begin_read_tx
   to claim/update a read mark slot. This waits for readers to release
   their shared read locks.
- Thread 2 tries to use with_shared_mut() in end_read_tx() and also
  can't proceed
2025-12-21 18:37:58 +02:00
Jussi Saurio
97be13a6be Implement progressive backoff in begin_read_tx
Extract try_begin_read_tx with TryBeginReadResult::Retry for transient
conditions. begin_read_tx now retries with SQLite's quadratic backoff:
immediate retries for first 5 attempts, yield for 6-9, then quadratic
microsecond delays matching SQLite's formula.
2025-12-21 18:37:34 +02:00
Jussi Saurio
aead47f2a8 Return BusySnapshot instead of Busy for stale snapshot in begin_write_tx
BusySnapshot indicates the transaction's snapshot is permanently stale
and must be rolled back. Unlike Busy, retrying with busy_timeout will
never help - the caller must rollback and restart the transaction.
2025-12-21 18:35:03 +02:00
Jussi Saurio
139b398e49 Fix begin_read_tx validation and unlock on retry
- Add lock-0 re-validation after acquiring read_locks[0]
- Remove incorrect best_mark == shared_max requirement (stale mark is fine)
- Add current_slot_mark validation to detect slot modification race
- Unlock read lock before returning Busy on validation failure
- Use shared_max instead of best_mark for max_frame (bug fix)
2025-12-21 18:34:06 +02:00
Jussi Saurio
6938f334ab Add yield_now() and sleep() to IO trait
Used for progressive backoff in contended lock acquisition.
2025-12-21 18:29:52 +02:00
Jussi Saurio
cabea235ce Add BusySnapshot error type
Distinct from Busy: indicates the transaction's snapshot is permanently
stale and must be rolled back. Retrying with busy_timeout will not help.
2025-12-21 18:29:39 +02:00
Preston Thorpe
a10051dde4
Merge 'Fix RTRIM ignoring trailing tabs' from Krishna Vishal
`str::trim_end()` removes trailing tabs too. Replaced it with
`trim_end_matches(' ')`. Rust `str::trim` functions seem problematic
because they remove non-ascii whitespace and others.
Behavior now:
```
turso> select 'x' || char(9) = 'x' collate rtrim;
┌─────────────────────────────────────┐
│ 'x' || char (9) = 'x' COLLATE rtrim │
├─────────────────────────────────────┤
│                                   0 │
└─────────────────────────────────────┘
```
Closes: #3480

Reviewed-by: Mikaël Francoeur (@LeMikaelF)

Closes #3891
2025-12-20 10:33:59 -05:00
Preston Thorpe
90e6ed0ba4
Merge 'Fix incorrect conversion from TEXT to INTEGER when text is a number followed by a trailing non-breaking space' from Krishna Vishal
This PR fixes incorrect conversion from TEXT to INTEGER when text is a
number followed by a trailing non-breaking space.
This happens because `str::trim()` trims non-breaking space and unicode
whitespace while SQLite only trims ASCII whitespace.
Closes: https://github.com/tursodatabase/turso/issues/3679

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

Closes #3878
2025-12-20 10:33:15 -05:00
Preston Thorpe
2a4eb02095
Merge 'Sync fixes' from Nikita Sivukhin
Some checks are pending
Build & publish @tursodatabase/database / db-bindings-x86_64-pc-windows-msvc - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / db-bindings-x86_64-unknown-linux-gnu - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-aarch64-apple-darwin - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-aarch64-unknown-linux-gnu - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-wasm32-wasip1-threads - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-x86_64-pc-windows-msvc - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-x86_64-unknown-linux-gnu - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / Test DB bindings on Linux-x64-gnu - node@20 (push) Blocked by required conditions
Build & publish @tursodatabase/database / Test DB bindings on browser@20 (push) Blocked by required conditions
Build & publish @tursodatabase/database / Publish (push) Blocked by required conditions
Python / configure-strategy (push) Waiting to run
Python / test (push) Blocked by required conditions
Python / lint (push) Waiting to run
Python / linux (x86_64) (push) Waiting to run
Python / macos-arm64 (aarch64) (push) Waiting to run
Python / sdist (push) Waiting to run
Python / Release (push) Blocked by required conditions
Rust / cargo-fmt-check (push) Waiting to run
Rust / build-native (blacksmith-4vcpu-ubuntu-2404) (push) Waiting to run
Rust / build-native (macos-latest) (push) Waiting to run
Rust / build-native (windows-latest) (push) Waiting to run
Rust / clippy (push) Waiting to run
Rust / simulator (push) Waiting to run
Rust / test-limbo (push) Waiting to run
Rust / test-sqlite (push) Waiting to run
Rust Benchmarks+Nyrkiö / vfs-bench-compile (push) Waiting to run
Rust Benchmarks+Nyrkiö / bench (push) Waiting to run
Rust Benchmarks+Nyrkiö / clickbench (push) Waiting to run
Rust Benchmarks+Nyrkiö / tpc-h-criterion (push) Waiting to run
Rust Benchmarks+Nyrkiö / tpc-h (push) Waiting to run
This PR introduces few sync fixes relevant to the partial sync feature:
1. Make `try_wal_watermark_read_page` async - this is important as now
db file can be partial and require extra network IO for fetching missing
pages
2. Do not panic if requested page doesn't exist on server - this can be
valid case if db on the server has smaller size
3. Maintain clean db file size in order to avoid reads outside of the
file (this can happen, when we revert new pages allocated only in the
WAL and need to fetch their previous state if there is one)

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

Closes #4297
2025-12-19 17:56:01 -05:00
Nuno Gonçalves
21268632eb fix(core): prevent ALTER COLUMN from resulting in tables with only generated columns 2025-12-19 21:52:36 +00:00
pedrocarlo
2bc976f3d9 add proper name checks for create table, view 2025-12-19 17:20:46 -03:00
pedrocarlo
880b04eaba add internal method to acquire IO from statement for sdk kit 2025-12-19 17:20:46 -03:00
pedrocarlo
10577dd6c5 adjust run_one_step_blocking 2025-12-19 17:20:46 -03:00
pedrocarlo
848c529653 fix more places to avoid using run_once 2025-12-19 17:20:45 -03:00
pedrocarlo
8b0baa0751 refactor more places to use helper statement functions + create run_one_step_blocking 2025-12-19 17:20:45 -03:00
pedrocarlo
e6c7e3832b remove Statement::run_once and create helper run_with_row_callback 2025-12-19 17:20:45 -03:00
pedrocarlo
47bea6ae94 add interrupt error variant 2025-12-19 17:20:45 -03:00
pedrocarlo
d6ee4a168b move Statement to separate file 2025-12-19 17:20:45 -03:00
Preston Thorpe
2e794934dd
Merge 'Use u64::from instead of .into()' from Elina
## Description
In certain edge cases, Into::into type inference fails and causes
library to fail to build in downstream crates
## Motivation and context
See https://github.com/ranile/turso-compile-fail
In this case, patching chrono to work with `ic-cdk` fails compilation of
turso. `ic-cdk` adds a dependency on `candid`, which provides some trait
implementations that make Into::into type inference break.
<details><summary>Error message</summary>
```
error[E0283]: type annotations needed
   --> /Users/me/.cargo/git/checkouts/turso-455557cd4a2364c7/2d78b53/core/mvcc/database/checkpoint_state_machine.rs:216:71
    |
216 |                         .is_some_and(|txid_max_old| b <= txid_max_old.into())
    |                                                       --              ^^^^
    |                                                       |
    |                                                       type must be known at this point
    |
    = note: multiple `impl`s satisfying `u64: PartialOrd<_>` found in the following crates: `candid`, `core`:
            - impl PartialOrd for u64;
            - impl PartialOrd<candid::types::number::Int> for u64;
            - impl PartialOrd<candid::types::number::Nat> for u64;
help: try using a fully qualified path to specify the expected types
    |
216 -                         .is_some_and(|txid_max_old| b <= txid_max_old.into())
216 +                         .is_some_and(|txid_max_old| b <= <std::num::NonZero<u64> as Into<T>>::into(txid_max_old))
    |

error[E0283]: type annotations needed
   --> /Users/me/.cargo/git/checkouts/turso-455557cd4a2364c7/2d78b53/core/mvcc/database/checkpoint_state_machine.rs:226:67
    |
226 |                     .is_some_and(|txid_max_old| e <= txid_max_old.into())
    |                                                   --              ^^^^
    |                                                   |
    |                                                   type must be known at this point
    |
    = note: multiple `impl`s satisfying `u64: PartialOrd<_>` found in the following crates: `candid`, `core`:
            - impl PartialOrd for u64;
            - impl PartialOrd<candid::types::number::Int> for u64;
            - impl PartialOrd<candid::types::number::Nat> for u64;
help: try using a fully qualified path to specify the expected types
    |
226 -                     .is_some_and(|txid_max_old| e <= txid_max_old.into())
226 +                     .is_some_and(|txid_max_old| e <= <std::num::NonZero<u64> as Into<T>>::into(txid_max_old))
    |

error[E0283]: type annotations needed
   --> /Users/me/.cargo/git/checkouts/turso-455557cd4a2364c7/2d78b53/core/mvcc/database/checkpoint_state_machine.rs:242:90
    |
242 |                     .is_none_or(|txid_max_old| begin_ts.is_some_and(|b| b > txid_max_old.into()));
    |                                                                           -              ^^^^
    |                                                                           |
    |                                                                           type must be known at this point
    |
    = note: multiple `impl`s satisfying `u64: PartialOrd<_>` found in the following crates: `candid`, `core`:
            - impl PartialOrd for u64;
            - impl PartialOrd<candid::types::number::Int> for u64;
            - impl PartialOrd<candid::types::number::Nat> for u64;
help: try using a fully qualified path to specify the expected types
    |
242 -                     .is_none_or(|txid_max_old| begin_ts.is_some_and(|b| b > txid_max_old.into()));
242 +                     .is_none_or(|txid_max_old| begin_ts.is_some_and(|b| b > <std::num::NonZero<u64> as Into<T>>::into(txid_max_old)));
    |

For more information about this error, try `rustc --explain E0283`.
error: could not compile `turso_core` (lib) due to 3 previous errors
```
</details>
## Description of AI Usage
All code is hand-written

Reviewed-by: Nikita Sivukhin (@sivukhin)

Closes #4293
2025-12-19 14:46:33 -05:00
PThorpe92
fa13d2bb05
Fix error handling in the WAL checkpoint path 2025-12-19 12:58:48 -05:00
PThorpe92
b39a244772
fix io_uring hang: wake completion callback when >1 completion remaining 2025-12-19 12:58:48 -05:00
PThorpe92
9161f825c8
Fix commit path and fix io_uring issues 2025-12-19 12:58:47 -05:00
Pere Diaz Bou
fe94cfc175 core/mvcc: set_null_flag(false) when seek is called 2025-12-19 16:47:33 +01:00
Pere Diaz Bou
2dec8a6e00
Merge ' core/execute: use same code for generating rowid in mvcc as in btree' from Pere Diaz Bou
## Description
in `op_new_rowid` we already have code logic that encodes how to get the
last rowid correctly, this PR uses advantage of it in MVCC too but with
a few `lock` guards in place to not collide rowids
## Motivation and context
It is hard to maintain two ways of getting a new rowid so this tries to
fold mvcc with btree
## Description of AI Usage
None

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

Closes #4228
2025-12-19 16:45:27 +01:00
Nikita Sivukhin
a261440180 fix for windows 2025-12-19 16:44:34 +04:00
Nikita Sivukhin
69ccd1c0a4 fix clippy 2025-12-19 16:04:35 +04:00
Pekka Enberg
4c1bc1ba95
Merge 'Improve MVCC DX by dropping --experimental-mvcc flag' from Pekka Enberg
Some checks are pending
Build & publish @tursodatabase/database / db-bindings-x86_64-pc-windows-msvc - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / db-bindings-x86_64-unknown-linux-gnu - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-aarch64-apple-darwin - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-aarch64-unknown-linux-gnu - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-wasm32-wasip1-threads - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-x86_64-pc-windows-msvc - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-x86_64-unknown-linux-gnu - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / Test DB bindings on Linux-x64-gnu - node@20 (push) Blocked by required conditions
Build & publish @tursodatabase/database / Test DB bindings on browser@20 (push) Blocked by required conditions
Build & publish @tursodatabase/database / Publish (push) Blocked by required conditions
Python / sdist (push) Waiting to run
Python / Release (push) Blocked by required conditions
Python / configure-strategy (push) Waiting to run
Python / test (push) Blocked by required conditions
Python / lint (push) Waiting to run
Python / linux (x86_64) (push) Waiting to run
Python / macos-arm64 (aarch64) (push) Waiting to run
Rust / simulator (push) Waiting to run
Rust / test-limbo (push) Waiting to run
Rust / test-sqlite (push) Waiting to run
Rust / cargo-fmt-check (push) Waiting to run
Rust / build-native (blacksmith-4vcpu-ubuntu-2404) (push) Waiting to run
Rust / build-native (macos-latest) (push) Waiting to run
Rust / build-native (windows-latest) (push) Waiting to run
Rust / clippy (push) Waiting to run
Rust Benchmarks+Nyrkiö / tpc-h (push) Waiting to run
Rust Benchmarks+Nyrkiö / vfs-bench-compile (push) Waiting to run
Rust Benchmarks+Nyrkiö / bench (push) Waiting to run
Rust Benchmarks+Nyrkiö / clickbench (push) Waiting to run
Rust Benchmarks+Nyrkiö / tpc-h-criterion (push) Waiting to run
The DX is right now pretty terrible:
```
penberg@vonneumann turso % cargo run -- hello.db
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.15s
     Running `target/debug/tursodb hello.db`
Turso v0.4.0-pre.18
Enter ".help" for usage hints.
Did you know that Turso supports live materialized views? Type .manual materialized-views to learn more.
This software is in BETA, use caution with production data and ensure you have backups.
turso> PRAGMA journal_mode = 'experimental_mvcc';
  × Invalid argument supplied: MVCC is not enabled. Enable it with `--experimental-mvcc` flag in the CLI or by setting the MVCC option in `DatabaseOpts`

turso>
```
To add insult to the injury, many SDKs don't even have a way to enable
MVCC via database options. Therefore, let's remove the flag altogether.

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

Closes #4294
2025-12-19 13:59:34 +02:00
Nikita Sivukhin
78ed7bfc8b break try_wal_watermark_read_page into parts in order to allow async usage 2025-12-19 15:53:59 +04:00
Pere Diaz Bou
95cc293508 core/mvcc: Fix typos and use turso_assert
Use turso_assert to check cursor state, clean up lock handling,
and rename fields from last_rowid/intialized to max_rowid/initialized
2025-12-19 12:52:01 +01:00
Pekka Enberg
edd45ff7b8 Improve MVCC DX by dropping --experimental-mvcc flag
The DX is right now pretty terrible:

```
penberg@vonneumann turso % cargo run -- hello.db
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.15s
     Running `target/debug/tursodb hello.db`
Turso v0.4.0-pre.18
Enter ".help" for usage hints.
Did you know that Turso supports live materialized views? Type .manual materialized-views to learn more.
This software is in BETA, use caution with production data and ensure you have backups.
turso> PRAGMA journal_mode = 'experimental_mvcc';
  × Invalid argument supplied: MVCC is not enabled. Enable it with `--experimental-mvcc` flag in the CLI or by setting the MVCC option in `DatabaseOpts`

turso>
```

To add insult to the injury, many SDKs don't even have a way to enable
MVCC via database options. Therefore, let's remove the flag altogether.
2025-12-19 12:59:42 +02:00
Pere Diaz Bou
5b4bcfa508 core/mvcc: fix clippy issues 2025-12-19 11:26:05 +01:00
Pere Diaz Bou
55de098ad3
Merge 'Local sync server' from Nikita Sivukhin
This PR introduces local sync server and run tests for Go and Python
against it in CI
The local sync server implements 2 endpoints:
1. `/v2/pipeline` - subset of SQL over HTTP protocol (Hrana) to execute
logical push operations from the client
2. `/pull-updates` - endpoint which returns page updates for client to
apply locally
The implementation is based on the local database file with **disabled
checkpoint** in order to preserve whole DB history and allow server to
respond to client which can have arbitrary stale DB.
For implementation, sync server uses extra API exposed by the turso-core
under `conn-raw-api` feature which includes `wal_state` /
`wal_get_frame` methods.
Usage:
- `tursodb --sync-server 0.0.0.0:8080` - in-memory database
- `tursodb local.db --sync-server 0.0.0.0:8080` - local db file

Closes #4191
2025-12-19 11:05:12 +01:00
Pere Diaz Bou
1da6bfd313 core/execute: end_new_rowid on finish with random rowid 2025-12-19 10:43:22 +01:00
Pere Diaz Bou
77ab8c9085 core/mvcc: introduce RowidAllocator
RowidAllocator is a centralized lock protected rowid allocator that is
used to ask for a new rowid. The idea is to have single atomic i64 that
we can increment when we get asked to allocate a new rowid.
2025-12-19 10:43:22 +01:00
Pere Diaz Bou
3141c067ed tcl: exclude partial index for mvcc tcl tests 2025-12-19 10:43:22 +01:00
Pere Diaz Bou
ad88e56e86 core/execute: use same code for generating rowid in mvcc 2025-12-19 10:43:22 +01:00
Elina
694a030ca7
cargo fmt on correct rust version 2025-12-19 17:41:44 +08:00
Elina
e72a26aff9
Use u64::from instead of .into()
In certain edge cases, Into::into type inference fails and causes library to fail to build in downstream crates
2025-12-19 17:35:04 +08:00
Krishna Vishal
173baa7e0e Add tests 2025-12-19 08:53:58 +05:30
Krishna Vishal
8300f2dae7 Trim only ascii whitespace. Rust's .trim() removes unicode
whitespace too. While SQLite only removes ASCII whitespace.

Closes: https://github.com/tursodatabase/turso/issues/3679
2025-12-19 08:53:57 +05:30
Preston Thorpe
850450cf03
Merge 'add readonly checks to ensure we do not change the header' from Pedro Muniz
Some checks are pending
Python / configure-strategy (push) Waiting to run
Build & publish @tursodatabase/database / db-bindings-x86_64-pc-windows-msvc - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / db-bindings-x86_64-unknown-linux-gnu - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-aarch64-apple-darwin - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-aarch64-unknown-linux-gnu - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-wasm32-wasip1-threads - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-x86_64-pc-windows-msvc - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / sync-bindings-x86_64-unknown-linux-gnu - node@20 (push) Waiting to run
Build & publish @tursodatabase/database / Test DB bindings on Linux-x64-gnu - node@20 (push) Blocked by required conditions
Build & publish @tursodatabase/database / Test DB bindings on browser@20 (push) Blocked by required conditions
Build & publish @tursodatabase/database / Publish (push) Blocked by required conditions
Python / sdist (push) Waiting to run
Python / Release (push) Blocked by required conditions
Python / test (push) Blocked by required conditions
Python / lint (push) Waiting to run
Python / linux (x86_64) (push) Waiting to run
Python / macos-arm64 (aarch64) (push) Waiting to run
Rust / simulator (push) Waiting to run
Rust / test-limbo (push) Waiting to run
Rust / test-sqlite (push) Waiting to run
Rust / cargo-fmt-check (push) Waiting to run
Rust / build-native (blacksmith-4vcpu-ubuntu-2404) (push) Waiting to run
Rust / build-native (macos-latest) (push) Waiting to run
Rust / build-native (windows-latest) (push) Waiting to run
Rust / clippy (push) Waiting to run
Rust Benchmarks+Nyrkiö / vfs-bench-compile (push) Waiting to run
Rust Benchmarks+Nyrkiö / bench (push) Waiting to run
Rust Benchmarks+Nyrkiö / clickbench (push) Waiting to run
Rust Benchmarks+Nyrkiö / tpc-h-criterion (push) Waiting to run
Rust Benchmarks+Nyrkiö / tpc-h (push) Waiting to run
## Description
Add some readonly checks in header validation and `pragma journal_mode`
. Depends on #4279 being merged first, to avoid conflicts here.
<!--
Please include a summary of the changes and the related issue.
-->
## Motivation and context
Close #4270
<!--
Please include relevant motivation and context.
Link relevant issues here.
-->
## Description of AI Usage
AI again did most of the work here, as it is pretty basic stuff and
mostly boilerplate. The main usefullness for AI here was to write the
tests to check for these edge cases.
**Prompt:**
```
I want to Make sure readonly databases cannot modify header page on Database open nor call `pragma journal mode` to update the journal mode. I need you
to implement the necessary checks to ensure we can still continue working normally and emit warnings to show that we cannot change to mvcc. Lastly add
tests in `header_version.rs` to prove your modifications works.
```
<!--
Please disclose how AI was used to help create this PR. For example, you
can share prompts,
specific tools, or ways of working that you took advantage of. You can
also share whether the
creation of the PR was mainly driven by AI, or whether it was used for
assistance.
This is a good way of sharing knowledge to other contributors about how
we can work more efficiently with
AI tools. Note that the use of AI is encouraged, but the committer is
still fully responsible for understanding
and reviewing the output.
-->

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>
Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #4280
2025-12-18 17:06:08 -05:00
Preston Thorpe
887d52f316
Merge 'Simplify slot bitmap to remove complex unused optimizations' from Preston Thorpe
## Description
This PR greatly simplifies the slot bitmap used to track free pages in
the arena buffer pool.
## Motivation and context
An optimization was included that would allow for allocating multiple
contiguous buffers, with the objective being that they would be
coalesced into single buffers when submitting `pwritev` calls, for
things like WAL appends. This optimization was never implemented and we
are left with a very complex bitmap with lots of unused/unnecessary
logic.
## Description of AI Usage
This was mostly codex 5.2 with the prompt:
```
This project is a SQLite rewrite in Rust, it uses a BufferPool that allocates large arenas 
and tracks which slots are free using a bitmap. this bitmap is core/storage/slot_bitmap.rs.. 
it was originally designed in a way that would allow to request multiple buffers that
were contiguous in memory, so that they could be coalesced into a single `pwrite` operation later down the line. 
However this optimization was never implemented and the bitmap has a complex 'two-pointer' algorithm that we no 
longer need. please rewrite this slot_bitmap.rs to simplify and only allocate single buffers at a time, removing the need
for the two pointer hint system.
```

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

Closes #4277
2025-12-18 13:05:23 -05:00