Files
turso/Dockerfile.antithesis
Pekka Enberg 50f3a217fb core/wal: fix multiprocess database file reader race
When the WAL is fully checkpointed, a new read transaction skips the WAL
and reads pages only from the database file. In multiprocess mode, other
processes could not see such a reader: it held read lock 0, but that
lock exists only inside its own process, and the reader did not register
in the shared reader table in the .tshm file. A checkpoint in another
process could therefore copy newer WAL frames into the database file
while the reader was still using its older snapshot, and the reader saw
a mix of old and new pages. The concurrent simulator hit this as FTS
index corruption.

Preston Thorpe's commit 121d5e5db, which added multiprocess WAL support,
did register these readers in the shared reader table, one slot per
reader. The follow-up commit 94c912fb0 removed the registration a day
later because many concurrent readers used up all the slots and new
connections failed with Busy. The test for that case was changed to
assert that these readers register nothing, so the missing protection
went unnoticed.

This change registers them again, but all such readers in one process
share a single slot, so they no longer run out of slots. While any
process has one registered, checkpoints in every process stop at the
current backfill point. This is the cross-process version of the read
lock 0 that a checkpoint already takes within one process, and it
matches SQLite. WAL restarts are still allowed, as in SQLite, because
these readers never read the WAL. Blocking restarts as well would make
the WAL grow without bound, because the restart before a write only runs
when the writer itself is one of these readers. A failed registration
now also releases the local read lock, which the WAL reader path used to
leak.

tlaplus/multiprocess/MultiprocessWal.tla models this coordination: the
local read locks, the shared reader table, the snapshot recheck when a
read begins, checkpoints that copy frames one at a time, and the restart
before a write. TLC checks every state of two processes with two
connections each and up to three commits (32 million states) and finds
no case where the database file holds a newer version than an active
reader's snapshot or where the WAL restarts under a WAL reader. With
database file readers left out of the shared reader table, TLC finds
this bug in 13 steps.

Aristo intents on the coordinator state the same rules at the code
sites that enforce them: the checkpoint safe frame stays below every
reader in every process, database file readers register in the shared
table and recheck the snapshot afterwards, the restart ignores database
file readers, and frame zero in a reader slot marks a database file
reader. One assume records that the tshm mapping is shared by every
process on the host.

testing/antithesis/multiprocess is a new Antithesis workload where
every driver is its own process and opens the database with the
multiprocess WAL feature. Writers stamp every row with the commit's
generation, so every commit rewrites every page. Readers pin a snapshot
by reading one row, then spawn a child process that commits and runs a
passive checkpoint under that snapshot, and then scan the whole table,
so the later pages come from the database file instead of the reader's
page cache. The child makes the cross-process overlap happen on every
read instead of waiting for the test composer to schedule it, which it
rarely does because it throttles parallel drivers on CPU use. A
checkpoint that copies newer frames under the snapshot shows up as rows
from two generations in one scan. Without the fix a local 30 second run
reports torn reads dozens of times; with the fix a 60 second run is
clean.

Tests: core/multiprocess_tests.rs
- subprocess_db_file_reader_stops_checkpoint_in_other_process
- subprocess_db_file_reader_allows_wal_restart_but_stops_backfill
- write_after_full_checkpoint_restarts_wal
Tests: testing/antithesis/multiprocess

Fixes #8648
2026-09-14 18:22:30 +03:00

99 lines
3.9 KiB
Docker

FROM lukemathwalker/cargo-chef:0.1.72-rust-1.88.0-slim-bookworm AS chef
RUN apt update \
&& apt install -y git libssl-dev pkg-config\
&& apt clean \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
#
# Cache dependencies
#
FROM chef AS planner
RUN --mount=type=bind,source=.,target=/app,ro \
cargo chef prepare --bin turso_stress --recipe-path /tmp/recipe.json
#
# Build the project.
#
FROM chef AS builder
ARG antithesis=true
RUN apt-get update && apt-get install -y pip && rm -rf /var/lib/apt/lists/*
RUN pip install --break-system-packages maturin
# Antithesis instrumentation library
ADD https://antithesis.com/assets/instrumentation/libvoidstar.so /opt/antithesis/libvoidstar.so
COPY --from=planner /tmp/recipe.json recipe.json
RUN cargo chef cook --bin turso_stress --release --recipe-path recipe.json
COPY . .
# Remove cdylib and staticlib from this line: `crate-type = ["lib", "cdylib", "staticlib"]`
# This is because somehow we lose llvm sanitizer coverage if the crate is not just a lib.
RUN for f in sdk-kit/Cargo.toml sync/sdk-kit/Cargo.toml; do \
grep -qF 'crate-type = ["lib", "cdylib", "staticlib"]' "$f" \
|| { echo "ERROR: expected crate-type not found in $f"; exit 1; }; \
done \
&& sed -i 's/crate-type = \["lib", "cdylib", "staticlib"\]/crate-type = ["lib"]/' \
sdk-kit/Cargo.toml sync/sdk-kit/Cargo.toml
RUN if [ "$antithesis" = "true" ]; then \
cp /opt/antithesis/libvoidstar.so /usr/lib/libvoidstar.so && \
export RUSTFLAGS="--cfg=tokio_unstable --cfg=antithesis -Ccodegen-units=1 -Cpasses=sancov-module -Cllvm-args=-sanitizer-coverage-level=3 -Cllvm-args=-sanitizer-coverage-trace-pc-guard -Clink-args=-Wl,--build-id -L/usr/lib/ -lvoidstar" && \
cargo build --bin turso_stress --profile antithesis; \
else \
cargo build --bin turso_stress --release; \
fi
WORKDIR /app/bindings/python
RUN maturin build
WORKDIR /app/testing/unreliable-libc
RUN make
#
# The final image.
#
FROM debian:bookworm-slim AS runtime
RUN apt-get update && apt-get install -y bash curl xz-utils python3 procps sqlite3 bc binutils pip rust-gdb && rm -rf /var/lib/apt/lists/*
RUN pip install --break-system-packages antithesis
WORKDIR /app
EXPOSE 8080
COPY --from=builder /usr/lib/libvoidstar.so* /usr/lib/
COPY --from=builder /app/testing/unreliable-libc/unreliable-libc.so /usr/lib/
COPY --from=builder /app/target/antithesis/turso_stress /bin/turso_stress
COPY --from=builder /app/target/antithesis/turso_stress /symbols
COPY testing/stress/docker-entrypoint.sh /bin
RUN chmod +x /bin/docker-entrypoint.sh
COPY --from=builder /app/target/wheels/* /tmp
RUN pip install --break-system-packages /tmp/*.whl
WORKDIR /app
COPY ./testing/antithesis/bank-test/*.py /opt/antithesis/test/v1/bank-test/
COPY ./testing/antithesis/stress-composer/*.py /opt/antithesis/test/v1/stress-composer/
COPY ./testing/antithesis/multiprocess/*.py /opt/antithesis/test/v1/multiprocess/
COPY ./testing/antithesis/stress /opt/antithesis/test/v1/stress
COPY ./testing/antithesis/stress-memory_yield /opt/antithesis/test/v1/stress-memory_yield
COPY ./testing/antithesis/stress-io_uring /opt/antithesis/test/v1/stress-io_uring
COPY ./testing/antithesis/stress-mvcc /opt/antithesis/test/v1/stress-mvcc
COPY ./testing/antithesis/stress-io_uring-mvcc /opt/antithesis/test/v1/stress-io_uring-mvcc
COPY ./testing/antithesis/stress-unreliable /opt/antithesis/test/v1/stress-unreliable
RUN chmod 777 -R /opt/antithesis/test/v1
RUN chmod -x /opt/antithesis/test/v1/multiprocess/helper_*.py /opt/antithesis/test/v1/stress-composer/helper_utils.py
RUN mkdir /opt/antithesis/catalog
RUN ln -s /opt/antithesis/test/v1/bank-test/*.py /opt/antithesis/catalog
RUN for f in /opt/antithesis/test/v1/multiprocess/*.py; do ln -s "$f" "/opt/antithesis/catalog/multiprocess_$(basename "$f")"; done
COPY testing/stress/targeted_coverage.jso[n] /opt/antithesis/
ENV RUST_BACKTRACE=1
ENTRYPOINT ["/bin/docker-entrypoint.sh"]