Commit Graph

136 Commits

Author SHA1 Message Date
Pere Diaz Bou
334da8abbb core/mvcc/logical-log: refactor get log path in tests 2025-09-25 18:33:26 +02:00
Jussi Saurio
c07a227560 Merge 'core/mvcc/logical-log: load logical log from disk' from Pere Diaz Bou
## Description
Read transactions from logical log and load mvcc store based on the
contents onto transaction 0, which is the special transaction where we
will load all row versions that can be read by all new transactions.
## Todo
- [x] Testing for multiple transactions
- [ ] Lock multiple loading of same logical-log at the same time
- [x] Add column_count to format because if not it is hard to judge from
record alone.
- [x] Trim buffer read
I was thinking to implement the rest on another pr to not increase load
to review this one.

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

Closes #3323
2025-09-25 16:26:34 +03:00
Jussi Saurio
3d38c5a101 mvcc: disallow promote to exclusive tx if another tx committed in between 2025-09-25 11:50:09 +03:00
Jussi Saurio
7c86e7b9c4 merge conflicts with atomics PRs 2025-09-25 11:49:44 +03:00
Jussi Saurio
ede2a882f1 mvcc: revert connection schema changes in mv rollback 2025-09-25 08:43:00 +03:00
Jussi Saurio
1626ef046b mvcc: abort tx if other tx made a schema change in between 2025-09-25 08:43:00 +03:00
Jussi Saurio
864fa379dd mvcc: require exclusive transaction for schema changes 2025-09-25 08:42:59 +03:00
Jussi Saurio
49602f409f fixes after atomics merge conflicts 2025-09-25 08:16:52 +03:00
Jussi Saurio
3010dc0255 mvcc: add CheckpointStateMachine
performs a blocking, truncating checkpoint:

- when started, blocks any other transactions from starting
- writes all row versions to pager that havent already been
  checkpointed
- flushes them to wal
- checkpoints wal to db

in the case of added/deleted rows in table id 1 (sqlite schema),
also creates/destroys btrees accordingly
2025-09-25 08:12:13 +03:00
Jussi Saurio
429f305fe8 mvcc: add MvStore::get_next_table_id()
this assigns "synthetic" root page numbers instead of using the pager
or btree cursors to allocate pages. Actual page allocation will only
happen during checkpoint, since regular MVCC commit bypasses the
pager.
2025-09-25 08:12:13 +03:00
Jussi Saurio
8f33b31c3d mvcc: update global header on commit end 2025-09-25 08:12:13 +03:00
Jussi Saurio
7464d1c172 mvcc: remove tx from store when commit write set is empty
previously, this was leaking transaction IDs in the mv store.
2025-09-25 08:12:13 +03:00
Jussi Saurio
949e6dd728 mvcc: remove unused states and fields from CommitStateMachine
none of the pager commit related data and logic are used anymore,
so let's delete them.
2025-09-25 08:12:12 +03:00
Pere Diaz Bou
1478538cb9 core/mvcc/logical-log: load logical log from disk
Read transactions from logical log and load mvcc store based on the
contents onto transaction 0, which is the special transaction where we
will load all row versions that can be read by all new transactions.

- [ ] Testing for multiple transactions
- [ ] Lock multiple loading of same logical-log at the same time
- [ ] Add column_count to format because if not it is hard to judge from
record alone.
2025-09-25 02:15:28 +02:00
Pekka Enberg
b590b353eb core/mvcc: Wrap Transaction::database_header with RwLock 2025-09-24 15:19:00 +03:00
Pekka Enberg
f5d3962459 core: Wrap Connection::transaction_state with RwLock 2025-09-23 14:01:31 +03:00
Pekka Enberg
b94aa22499 core: Wrap Connection::schema in RwLock 2025-09-23 10:31:20 +03:00
Pekka Enberg
b857f94fe4 Merge 'core: Wrap Connection::pager in RwLock' from Pekka Enberg
Closes #3247
2025-09-23 07:29:09 +03:00
Pekka Enberg
aa454a6637 core: Wrap Connection::pager in RwLock 2025-09-22 17:02:08 +03:00
Jussi Saurio
4af49ef98c mvcc: simplify StateMachine
TransitionResult is an internal implementation detail that tells
an invocation of StateMachine::step() to continue looping, but it
is of no use to other callers.

For this reason, just return an IOResult from StateMachine::step()
which simplifies the result handling.
2025-09-22 16:37:31 +03:00
Jussi Saurio
6a20735fe0 mvcc: add blocking checkpoint lock
MVCC checkpoints are always TRUNCATE, plus they block all other transactions.
This guarantees that never need to let transactions read from the SQLite WAL.

In MVCC, the checkpoint procedure is roughly as follows:
- Take the blocking_checkpoint_lock
- Write everything in the logical log to the pager, and from there commit to the SQLite WAL.
- Immediately TRUNCATE checkpoint the WAL into the database file.
- Release the blocking_checkpoint_lock.
2025-09-22 12:40:19 +03:00
Jussi Saurio
ba7ae50eff mvcc: remove unused code related to is_logical_log()
is always logical log
2025-09-19 12:55:27 +03:00
Jussi Saurio
8555d81a62 mvcc: keep existing begin timestamp when upgrading mv tx to exclusive 2025-09-19 09:18:20 +03:00
Jussi Saurio
c289ab90bc mvcc: fix trying to end pager tx in rollback 2025-09-19 09:18:20 +03:00
Jussi Saurio
ed06c7c423 mvcc: fix hang when non-concurrent tx holds write lock 2025-09-19 09:18:20 +03:00
Jussi Saurio
30596de741 mvcc: dont set tx state to commit before actually committing 2025-09-19 09:18:20 +03:00
Pere Diaz Bou
abaf2118a3 clippy 2025-09-18 19:26:46 +02:00
Pere Diaz Bou
b40e699c8c core/mvcc: don't end pager tx on logical log 2025-09-18 19:12:45 +02:00
Pere Diaz Bou
0fd704d00f core/mvcc: begin_tx with logical log don't use pager 2025-09-18 18:39:57 +02:00
Pere Diaz Bou
3e7a074f82 core/mvcc: fix review comments 2025-09-18 18:27:57 +02:00
Pere Diaz Bou
ef341338dc core/mvcc: rebase fix 2025-09-18 18:24:55 +02:00
Pere Diaz Bou
ff3c79d5d7 remove mvvmode and set logical log as default 2025-09-18 18:22:25 +02:00
Pere Diaz Bou
e6eb3adcbd core/mvcc/logical-log: sync 2025-09-18 18:22:06 +02:00
Pere Diaz Bou
d53c64e84b core/schema: parse schema rows for MVCC transactions 2025-09-18 18:22:06 +02:00
Pere Diaz Bou
a0555c254d core/mvcc/logical-log: change schema on update 2025-09-18 18:22:06 +02:00
Pere Diaz Bou
50c18ada1c core/mvcc: logical log update header on commit 2025-09-18 18:22:06 +02:00
Pere Diaz Bou
e2824835dc fix all open_file use cases for mvcc mode 2025-09-18 18:22:05 +02:00
Pere Diaz Bou
050055b833 core/mvcc: do not start pager txns with logical log 2025-09-18 18:21:21 +02:00
Pere Diaz Bou
6b9fb2f181 core/mvcc: fix locks in logical log 2025-09-18 18:21:04 +02:00
Pere Diaz Bou
81a33bb25a core/mvcc: introduce LogicalLog simple append serializer 2025-09-18 18:21:04 +02:00
Pekka Enberg
ecbe2c231f core: Rename Connection::_db to db 2025-09-18 16:00:41 +03:00
Pere Diaz Bou
434daf4b10 core/mvcc: fmt 2025-09-17 12:18:44 +02:00
Pere Diaz Bou
1627590bc3 core/mvcc: add expect panic in case txn was not found 2025-09-17 12:12:24 +02:00
Pere Diaz Bou
88307197cc with_header mvcc update rc to arc 2025-09-17 11:50:24 +02:00
Pere Diaz Bou
64616dc2ca core/mvcc: introduce with_header for MVCC header update tracking
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.
2025-09-17 11:42:44 +02:00
Jussi Saurio
9a2797963a Merge 'Remove LimboResult enum and InsnFunctionStepResult::Busy variant' from Jussi Saurio
We can just use `LimboError::Busy` for both of these.

Reviewed-by: Pekka Enberg <penberg@iki.fi>

Closes #3170
2025-09-17 12:06:54 +03:00
Jussi Saurio
dc103da2ed Remove LimboResult
this is only used for returning LimboResult::Busy, and we already
have LimboError::Busy, so it only adds confusion.

Moreover, the current busy handler was not handling LimboError::Busy,
because it's returned as an error, not as Ok. So this may fix the
"busy handler not working" issue in the perf thrpt benchmark.
2025-09-17 11:04:44 +03:00
Pekka Enberg
17e9f05ea4 core: Convert Rc<Pager> to Arc<Pager> 2025-09-17 09:32:49 +03:00
Jussi Saurio
d9e7b7f0e1 mvcc: starting a pager read tx can fail with busy 2025-09-16 15:19:49 +03:00
Jussi Saurio
e012768549 mvcc: dont allow CONCURRENT transaction to overwrite others changes
We start a pager read transaction at the beginning of the MV transaction, because
any reads we do from the database file and WAL must uphold snapshot isolation.
However, we must end and immediately restart the read transaction before committing.
This is because other transactions may have committed writes to the DB file or WAL,
and our pager must read in those changes when applying our writes; otherwise we would overwrite
the changes from the previous committed transactions.

Note that this would be incredibly unsafe in the regular transaction model, but in MVCC we trust
the MV-store to uphold the guarantee that no write-write conflicts happened.
2025-09-16 15:03:26 +03:00