Skip to content

Implement WAL group commits#547

Merged
adsharma merged 8 commits into
mainfrom
group-commit-wal
Jun 2, 2026
Merged

Implement WAL group commits#547
adsharma merged 8 commits into
mainfrom
group-commit-wal

Conversation

@adsharma

@adsharma adsharma commented May 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add WAL group commit sequencing so multiple committers can share one durable sync
  • split transaction commit into durable WAL append followed by in-memory publish
  • preserve publish order and single-writer behavior while allowing committers to wait during sync

Benchmark

C++ benchmark source: node_write_bench.cpp. Optimal was 64 threads at 6k writes/sec.

Setup:

  • on-disk temp database under /private/tmp
  • enableMultiWrites=true
  • autoCheckpoint=false
  • forceCheckpointOnClose=false
  • one autocommitted CREATE (:person {id, name}) per write
  • one Connection per writer thread
  • count verified after each run

1,000 writes per thread

Branch Threads Total writes Writes/sec
main 1 1,000 249.068
group commit 1 1,000 244.118
main 2 2,000 256.391
group commit 2 2,000 248.242
main 4 4,000 254.625
group commit 4 4,000 495.887
main 8 8,000 258.332
group commit 8 8,000 951.349

2,000 writes per thread

Branch Threads Total writes Writes/sec Speedup
main 4 8,000 265.451 1.00x
group commit 4 8,000 493.874 1.86x
main 8 16,000 283.718 1.00x
group commit 8 16,000 1,016.86 3.58x
main 16 32,000 290.376 1.00x
group commit 16 32,000 2,115.63 7.29x

Main remains fsync-bound at roughly 250-290 writes/sec as writer concurrency increases. With group commits, throughput scales to roughly 1,017 writes/sec at 8 writers and 2,116 writes/sec at 16 writers for this benchmark.

@adsharma

Copy link
Copy Markdown
Contributor Author

Cc: @loganpowell

@adsharma

Copy link
Copy Markdown
Contributor Author
  • WAL sync failures now still expose the allocated commit sequence to TM cleanup.
  • Exception cleanup now clears active write transaction state and wakes waiters.
  • Direct Transaction::commit() / publishCommit() now guard invalid commit timestamps.
  • Replaced the begin-transaction sleep loop with a condition variable.
  • Fixed WAL::reset() ordering.

@adsharma

Copy link
Copy Markdown
Contributor Author

Postgres and SQLite handle fsync() failures differently. Postgres poisons the WAL and blocks any future commits. SQLite continues with an "uncertain durability" state.

We're taking the Postgres approach.

@adsharma adsharma force-pushed the group-commit-wal branch from 17d1afd to 63e8ad1 Compare May 31, 2026 17:39
@adsharma adsharma marked this pull request as ready for review May 31, 2026 17:43
adsharma added 5 commits May 31, 2026 14:15
The group-commit review fix made TransactionManager::commit() clear
the active transaction and decrement activeWriteTransactionCount
whenever commit failed after a write transaction had entered the
committing state.

That is too aggressive for failures in publishCommit(). At that
point localStorage::commit() may have performed partial in-memory
publish work before throwing, and the normal query error path still
needs the active Transaction object so TransactionContext::rollback()
can undo those partial changes. Clearing the transaction inside
commit() leaves TransactionContext with a dangling activeTransaction
pointer; the outer error handler then tries to roll it back and can
report "Invalid transaction type to rollback" or crash. CI exposed
this in CopyTest.RelInsertBMExceptionDuringCommitRecovery.

Keep the transaction active on commit failure and only drop
committingWriteTransactionCount / notify waiters. The caller's
rollback path remains responsible for clearing activeTransactions
and activeWriteTransactionCount. Successful commits still clear
both counters in commit(), and rollback already notifies
cvForCommittingWriteTransaction.
@adsharma adsharma force-pushed the group-commit-wal branch from 9f88fab to 5733320 Compare May 31, 2026 21:16
@adsharma adsharma merged commit 5dcd610 into main Jun 2, 2026
4 checks passed
@adsharma adsharma deleted the group-commit-wal branch June 2, 2026 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant