Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ jobs:
make ${{ matrix.make }} dist/loadable
echo 'set -e; cd /data/local/tmp; export TMPDIR=/data/local/tmp; ./loadable ./multiwriter.so; echo EXIT_CODE=0' > dist/commands.sh

# The runner has /dev/kvm but not for the runner's user: without it the action runs the emulator with -accel off, which the emulator refuses since version 37 ("Software CPU
# emulation (-accel off) is not supported"). With KVM the emulator is accelerated (the setup that the action documents).
- name: android emulator - enable KVM
if: matrix.test == 'emulator'
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: android emulator - run
if: matrix.test == 'emulator'
uses: reactivecircus/android-emulator-runner@v2.34.0
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@
All notable changes of sqlite-multiwriter are recorded here, newest first. The version is `MW_VERSION` in `src/multiwriter.h`; a version that is not released yet is pushed to `main` and released by the CI.
The format of the files on disk (`-mwlock`, `-mwidx`, `-mw.N`, `-mw`) is the same in the versions listed here.

## 0.7.0 - 2026-11-27

### Changed
- **Speculative snapshots of the writers** (one process). A write transaction (its first statement writes, or `BEGIN IMMEDIATE`/`EXCLUSIVE`) reads at the newest *installed* commit instead of the newest durable one, and is still acknowledged only when its own record is durable (the log is durable as a prefix, so never without the commits it read). Commits that depend on each other, above all inserts with the rowid that SQLite picks (each one takes the key after the last one it sees), used to follow each other one fsync at a time: with 24 writers and an fsync of about 3 ms, 333 tx/s, p99 694 ms, 545 retries per 100 tx; now 2,547 tx/s, p99 20 ms, 7 retries (the workload of the external comparison "SQLite vs WAL vs Turso MVCC vs sqlite-multiwriter", `bench/events_bench.c`, `MW_FULLFSYNC=1` on this Mac). A transaction that does not write reads only durable commits as before; one that read speculatively and ends without a commit waits until what it read is durable; a commit whose record could not be written is taken back and the transactions that read it are refused (`SQLITE_BUSY_SNAPSHOT`). URI `mw_spec=0` turns it off for a connection, `MW_NO_SPEC=1` for the process (the default stays on). The processes mode is unchanged.
- The rebase: its helper reads speculatively too (at least what the transaction it replays read), and the publication gate that it closes after a lost replay waits until every assigned commit is installed, not durable (waiting for their fsync held every publisher: `samepage` with the rebase, 64 threads on Linux, 15.5k -> 20.6k tx/s against 17.6k before this change).
- Hot spots (one process): with speculative snapshots the turn is taken after the first refusal (it was after 16) and given back as soon as the commit is installed or conflicts (it was at the end of the transaction, after the fsync). Retries per 100 tx of the appends above: 131-143 -> 7 with a fast fsync, 105-111 -> 13-18 with `synchronous=OFF`, and the p99.9 latency 60-175 ms -> 2-56 ms.
- `mw_bench`, threads, `synchronous=FULL`, 4/16/64 writers: `hot` +9%..+160%, `groups`, `samepage`, `cols`, `insert-autoinc`, `crdtinsert` without the rebase +13%..+500%, with it mostly higher too; `bulk`, `independent`, `mixed` unchanged (within ±5%). Lower: `samepage` with the rebase at 4-16 writers on macOS (-9..-11%: more commits take the fast path, one fsync each, instead of the batched replays). On Linux (Docker, fsync about 0.3 ms) the contended workloads go from 1-4k to 17-34k tx/s (the engine without the change collapses under contention), the appends of the comparison with 24 writers from 1,820 to 7,625 tx/s; with no durable fsync (tmpfs, `synchronous=OFF`) they are 3-7% slower from 8 writers up, with a p99 4-5 times lower.

### Fixed
- **Processes mode: a commit could be acknowledged without an fsync of the log.** A committer that becomes the leader of the group sync and finds its own record made durable already (by the leader before it, which finished between its look and its turn) syncs nothing, but it still moved the durable point to the end of the log as it read it, after the others had installed more records: those were acknowledged with nothing synced, and a power failure could lose them. It now moves the durable point only after its own `msync` and `fsync`. Found by `mw_syncwindow` in the CI (linux-x86_64, about 1 run in 20 on a Linux of 4 CPUs, also before 0.7); its new scenario 3 (`MW_TEST_SYNC_PRELEAD_US`: a delay before a committer tries to be the leader) shows it in every run: 459-531 of 800 commits acknowledged without a sync with the old code, 0 now.
- A data race that ThreadSanitizer built with gcc reported in `mw_log_rewrite_prepare` against `lane_publish` (the tests `mw_rebasewr` and `mw_rebasefkstress`, about 7 runs in 8 on Linux arm64): gcc read the flags `mp_req`, `mp` and `has_log` with one 8-byte load that took in the atomic counter `inflight` next to them. The atomics that follow plain fields of the database (`inflight`, `open_done`) start a word of their own. The CI builds with clang, which reads the flags one by one, and did not see it.

- Test `mw_multiproc`, scenario 4: the process to kill was killed 150 ms after it was started, and on a slow machine (ThreadSanitizer in a Linux container: 1 run in 15) it had not committed anything yet (`killed > 0` failed). It is killed once it has acknowledged 50 commits (through a pipe, at most a minute), as `mw_procs` does since 0.6.3. Under ThreadSanitizer the test also needs `llvm-symbolizer`: without it the race of SQLite on `randomnessPid` in the children is not matched by `test/tsan.supp`, and the children exit with 66.

- The build has no warnings with gcc 12 (Linux), clang (macOS, Linux) and MinGW-w64: lines with several `if` on one line (`multiwriter_shidx.c`, `multiwriter_shared.c`, `mw_reloc`) are split; `install_impl` of the shared index refuses a negative count of pages (gcc could not exclude that its allocations wrap) and the repair of a commit that a publisher left half installed initialises its arrays; in the tests, a buffer of `mw_diskfull` that could truncate a command, values that `mw_ioerr` printed uninitialised, a counter that `mw_sharedwindow` did not use, variables of `mw_serial` used only outside Windows.
- CI: the job of the Android x86_64 emulator gives the runner's user access to `/dev/kvm`. Without it the emulator ran with `-accel off`, which the emulator refuses since version 37 (the action installs the latest): the emulator never started and the job timed out.
- Test `mw_relocprep`, scenario 1: it must exercise the rewrite of a prepared relocation, which needs threads that overlap; under ThreadSanitizer on a runner of 4 CPUs one run had 5 relocations and none rewritten. The scenario runs again, up to three times, until a rewrite happens (the data are checked every time).
- `mw_multiproc` printed its lines more than once under ThreadSanitizer: each child wrote again what the parent had printed and not yet flushed. The parent flushes before it forks.

### Added
- `bench/events_bench.c` (`make bench`): the workload of the external comparison (100 inserts of 64 bytes per transaction with SQLite's rowid and an index, 4 readers, `busy_timeout=5000`, retries counted in the latency).
- Test `mw_spec`: a reader does not see a commit whose fsync is held, a writer does and is acknowledged after it; a commit taken back refuses the writer that read it; dependent appends share the fsyncs.

## 0.6.5 - 2026-10-31

### Fixed
Expand Down
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ $(DIST)/mw_admitcap$(EXE): $(BUILD)/t_mw_admitcap.o $(filter-out $(BUILD)/multiw
$(DIST)/mw_holesync$(EXE): $(BUILD)/t_mw_holesync.o $(filter-out $(BUILD)/multiwriter_log.o,$(LIB_OBJ)) $(BUILD)/inject_fsync.o
@mkdir -p $(DIST)
$(CC) $^ -o $@ $(LDFLAGS)
$(DIST)/mw_spec$(EXE): $(BUILD)/t_mw_spec.o $(filter-out $(BUILD)/multiwriter_log.o,$(LIB_OBJ)) $(BUILD)/inject_fsync.o
@mkdir -p $(DIST)
$(CC) $^ -o $@ $(LDFLAGS)
$(DIST)/mw_stagednormal$(EXE): $(BUILD)/t_mw_stagednormal.o $(filter-out $(BUILD)/multiwriter_log.o,$(LIB_OBJ)) $(BUILD)/inject_log.o
@mkdir -p $(DIST)
$(CC) $^ -o $@ $(LDFLAGS)
Expand Down Expand Up @@ -119,7 +122,7 @@ TSAN_TESTS := mw_admitcap mw_appendfail mw_attachsync mw_autoextfail mw_closesta
mw_fastcommit mw_format mw_fullfsync mw_gc mw_holesync mw_identity mw_lanes mw_lanetrim mw_logopen mw_logrewrite mw_logswap mw_mapfail mw_mpstale mw_multiproc \
mw_multiproc_crash mw_multiproc_liveness mw_openfail mw_openflags mw_openlocks mw_openrace mw_openrepair mw_oslayer mw_ownepoch mw_procs mw_profile mw_readdeps \
mw_rebase mw_rebasecases mw_rebasefk mw_rebasefkstress mw_rebaseneg mw_rebasenoop mw_rebasepolicy mw_rebaseskew mw_rebasewr mw_recoverread mw_reloc mw_relocprep \
mw_repairinstall mw_rollback mw_rollbackrace mw_routes mw_rowdiffoom mw_rowid mw_selfcommit mw_shared mw_sharedwindow mw_shidx mw_sizering mw_slotstuck mw_stacked \
mw_repairinstall mw_rollback mw_rollbackrace mw_routes mw_rowdiffoom mw_rowid mw_selfcommit mw_shared mw_sharedwindow mw_shidx mw_sizering mw_slotstuck mw_spec mw_stacked \
mw_stagedlog mw_stagednormal mw_stalewal mw_store mw_strictany mw_structural mw_syfail mw_syncpragma mw_syncwindow mw_tailscan mw_tempbarrier mw_tempddl mw_ticketring \
mw_trimfail mw_vfs_trace mw_walstatfail mw_warm mw_writeskew
.PHONY: test-tsan
Expand All @@ -141,6 +144,13 @@ $(BUILD)/b_mw_bench.o: bench/mw_bench.c $(HEADERS)
$(DIST)/mw_bench$(EXE): $(BUILD)/b_mw_bench.o $(LIB_OBJ)
@mkdir -p $(DIST)
$(CC) $^ -o $@ $(LDFLAGS)
bench: $(DIST)/events_bench$(EXE)
$(BUILD)/b_events_bench.o: bench/events_bench.c $(HEADERS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -c $< -o $@
$(DIST)/events_bench$(EXE): $(BUILD)/b_events_bench.o $(LIB_OBJ)
@mkdir -p $(DIST)
$(CC) $^ -o $@ $(LDFLAGS)

include mk/extension.mk
include mk/package.mk
Expand Down
Loading
Loading