Skip to content

Prepare v4.6.6: query improvements and WAL concurrency fixes - #73

Merged
MaxAkbar merged 27 commits into
mainfrom
version.4.6.6
Oct 11, 2026
Merged

MaxAkbar merged 27 commits into
mainfrom
version.4.6.6

Conversation

@MaxAkbar

Copy link
Copy Markdown
Owner

Summary

Prepare CSharpDB 4.6.6 with prepared-query reuse, bounded primary-key reads, lower query/write allocations, and stronger reader snapshot and storage ownership guarantees.

  • Reuse prepared SELECT plans across parameter values, preserve reader catalog snapshots, and support bounded primary-key ranges through pooled readers and ordinary queries.
  • Reduce scan, LIMIT, prefetch, INSERT, and primary-key mutation overhead while preserving mixed row/batch traversal and page ownership.
  • Fix checkpoint finalization racing with write-conflict reads. A reader could retain a WAL offset that reset or retained-tail compaction invalidated, causing a short read or incorrect page contents. Finalization now acquires the commit mutex before the begin/writer barrier and defers while durable commits still own unpublished offsets.
  • Add deterministic WAL regressions for reset, compaction, in-bounds stale offsets, parent/split reads, cancellation, lock release, and forward progress.
  • Update NuGet dependencies while retaining Microsoft.OpenApi 2.12.0, which is compatible with Microsoft.AspNetCore.OpenApi 10.0.12 on .NET 10.
  • Strengthen performance-evidence guardrails and retain the performance investigation and isolated WAL prototype for review. Update release notes, the unreleased website summary, and the release-note review hash.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactor / maintenance
  • Tests only

Related Issues

None linked.

Testing

  • dotnet build CSharpDB.slnx
  • Relevant tests executed
  • Failure-path tests executed (if applicable: cancellation, invalid/unsupported inputs, non-DbException paths)
  • Manual verification performed (if applicable)

Local validation used Windows x64 and .NET SDK 10.0.401. No application/UI manual verification was performed for this PR preparation.

Validation Result
Debug and Release solution builds after the dependency updates Both passed with 0 warnings and 0 errors
CheckpointConflictReadTests after the dependency updates 23 passed, 0 failed, 0 skipped
CSharpDB.Api.Tests after the dependency updates 191 passed, 0 failed, 0 skipped
CSharpDB.Daemon.Tests with a corrected test-process PATH 248 passed, 1 timeout, 0 skipped; the timed-out test passed when run alone with the same binary and timeout
Earlier CSharpDB.Tests run with the final production WAL fix, before the dependency updates 3,497 passed, 0 failed, 0 skipped
Earlier CSharpDB.Data.Tests run, before the dependency updates 325 passed, 0 failed, 0 skipped
Earlier CSharpDB.Cli.Tests run, before the dependency updates 410 passed, 0 failed, 1 skipped because CSHARPDB_ACCESS_LIVE_FIXTURE was not configured
Warning-fix theory, before the dependency updates All 4 cases passed, 0 failed, 0 skipped
scripts/Test-Documentation.ps1 after updating the release notes Passed changelog, downloads, website, link, sitemap, and associated guardrail checks
git diff --check Passed

The earlier full core run included the first 19 WAL regression cases; four structural cases were added afterward and passed separately. All 23 were subsequently rerun together after the dependency updates. The full core/Data/CLI suites have not been rerun against the updated package graph.

Two deterministic retained-tail regressions failed against unchanged production code before the fix: one reproduced a short WAL read at offset 45352, and one read incorrect bytes from a stale offset that remained within file bounds. Both pass with the fix. A mutex-only candidate also exposed a pending legacy-flush failure; the final pending-commit guard addresses that case.

The initial daemon run had 33 failures because the inherited 10,623-character PATH prevented command-script helpers from finding PowerShell. A shorter PATH was applied only to the test process. The subsequent suite's remaining timeout was Wrapper_ExecutesInterleavedSuitesAndRejectsDuplicateMedians; its isolated rerun passed without changing code or increasing the timeout. This is not a claim that the full daemon run was failure-free.

Checklist

  • I followed the project style and conventions.
  • I added or updated tests for behavior changes.
  • I covered both success and failure paths for changed behavior.
  • I updated docs for user-facing changes.
  • I verified no sensitive data was added.

Notes for Reviewers

  • This PR contains the full version.4.6.6 branch relative to main, including earlier query/write improvements and performance research, not only the latest WAL and dependency commits.
  • Lock ordering is commit mutex -> begin barrier -> writer barrier -> checkpoint admission. Copy admission is released before finalization acquires the commit mutex. Reservations are released on cancellation and error paths; pending durable publication is checked before moving or truncating WAL bytes.
  • The original CI interleaving was not captured. The deterministic tests establish the reproduced failure mechanism, not an identical historical CI schedule.
  • Finalization now serializes with conflict-resolution I/O. Its incremental latency/throughput impact has not been benchmarked. The retained performance checkpoint describes earlier product revisions and is not performance qualification of this final commit.
  • The experimental CSharpDB.WalPrototype.* projects remain outside the product solution. They do not change the production database or WAL format and are not a shipping storage implementation.
  • The Access live-fixture coverage gap and the daemon test's timing reliability remain visible above. A full cross-platform test matrix and release qualification have not been run locally for this final branch state.
  • Version 4.6.6 remains an unreleased candidate; the website's stable downloads remain on 4.6.5. This PR does not publish a release or NuGet packages.

Coalesce WAL header validation and admit large writers between checkpoint slices after covering their commit copy budget. Preserve the latest committed header and size each checkpoint for its captured database image.

Validation: 3,125 CSharpDB.Tests passed and all 24 durable reopen checks passed. The local four-pair comparison improved 10,000-row throughput including drain by 16.9% and P99 by 63.6%. Single-row and 1,000-row P99 regressions remain unresolved.
Require captured provenance, complete comparison coverage, and nonzero execution even in report-only mode. Compare base and head in balanced order with a common harness, retain both artifact roots, and replace stale reports when evidence is invalid.

Validation: all 42 guardrail contract tests passed. The reviewed benchmark Release build completed with zero warnings and errors.
Add bounded template plans with independent execution values for integer lookups and ranges. Preserve lookup shortcuts, allocate small-result batches lazily, and bound physical primary-key range traversal.

Keep ReaderSession primary-key ranges on their existing path pending snapshot catalog qualification. Add regression coverage and reusable benchmarks; validate 3,197 engine and 313 ADO tests.
Capture committed roots, schema and row counts for reader sessions, with bounded metadata-change tracking and snapshot-backed fallback during publication. Protect base-file pages still visible to readers and retain commits appended after checkpoint planning.

Retain regression coverage for catalog changes, concurrent writers and checkpoint repair. Reader and pooled prepared primary-key ranges remain disabled. Verified exact source hashes against the passing Release receipts: 3,247 engine tests and 315 ADO tests. Document diagnostic performance results and unresolved tail-latency qualification.
Use the reader's frozen catalog view to enable the existing prepared range
planner for ReaderSession and pooled ADO queries. Cover snapshot root growth,
commit/rollback visibility, and plan reuse across changing parameter bounds.

Record the isolated 240,000-query local comparison and its qualification limits.
The 65/2,048-parameter cases improved median latency by 73.38% geometrically;
median, allocation and P99 checks passed. Verified Release results: 3,249 engine
and 315 ADO tests passed, with current source hashes matching tested inputs.
Pass the requested upper bound to BTreeCursor as a prefetch hint. Skip the
next-leaf read once the current leaf reaches that bound, while preserving
cursor traversal, reseeking, and read-ahead across needed leaves.

Add eight regression cases and document the paired local benchmark. Four-row
pooled queries allocate 21.73% less and improve median latency by 23.15%; larger
ranges pass the declared regression checks across 249,600 measured queries.

Validation: 3,257 engine and 315 ADO Release tests passed. Verified the committed
source matches the tested inputs and checked staged scope and whitespace.
Keep resource diagnostics on writer pagers and share a stateless read-only
allocator across snapshots. Preserve faulted allocation/free operations,
rejection messages, cancellation precedence, and writer diagnostics behavior.

Add snapshot diagnostics, write-rejection, and retained-page regression tests.
Document the 1,544-byte pager allocation saving and local pooled comparison:
7.75% fewer allocated bytes across four-row queries, with declared regression
checks passing over 249,600 measured queries under normal background load.

Validation: 3,260 engine and 315 ADO Release tests passed; source/runtime hashes,
staged scope, and whitespace verified. Independent code and results review passed.
Initialize planner caches and diagnostics on demand, guard fast inserts against stale trigger metadata, and use bounded physical integer primary-key scans for ordinary SELECT and join predicates.

Validated with 3,607 Release tests. Record paired performance results, including two original prepared-control flags and their separate passing follow-up.
Defer batch storage until batch access while preserving row reads, decode widths, reopen behavior, and retained-buffer ownership.

Validated with 3,615 Release tests. Small expression/join allocation fell 12.89%; retain failed latency comparisons and the unresolved prepared-range slowdown without claiming latency qualification.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T20:23:13.812432Z f6d65ab PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@MaxAkbar
MaxAkbar merged commit 99ad896 into main Oct 11, 2026
15 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.

2 participants