Commit Graph

8829 Commits

Author SHA1 Message Date
Pekka Enberg
a5f1bdbc9d Merge 'perf/throughput/turso: Don't interleave concurrent transactions in on…' from Pekka Enberg
…e connection
With BEGIN CONCURRENT, we cannot use the same connection all the time
because there's no way for the transaction manager to know which
transaction belongs to what "session" -- they're all individual
statements executed in the context of the one connection.
Fixes #3093

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

Closes #3094
2025-09-14 11:33:20 +03:00
Pekka Enberg
222b9e7ca2 Merge 'perf/throughput/turso: Don't execute futures serially' from Pekka Enberg
Looping through the futures means we're essentially executing them
serially.

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

Closes #3092
2025-09-14 11:01:06 +03:00
Pekka Enberg
6e9ba4c561 perf/throughput/turso: Don't interleave concurrent transactions in one connection
With BEGIN CONCURRENT, we cannot use the same connection all the time
because there's no way for the transaction manager to know which
transaction belongs to what "session" -- they're all individual
statements executed in the context of the one connection.

Fixes #3093
2025-09-14 10:52:56 +03:00
Pekka Enberg
98af9386e2 perf/throughput/turso: Don't execute futures serially
Looping through the futures means we're essentially executing them
serially.
2025-09-14 10:07:21 +03:00
Preston Thorpe
4e4f0ea61f Merge 'Dont grab page cache write lock in a loop' from Preston Thorpe
durp

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

Closes #3088
2025-09-13 12:48:19 -04:00
PThorpe92
f6dd0bc4d6 Dont grab page cache write lock in a loop 2025-09-13 12:21:13 -04:00
Pekka Enberg
6a2f0d6061 Merge 'Add per page checksums' from Avinash Sajjanshetty
This patch adds checksums to Turso DB. You may check the design here in
the [RFC](https://github.com/tursodatabase/turso/issues/2178).
1. We use reserved bytes (8 bytes) to store the checksums. On every IO
read, we verify that the checksum matches.
2. We use twox hash for checksums.
3. Checksum works only on 4K pages now. It's a small change to enable
for all other sizes, I will send another PR.
4. Right now, it's not possible to switch to different algorithm or turn
off altogether. That will be added in the future PRs.
5. Checksums can be enabled only for new dbs. For existing DBs, we will
disable it.
6. To add checksums for existing DBs, we need vacuum since it would
require rewrite of whole db.

Closes #2840
2025-09-13 18:46:53 +03:00
Pekka Enberg
7f5038f7c9 Merge 'perf/throughput/turso: Async transactions with concurrent mode' from Pekka Enberg
With `BEGIN CONCURRENT`, we should also take advantage of async
transaction processing to maximize concurrency.

Closes #3082
2025-09-13 15:07:29 +03:00
Pekka Enberg
7d3ce68695 Merge 'core/throughput: Add per transaction think time support' from Pekka Enberg
Closes #3080
2025-09-13 14:07:30 +03:00
Pekka Enberg
898f32f7f7 Fix Antithesis Dockerfile to include whopper 2025-09-13 13:33:11 +03:00
Pekka Enberg
3733d3856a Merge 'core: Panic on fsync() error by default' from Pekka Enberg
Retrying fsync() on error was historically not safe ("fsyncgate") and
Postgres still defaults to panicing on fsync(). Therefore, add a
"data_sync_retry" pragma (disabled by default) and use it to determine
whether to panic on fsync() error or not.

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

Closes #3077
2025-09-13 13:32:07 +03:00
Pekka Enberg
0fad30a30d perf/throughput/turso: Async transactions with concurrent mode
With `BEGIN CONCURRENT`, we should also take advantage of async
transaction processing to maximize concurrency.
2025-09-13 13:25:16 +03:00
Pekka Enberg
8dc2e738a4 core/throughput: Add per transaction think time support 2025-09-13 13:02:43 +03:00
Pekka Enberg
d8f07fe3da core: Panic on fsync() error by default
Retrying fsync() on error was historically not safe ("fsyncgate") and
Postgres still defaults to panicing on fsync(). Therefore, add a
"data_sync_retry" pragma (disabled by default) and use it to determine
whether to panic on fsync() error or not.
2025-09-13 10:21:12 +03:00
Pekka Enberg
a7e34f1551 Merge 'Handle partial writes in unix IO for pwrite and pwritev' from Preston Thorpe
currently, `io_uring` is setup to handle partial writes for `pwritev`
(will add `pwrite` in subsequent PR), but unix and other IO back-ends
were not correctly setup for this.

Closes #3073
2025-09-13 09:08:43 +03:00
Pekka Enberg
f547a302cc Merge 'remove Stmt clone' from Lâm Hoàng Phúc
Closes #3076
2025-09-13 09:06:15 +03:00
Avinash Sajjanshetty
5256f29a9c Add checksums behind a feature flag 2025-09-13 11:00:39 +05:30
Avinash Sajjanshetty
06a824ec68 Add checksum tests 2025-09-13 11:00:39 +05:30
Avinash Sajjanshetty
1536f65f07 move test helper run_query to common module 2025-09-13 11:00:39 +05:30
Avinash Sajjanshetty
11030056c7 rename method to verify_checksum 2025-09-13 11:00:39 +05:30
Avinash Sajjanshetty
e010c46552 use checksums when reading/writing from db file 2025-09-13 11:00:39 +05:30
Avinash Sajjanshetty
4b59cf19e5 use checksums when reading/writing from wal 2025-09-13 11:00:39 +05:30
Avinash Sajjanshetty
14a1307720 Set reserved space as required when allocating page1 2025-09-13 11:00:39 +05:30
Avinash Sajjanshetty
3b410e4f79 set required reserved bytes while initialising the pager 2025-09-13 11:00:39 +05:30
Avinash Sajjanshetty
2e6943bfdf Add helper to read reserved bytes value from disk 2025-09-13 11:00:39 +05:30
Avinash Sajjanshetty
c2c1ec2dba Pass use usable_space() instead of hardcoding the value 2025-09-13 11:00:38 +05:30
Avinash Sajjanshetty
15266105f7 Update IOContext to carry checksum ctx 2025-09-13 11:00:38 +05:30
Avinash Sajjanshetty
3f72de3623 Add checksum module 2025-09-13 11:00:37 +05:30
TcMits
48522c1cc0 remove Stmt clone 2025-09-13 12:08:29 +07:00
PThorpe92
6098bca211 Handle partial writes in unix IO for pwrite and pwritev 2025-09-12 18:13:02 -04:00
Preston Thorpe
b1420904bb Merge 'fix(btree): advance cursor after interior node replacement in delete' from Jussi Saurio
## Problem
When a delete replaces an index interior cell, the replacement key is LT
the deleted key. Currently on the main branch, after the deletion
happens, the following call to BTreeCursor::next() stops at the replaced
interior cell.
This is incorrect - imagine the following sequence:
- We are executing a query that deletes all keys WHERE key > 5
- We delete <key=6> from an interior node, and take a replacement
<key=5> from the left subtree of that interior page
- next() is called, and we land on the interior node again, which now
has <key=5>, and we incorrectly delete it even though our WHERE
condition is key > 5.
## Solution
This PR:
- Tracks `interior_node_was_replaced` in CheckNeedsBalancing
- If no balancing is needed and a replacement occurred, advances once so
the next invocation of next() will skip the replaced cell properly
i.e. we prevent next() from landing on the replaced content and ensures
iteration continues with the next logical record.
## Details
This problem only became apparent once we started using indexes as valid
iteration cursors for DELETE operations in #2981
Closes #3045

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

Closes #3049
2025-09-12 17:37:01 -04:00
Pekka Enberg
1803d0bb5d test: Enable some MVCC test cases
Suggested by Jussi
2025-09-12 23:11:45 +03:00
Pekka Enberg
ad6157028e Merge 'core/vdbe: Fix BEGIN CONCURRENT transactions' from Pekka Enberg
The transaction upgrade logic in Transaction opcode is total nonsense
for concurrent transactions so just drop it.
Fixes #3061

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>
Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #3070
2025-09-12 23:11:12 +03:00
Pekka Enberg
a0921c4221 Merge 'core/storage: Remove unused import warning' from Pekka Enberg
Closes #3069
2025-09-12 23:11:05 +03:00
Pekka Enberg
5e2b1bc0d3 Merge 'Fix incompatible math functions' from Levy A.
Fixes #1817, #2068, #1326, #1397.
The solution is very much not ideal, but fixes all math function related
incompatibilities.

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

Closes #3033
2025-09-12 21:28:08 +03:00
Pekka Enberg
86dcdad3d0 core/vdbe: Fix BEGIN CONCURRENT transactions
The transaction upgrade logic in Transaction opcode is total nonsense
for concurrent transactions so just drop it.

Fixes #3061
2025-09-12 21:19:34 +03:00
Pekka Enberg
2bc8c0c850 core/storage: Remove unused import warning 2025-09-12 21:09:38 +03:00
Pekka Enberg
dcd43ab8fc Merge 'Handle EXPLAIN QUERY PLAN like SQLite' from Lâm Hoàng Phúc
After this PR:
```
turso> EXPLAIN QUERY PLAN SELECT 1;
QUERY PLAN
`--SCAN CONSTANT ROW
turso> EXPLAIN QUERY PLAN SELECT 1 UNION SELECT 1;
QUERY PLAN
`--COMPOUND QUERY
   |--LEFT-MOST SUBQUERY
   |  `--SCAN CONSTANT ROW
   `--UNION USING TEMP B-TREE
      `--SCAN CONSTANT ROW
turso> CREATE TABLE x(y);
turso> CREATE TABLE z(y);
turso> EXPLAIN QUERY PLAN SELECT * from x,z;
QUERY PLAN
|--SCAN x
`--SCAN z
turso> EXPLAIN QUERY PLAN SELECT * from x,z ON x.y = z.y;
QUERY PLAN
|--SCAN x
`--SEARCH z USING INDEX ephemeral_z_t2
turso>
```

Closes #3057
2025-09-12 20:41:23 +03:00
Pekka Enberg
b2d0de796b Merge 'Fix simulator docker build chef by adding whopper directory' from Preston Thorpe
Closes #3068
2025-09-12 20:40:42 +03:00
PThorpe92
02743253ee Fix simulator docker build chef by adding whopper directory 2025-09-12 13:35:02 -04:00
Preston Thorpe
1752266285 Merge 'Update epoch on each checkpoint to prevent using stale pages for backfilling' from Preston Thorpe
Using this epoch that gets incremented on each checkpoint, combined with
snapshotting the page, allows us to use cached pages during even passive
mode (without the write lock), because we check again after the snapshot
that the page is still valid.
https://github.com/tursodatabase/turso/pull/3053#issuecomment-3285093103
This PR also removes the `WalFile` copy of the `WalHeader`, to prevent
us forgetting that it exists and using potentially stale data, and adds
`checkpoint_seq` atomic to WalFile to help us determine whether the log
has changed and a read tx snapshot is stale.

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

Closes #3058
2025-09-12 12:54:00 -04:00
PThorpe92
b04c364981 Fix clippy error 2025-09-12 11:43:38 -04:00
Pekka Enberg
5df05e05f8 Turso 0.2.0-pre.3 2025-09-12 18:40:06 +03:00
Pekka Enberg
9c08095abf Merge 'fix wasm-runtime package.json' from Nikita Sivukhin
Closes #3066
2025-09-12 18:39:49 +03:00
PThorpe92
7a14c7394f Remove the header copy stored on the WalFile, fix fast_path 2025-09-12 11:29:43 -04:00
PThorpe92
25e7c719f1 Update checkpoint_seq on each checkpoint, not just when log restarts
This was causing checkpoint_seq to be 0 when we had already successfully
ran a passive checkpoint, and causing us to use improper pages from the
cache.
2025-09-12 11:29:42 -04:00
Nikita Sivukhin
99759b9efd fix wasm-runtime package.json 2025-09-12 19:28:30 +04:00
Pekka Enberg
2651b597c6 Turso 0.2.0-pre.2 2025-09-12 17:38:30 +03:00
Pekka Enberg
14da283e36 Merge 'MVCC: remove reliance on BTreeCursor::has_record()' from Jussi Saurio
Closes #3051
Closes #3032

Closes #3056
2025-09-12 17:31:15 +03:00
Pekka Enberg
54b4c9f30b Merge 'Implement the balance_quick algorithm' from Jussi Saurio
Fast balancing routine for the common special case where the rightmost
leaf page of a given subtree overflows such that the overflowing cell
would be the rightmost cell on the page -- i.e. an append. In this case
we just add a new leaf page as the right sibling of that page, put the
overflow cell there, and insert a new divider cell into the parent. The
high level steps are:
1. Allocate a new leaf page and insert the overflow cell payload in it.
2. Create a new divider cell in the parent - it contains the page number
of the old rightmost leaf, plus the largest rowid on that page.
3. Update the rightmost pointer of the parent to point to the new leaf
page.
4. Continue balance from the parent page (inserting the new divider cell
may have overflowed the parent

Closes #3041
2025-09-12 17:30:52 +03:00