`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>
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
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
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>
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>
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>
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>
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
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.
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.
- 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