Commit Graph

6 Commits

Author SHA1 Message Date
Glauber Costa
e6f0981b43 simulator: correct MVCC rowid assumptions and validation
Under MVCC, implicit rowid allocation behaves like a sequence: the next
value comes from a high-water mark that a rollback does not lower, so an
aborted insert consumes its rowid for good and the next insert skips
past it. This is deliberate — we do not guarantee that a rolled-back
allocation is handed back, matching PostgreSQL sequences, where nextval
is never rolled back and aborted transactions leave permanent gaps.
(AUTOINCREMENT already behaved this way; the same rule now covers plain
INTEGER PRIMARY KEY rowids.) WAL mode, like SQLite, reuses the freed
value.

The simulator makes exact-row assertions, and it cannot predict a
post-rollback rowid without modeling that watermark. Rather than model
it, generate explicit integer primary keys in MVCC INSERT and UPSERT
workloads, so the assertions no longer assume rolled-back allocations
come back. WAL mode keeps generating implicit keys.

Check MVCC integrity with Turso, which can read the logical-log state
SQLite cannot, and keep the SQLite integrity check for WAL. Export the
logical log from the in-memory I/O so a retained failure artifact
includes committed state.

Tests: 21 generator tests, the MVCC profile regression, and
deterministic integrity and export regressions pass.
2026-10-12 19:56:09 -05:00
Pavan Nambi
8157411019 simulator: model durable file state across power loss
Keep completed file mutations separate from the bytes protected by a
successful sync so power loss can discard unsynced writes and truncations.

Cancel pending I/O at the crash boundary, invalidate old file handles,
and retain mutation completion order when updating durable bytes.
2026-09-08 18:15:24 +05:30
Pekka Enberg
48df0b70db core: Switch to file ID for database registry mapping
The previous approach (34db5d989) tried to detect stale DATABASE_MANAGER
entries by storing the inode at open time and comparing it on lookup.
This required a zero sentinel for unknown inodes, platform cfg gates
everywhere, and silently assumed a match when identity couldn't be
determined — all of which papered over the real problem: path strings
are the wrong key for a file registry.

Like SQLite's inodeList, the process-wide database registry is now keyed
by (device, inode) instead of canonical path strings. This makes stale
entry detection impossible by construction: a deleted-and-recreated file
has a different inode, so it naturally gets a fresh registry entry.
2026-03-31 19:05:52 +03:00
Jussi Saurio
95d82bc582 simulator: make MemorySimIO reads return short reads, not panics
MemorySimIO read handling assumed the requested range always existed in the

in-memory file buffer and indexed directly into slices. Under fault-heavy runs,

that produced out-of-bounds panics instead of an I/O-style result.

This change gives MemorySimIO pread behavior that matches real file I/O:

- read past EOF returns 0 bytes

- partial range returns the available prefix

- unread tail bytes in the destination buffer are zero-filled for deterministic tests

Short-read detection remains the caller's job via completion callbacks, which is

how the real IO stack reports short reads today.
2026-02-24 09:33:42 +02:00
Glauber Costa
b49254116f feat: add ATTACH database infrastructure to deterministic simulator
Add full infrastructure for testing ATTACH databases in the simulator:
- SimulatorEnv tracks attached databases with path helpers and cleanup
- Selective per-file fault injection via inject_fault_selective() on SimIO
- CREATE TABLE redirect to attached DBs (30% probability) in plan generation
- Proper QualifiedName/DoublyQualified handling for dotted table names in
  sql_generation (FROM clauses, column references, result columns)
- Re-ATTACH on database reopen with DatabaseOpts::with_attach(true)
- Fix core/connection.rs attach_database() to reuse parent DB IO instead
  of creating a new PlatformIO (enables simulator fault injection)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 12:08:51 -05:00
pedrocarlo
68701b1011 move simulator and docker runner to testing/simulator 2026-01-20 12:24:03 -03:00