Repository navigation
Add opt-in safe checkpoint polling for SQL Server (#72) - #75
AGiorgetti wants to merge 5 commits into
Conversation
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Why this PR uses shared writer locks and a short polling fenceThe aim for #21 and the SQL Server part of #72 is to preserve the existing
Fabian Schmied's insert-only lock proposal highlighted the cost of our earlier exclusive lock held through each writer's whole transaction. The separate prototype and benchmark passed 32 controlled cases with the locking hint on the stock SQL Server schema. The unhinted RCSI control exposed the higher checkpoint early. With eight writers, a 12 ms hold and an active poller, #75 measured 457 commits/s, the insert-only prototype 428, and the bounded version of that prototype 421. With no hold and no poller, the comparison was 2,160 vs. 1,002 commits/s. These are local results, not a production estimate or a proof for all query plans. The fence gives a correctness argument independent of the row access path and had higher write throughput in those runs. A MongoDB-style optimistic allocator is not a drop-in replacement here: SQL Server Safe mode stays opt-in. Drain incompatible in-flight writes before enabling it, and switch all writers and safe readers using the same store. Legacy polling is unchanged and does not acquire this guarantee automatically. The implementation is scoped to the built-in SQL Server path; other engines remain tracked in #72 and Azure SQL verification is deferred to #14. See the SQL Server guide. Co-authored by Alessandro Giorgetti and Codex (OpenAI). |
Scope
SQL Server slice of #72, addressing #21 and the SQL provider part of NEventStore/NEventStore#425. The other SQL dialects still need independent qualification. Azure SQL verification remains deferred to #14.
IDENTITYinsert. Independent writers can allocate and commit concurrently, and the shared lock stays held through actual commit or rollback, including ambient transactions. Registration and insert still share one batch; no new transaction, schema, checkpoint or writer-side round trip.Performance
Eight writers with a simulated 12 ms hold inside each ambient transaction and one active poller: 77 → 473 commits/s and 115 → 24 ms p95 append, comparing this protocol against the earlier exclusive-writer draft. p95 poll duration increased 4 → 18 ms. Without a poller, the same writer workload improved from 75 → 540 commits/s. Local SQL Server 2022/.NET 10, pooled loopback, three trials; not a production estimate. Frequent or waiting poll fences can still delay subsequent writes.
There is no additional transaction. An optimistic explicit-key allocator like MongoDB #118 is not a drop-in replacement for the existing SQL Server
IDENTITYschema: it needs a durable floor against ID reuse, and same-key contenders would still wait on an uncommitted ambient writer.Verification
Draft dependency: Repin the source submodule to the merged core #555 revision and rerun CI before merging. Before release, set the SQL NuGet dependency floor to a published core containing the contract and verify a package-only consumer.
Co-authored by Alessandro Giorgetti and Codex (OpenAI).