← 输入框|github.com|刷新
Skip to content

Add opt-in locking for SQL Server commit reads (#31) - #73

Merged
AGiorgetti merged 2 commits into
developfrom
fix/31-checkpoint-read-locking
Dec 3, 2026
Merged

AGiorgetti merged 2 commits into
developfrom
fix/31-checkpoint-read-locking

Conversation

@AGiorgetti

@AGiorgetti AGiorgetti commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Closes #31. Mitigates the RCSI symptom in #14 and #21 without closing those reports. SQL #72, #63, and NEventStore/NEventStore#425 remain separate.

Behavior

  • WithDialect(new MsSqlDialect(useReadCommittedLockForCommitReads: true)) requests READCOMMITTEDLOCK for all seven public commit-read statements: open-ended and bounded checkpoint reads, both date-based reads, and stream revision reads. The built-in and custom consumers share these statements. The hint helper uses the name from Feature/31 readcommitedlock #39.
  • Preserves the parameterless constructor, the default-off behavior, paging, snapshot and write queries, the schema, and other dialects.
  • Reads can wait for an inserted, uncommitted matching row under RCSI. This does not guarantee checkpoint publication order or implement safe polling.

Verification

  • The expanded query-scope test failed before the change and passes afterward. It verifies all seven SQL statements, default behavior, and unchanged snapshots and writes.
  • Ten SQL Server integration cases cover a real lock wait under RCSI: checkpoint reads (global and bucket-scoped, bounded and open-ended), date-based reads, and stream revision reads, with sync/async where available and commit/rollback. CI is verifying the expanded head. Azure SQL is not separately runtime-tested.

Co-authored by Alessandro Giorgetti and Codex (OpenAI).

AGiorgetti and others added 2 commits December 3, 2026 11:12
Restrict READCOMMITTEDLOCK to the two open-ended checkpoint queries used by legacy pollers. Preserve the existing default, bounded reads, stream loading, and other dialects.

Co-authored-by: Codex <codex@openai.com>
Cover custom consumers using checkpoint ranges, date bounds or stream revisions as well as the built-in pollers. Keep the default, paging, snapshot queries and writes unchanged.

Co-authored-by: Codex <codex@openai.com>
@AGiorgetti AGiorgetti changed the title Add opt-in locking for SQL Server legacy checkpoint polls (#31) Add opt-in locking for SQL Server commit reads (#31) Dec 3, 2026
@AGiorgetti
AGiorgetti requested a balanced review from Copilot December 3, 2026 10:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The RCSI mitigation requires expanded integration tests to pass on the final head against real SQL Server lock-wait behavior, but this review environment cannot run those tests.

No open issues 🎉

What changed in this PR

Adds opt-in SQL Server commit-read locking to mitigate skipped reads under READ_COMMITTED_SNAPSHOT, without guaranteeing checkpoint publication order or safe polling.

Changes:

  • Applies READCOMMITTEDLOCK to all seven commit-read statements while preserving default behavior, paging, snapshots, and writes.
  • Adds query-scope checks and ten integration cases covering lock waits with commit and rollback.
  • Documents the option and its limitations.
File Description
src/​NEventStore.Persistence.Sql/​SqlDialects/​MsSqlDialect.cs Adds the opt-in constructor and commit-read hint helper.
src/​NEventStore.Persistence.MsSql.Tests/​CheckpointReadLockTests.cs Adds query-scope and RCSI lock-wait tests.
Changelog.md Documents the mitigation and unchanged behavior.

Review effort: Balanced

@AGiorgetti
AGiorgetti marked this pull request as ready for review December 3, 2026 10:51
@AGiorgetti
AGiorgetti merged commit e544ccd into develop Dec 3, 2026
6 checks passed
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.

Make MsSqlDialect compatible with AzureSql and READ COMMITTED SNAPSHOT

2 participants