105 Commits

Author SHA1 Message Date
Raminder Singh
8dd0caac4e docs: fix 'cargo doc' warnings
`cargo doc --workspace --no-deps` reported many rustdoc warnings. Fix
them without changing what any comment says:

- Wrap bare URLs in `<` and `>` so rustdoc renders them as links.
- Drop explicit link targets that only repeat the link text.
- Point intra-doc links at the item's real path, or write names that
  rustdoc cannot resolve as plain code text.
- Escape `<` and `>` that are not HTML tags.
- Add the braces rustdoc needs to parse the example code blocks.

Tests: cargo doc --workspace --no-deps reports no rustdoc warnings

Co-authored-by: Pekka Enberg <penberg@iki.fi>
2026-10-06 10:18:26 +03:00
Jussi Saurio
b4a01498ce macros: remove a redundant string conversion 2026-09-08 13:16:07 +03:00
Claude
0d0fa52eae macros: evaluate turso_debug_assert conditions only in debug builds
turso_debug_assert! bound its condition to a local before handing it to
debug_assert!, so release builds still evaluated every condition and
only skipped the check. Conditions that call something fallible, like
`matches!(self.page_type(), Ok(PageType::TableLeaf))` in the cell
readers, cannot be optimized away because the error path builds a
LimboError, so every rowid read and every interior-cell probe of a
b-tree descent paid for a page type conversion it never used.

Put the condition inside debug_assert!, where it sits under
`if cfg!(debug_assertions)` and disappears from release code. The
antithesis build keeps the bound local, which it needs for its own
report.

Measured with callgrind, instructions per execution:
  SELECT * FROM t WHERE id = 12345:            7,878 -> 7,532 (-4.4%)
  SELECT id FROM t WHERE value = 500 LIMIT 1: 13,527 -> 13,605 (+0.6%)
  SELECT 1:                                    1,801 -> 1,813 (+0.7%)
and per row of SELECT * FROM t, the rowid read no longer converts the
page type: BTreeCursor functions 109,832,094 -> 106,632,094 over 400k
rows (-8 per row). The other two statements and the whole-scan totals
move by +-1% with the changed inlining inside Program::step, which this
change does not touch.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Feji9LAGhf6W4U2BBE6aWs
2026-09-07 10:35:29 -07:00
Mikaël Francoeur
907174f3db Merge 'Exercise MVCC recovery in turso_stress (v2)' from Mikaël Francoeur
This is a simple version of
https://github.com/tursodatabase/turso/pull/7489
I did a bunch of refactoring to make `main.rs` in turso-stress have less
responsibilities and be easier to work with. Unfortunately the commit
history isn't as nice as I would have wanted, so the diff may be a bit
messy.
Here's what's going on in this PR:
* extracted logging to a `Tracer` type
* extracted SQL logging (to a file) to a `SqlLogger` type
* extracted progress bars to a `Progress` type
* encapsulated post-statement SQL logging inside a `StressConn` type
* encapsulated closing/reopening in a `StressDb` type
* moved the ddl up so that it was performed only once (previously we
performed the same DDL setup once per thread, which I think was a
mistake). This was necessary because without this fix, threads with
higher indexes barely got any attention, because by the time threads 0
or 1 requested a synchronization, they were still performing their
initialization.
* restored `turso_assert_reachable!` (it was a no-op), and added one
invocation to MVCC recovery, so that we'll know if we ever have a
regression and it's not exercised in Antithesis anymore.
* changed how the loop is structured, so that all the DBs are dropped at
the same time, thereby exercising MVCC recovery
Handwritten. I used Claude to figure out bugs (I had a few deadlocks and
starvation issues while coding this).

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

Closes #7571
2026-06-25 08:25:15 -04:00
Mikaël Francoeur
d11fa38b5b restore turso_assert_reachable
Restore the turso_assert_reachable! macro (it had been turned into a
no-op) and add one invocation to MVCC recovery, so that a regression in
which MVCC recovery is no longer exercised is detected even though
turso_stress is no longer run under Antithesis.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 08:19:18 -07:00
pedrocarlo
bec8aa1b6f ci: shard codspeed benchmarks by toolchain 2026-06-19 15:22:50 -03:00
pedrocarlo
cc07fa9c55 mvcc: add allocation site instrumentation 2026-06-19 01:26:38 -03:00
PThorpe92
87cfcaaa12 add plumbing in extension lib + macros for Context-based scalar functions 2026-05-27 15:51:35 -04:00
Marc-André Moreau
a4fab8fffb Add managed aggregate callbacks
Port aggregate callback registration and runtime support on top of the merged scalar and extension-loading foundation. This wires aggregate contexts through extension registration, supports variadic call-site arity, handles external aggregate step/final cleanup, and adds focused integration coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-27 08:48:18 -04:00
PThorpe92
59b0c9f334 rustfmt 2026-05-26 15:43:39 -04:00
PThorpe92
aefd6a7ab0 remove scalar_context macro, defer to future work 2026-05-26 15:39:30 -04:00
Marc-André Moreau
7acee874fa Add context-aware scalar macro
Keep the simple scalar macro ergonomic while adding scalar_context for callbacks that need context and destructor metadata. Pass the scalar metadata through the extension callback ABI and cover it in managed scalar integration tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-26 15:39:29 -04:00
Marc-André Moreau
17888313e1 Deduplicate managed scalar value ABI
Reuse turso_ext::Value for managed scalar results instead of adding a parallel ContextValue type. Carry context, arity, determinism, and destructor metadata through the existing scalar registration path and update macros/tests accordingly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-26 15:39:29 -04:00
pedrocarlo
7d14deda67 Format stack report paths from tracing spans 2026-04-29 15:31:44 -03:00
pedrocarlo
988f734d23 Use trace_stack macro for scoped traces 2026-04-29 15:31:44 -03:00
pedrocarlo
c9b70d8df9 Use trace_stack attribute for function tracing 2026-04-29 15:31:44 -03:00
pedrocarlo
0392028879 tzx 2026-04-29 15:31:44 -03:00
Pekka Enberg
3fc00260b0 Merge 'core/mvcc: Make MVCC encryption less memory hungry with chunking' from Avinash Sajjanshetty
This PR builds on top of #5836. In the previous PR, we encrypted entire
frame as one. This adds a chunking optimisation. If the tx frame is
below 32KB, we encrypt the whole thing. Otherwise we split it into
chunks of 32KB and operate.
Why 32KB? picked some size, I felt not to big to hold in memory and not
so small that it adds lots of overhead.
## Why
In MVCC log, each log item is Tx Frame, each frame contains multiple ops
(insert/update etc). The payload size is not fixed (unlike 4KB fixed
size in a WAL), it can be anything. If we don't do chunking, we have to
keep entire payload in the memory while encrypting it (during write
path). With chunking, we can keep only upto chunk size and keep writing
to disk. Similar thing applies while reading from disk, we can keep
reading the part as we require it and decrypt it, as supposed to read
everything to decrypt.
We want to do this _now_ because encryption maps to disk format. If we
want to introduce such optimisation tomorrow, we have to do it with
versioning.
This is not a CPU performance optimisation, rather more like
optimisation in the algorithm, the direct effect would in reduction of
memory usage.
## Encrypted Chunking for MVCC Logical Log
  ### Frame Layout: Unencrypted vs Encrypted
  ```text
  Unencrypted:
  ┌──────────────┬──────────────────────────────┬───────────┐
  │ TX Header    │ Payload                      │ Trailer   │
  │ (24B plain)  │ Op₀ | Op₁ | Op₂ | ...        │ CRC + End │
  └──────────────┴──────────────────────────────┴───────────┘

  Encrypted (chunked):
  ┌──────────────┬──────────┬──────────┬──────────┬───────────┐
  │ TX Header    │ Chunk 0  │ Chunk 1  │ Chunk N  │ Trailer   │
  │ (24B plain)  │ ct|n     │ ct|n     │ ct|n     │ CRC + End │
  └──────────────┴──────────┴──────────┴──────────┴───────────┘
                      │
                      ▼
                ┌───────────────────────────┬───────┐
                │ ciphertext (plain + tag)  │ nonce │
                └───────────────────────────┴───────┘
  ```
  Each chunk encrypted with AAD (32B):
  ```text
  ┌────────┬────────────────────┬──────────┬────────────┬─────────────┐
  │salt (8)│payload_size_or_0(8)│op_cnt (4)│commit_ts(8)│chunk_idx (4)│
  └────────┴────────────────────┴──────────┴────────────┴─────────────┘
            ↑
            └── payload_size only in final chunk; zero for all others
  ```
  ### How Plaintext Payload Is Split Into Chunks
  ```text
  Plaintext payload (serialized ops, payload_size bytes):

  ┌──────┬──────┬────────────┬──────────┬──────┬────────────┬──────┬──────┬──────┬───────┐
  │ Op₀  │ Op₁  │    Op₂     │   Op₃    │ Op₄  │    Op₅     │ Op₆  │ Op₇  │ Op₈  │ Op₉   │
  └──────┴──────┴─────┼──────┴──────────┴──────┴──────┼─────┴──────┴──────┴──────┴───────┘
                      │                               │
                32 KB boundary                   64 KB boundary

  Chunking splits at fixed 32 KB boundaries — ops may straddle them:

    Chunk 0 (32 KB)              Chunk 1 (32 KB)              Chunk 2 (remainder)
  ┌──────┬──────┬──────┐     ┌──────┬──────┬──────┬──────┐   ┌──────┬──────┬──────┬──────┐
  │ Op₀  │ Op₁  │ Op₂▌ │     │▐Op₂  │ Op₃  │ Op₄  │ Op₅▌ │   │▐Op₅  │ Op₆  │ Op₇  │ ...  │
  └──────┴──────┴──────┘     └──────┴──────┴──────┴──────┘   └──────┴──────┴──────┴──────┘
                 ├─── Op₂ split across chunks 0 & 1 ───┤              │
                                           ├── Op₅ split across chunks 1 & 2 ──┤

    Op₂ starts in chunk 0, ends in chunk 1.  The reader uses a "carry buffer"
    to accumulate the partial op across chunk boundaries before parsing.

              │                          │                       │
              ▼                          ▼                       ▼
        ┌───────────┬────┐         ┌───────────┬────┐     ┌───────────┬────┐
        │ciphertext₀│ N₀ │         │ciphertext₁│ N₁ │     │ciphertext₂│ N₂ │
        │(32KB+tag) │    │         │(32KB+tag) │    │     │(rem+tag)  │    │
        └───────────┴────┘         └───────────┴────┘     └───────────┴────┘
         on-disk chunk blob         on-disk chunk blob     on-disk chunk blob

  Each chunk is encrypted independently with AEAD. The reader decrypts one chunk
  at a time. If an op is incomplete at the end of a chunk, the leftover bytes go
  into a carry buffer and are joined with bytes from the next decrypted chunk.
  ```
Used Codex, but with multiple iterations.

Reviewed-by: Nikita Sivukhin (@sivukhin)

Closes #6174
2026-04-09 12:16:53 +03:00
Avinash Sajjanshetty
356f7b411c Add a macro to run existing tests with encryption 2026-04-02 20:17:44 +05:30
Mike Marcacci
5f0dd76761 Use BTreeMap instead of Hashmap in macro
The latter has arbitrary, nondeterministic iteration order, leading to non-reproducible builds.
2026-04-01 09:13:21 -07:00
Mikaël Francoeur
76680551f0 partial virtual column support 2026-03-24 11:38:05 -04:00
PThorpe92
009c8a9ba6 Remove experimental flag from triggers, enable by default 2026-03-06 15:54:44 -05:00
Jussi Saurio
39bddab132 Merge 'Fix materialized view re-entrancy bug' from Martin Mauch
Fix bug in materialized view where it didn't handle IO from seek
properly.

Closes #4084
2026-02-18 21:28:50 +02:00
Martin Mauch
d7070669a7 Reproduce bug regarding materialized views and btree balancing 2026-02-18 18:27:20 +01:00
Mikaël Francoeur
fd7bd44b63 use Debug instead of Serialize 2026-02-18 08:44:50 -05:00
Mikaël Francoeur
45abf9b0cf Reapply "Merge 'Use new Antithesis assertions' from Mikaël Francoeur" 2026-02-18 08:44:50 -05:00
Pekka Enberg
80db011182 Revert "Merge 'Use new Antithesis assertions' from Mikaël Francoeur"
This reverts commit 73d48edeb4, reversing
changes made to 6acfa563ab because it breaks
the Antithesis Docker build.
2026-02-17 08:57:12 +02:00
Mikaël Francoeur
da4912611d remove format-args support from turso assertion macros 2026-02-16 14:21:46 -05:00
Mikaël Francoeur
2e3594c42a extract helpers from macros 2026-02-10 10:11:59 -05:00
Jussi Saurio
d76a3b7343 mark attach as experimental 2026-01-05 09:52:02 +02:00
Jussi Saurio
9517c1290f don't test macro comments - theyre just an illustration 2025-12-22 12:24:06 +02:00
Jussi Saurio
2bf7ec5136 mark triggers as experimental 2025-12-21 21:18:15 +02: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
Pekka Enberg
98d0d755c7 macros: Remove unused Debug derive from Args struct
syn::Expr doesn't implement Debug by default, which caused
turso_macros to fail packaging for crates.io. The Debug derive
wasn't used anywhere, so removing it fixes the build.
2025-12-17 10:17:57 +02:00
Jussi Saurio
826ca4d44d chore: remove experimental_indexes feature flags 2025-12-08 13:00:37 +02:00
Jussi Saurio
ea905d276c Merge 'Add #[turso_macros::test] to automatically create tests that can run MVCC with minimal code changes' from Pedro Muniz
- added procedural macro that creates Rust tests and with just a flag,
creates a new test that runs the same with MVCC enabled
- migrated almost all tests to use this new macro and added the mvcc
flag to the tests that were not failing
- added a `TempDatabase` builder to facilitate the proc_macro to
generate the correct database options

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

Closes #3991
2025-11-27 21:53:09 +02:00
Pekka Enberg
36d2dfcbad macros: Replace unwrap() with expect() in generate_get_description() 2025-11-22 09:57:44 +02:00
Pekka Enberg
7b1b06a128 macros: Eliminate unwrap() calls in derive_atomic_enum_inner() 2025-11-22 09:57:44 +02:00
Pekka Enberg
bdbcfaa28b macros: Eliminate unwrap() in match_ignore_ascci_case() 2025-11-22 09:57:44 +02:00
pedrocarlo
a3acec58df clippy 2025-11-19 23:42:46 -03:00
pedrocarlo
99f895256d add docs to macro 2025-11-19 23:28:23 -03:00
pedrocarlo
0ffda31549 add init_sql arg to proc macro 2025-11-19 12:08:18 -03:00
pedrocarlo
1e85706d54 pass the fn arg type to the macro closure to avoid errors 2025-11-19 11:49:53 -03:00
pedrocarlo
19bb802f97 create two tests when mvcc flag is passed 2025-11-19 11:49:53 -03:00
pedrocarlo
237ce5b601 enhance proc macro to detect the fn args and the return type with better spans 2025-11-19 11:49:53 -03:00
pedrocarlo
696bf2252c create a basic test proc macro that takes a db path and an mvcc flag 2025-11-19 11:49:53 -03:00
PThorpe92
e09d9eb720 Add VBegin, VRename, VRollback and VCommit opcodes 2025-11-09 11:07:42 -05:00
PThorpe92
a8b257c664 Replace several RwLock<Enum> values with new AtomicEnums 2025-10-22 09:35:26 -04:00
PThorpe92
123a26b7d9 Add AtomicEnum macro macros crate 2025-10-22 09:27:14 -04:00
TcMits
4bb6b02b65 clean PR 2025-09-14 19:03:09 +07:00