Skip to content

fix(index): keep PTable construction predictable - #458

Merged
yordis merged 2 commits into
masterfrom
yordis/chore-reduce-platform-index-risk
Aug 10, 2026
Merged

fix(index): keep PTable construction predictable#458
yordis merged 2 commits into
masterfrom
yordis/chore-reduce-platform-index-risk

Conversation

@yordis

@yordis yordis commented Aug 10, 2026

Copy link
Copy Markdown
Member
  • Index rebuild throughput and file-handle safety should stay consistent across supported platforms without carrying a separate native stream path.
  • High-volume PTable construction should avoid per-stream allocation overhead that makes recovery and rebuild latency less predictable.

yordis added 2 commits August 10, 2026 14:22
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@cursor

cursor Bot commented Aug 10, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes core index file open/disposal and memtable hot paths used during recovery and rebuild; behavior should be equivalent but platform I/O is simplified and worth validating on Windows and Linux.

Overview
Removes the EventStore.Native project and the cross-platform unbuffered transaction-log I/O stack (UnbufferedFileStream, Windows/Unix native file helpers, and their test suite). PTable now opens index files only through the existing work-item pool and standard FileStream readers on all platforms, dropping the Windows-only unbuffered path and Mono.Posix.NETStandard from central packages and license notices.

HashListMemTable and ReverseComparer are tuned for rebuild/iteration: stream keys are read via GetKeyAtIndex instead of Keys[i], descending hash sort reuses a static comparer, and reverse comparison uses Comparer<T>.Default.Compare(y, x) to avoid per-comparison boxing/allocation.

New tests cover corrupt PTable open releasing file handles, single-reader PTable lookup after init, and GC allocation bounds for ordered memtable iteration and ReverseComparer comparisons.

Reviewed by Cursor Bugbot for commit bd47526. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cdaadd33-0be9-4271-b917-e517c1472f97

📥 Commits

Reviewing files that changed from the base of the PR and between 1f38699 and bd47526.

📒 Files selected for processing (20)
  • NOTICE.html
  • qodana.yaml
  • src/Directory.Packages.props
  • src/EventStore.Core.Tests/Index/IndexV1/when_a_ptable_is_corrupt_on_disk.cs
  • src/EventStore.Core.Tests/Index/IndexV1/when_opening_a_ptable_with_one_reader.cs
  • src/EventStore.Core.Tests/Index/MemTableTests.cs
  • src/EventStore.Core.Tests/Index/ReverseComparerTests.cs
  • src/EventStore.Core.Tests/TransactionLog/Unbuffered/UnbufferedTests.cs
  • src/EventStore.Core/EventStore.Core.csproj
  • src/EventStore.Core/Index/HashListMemTable.cs
  • src/EventStore.Core/Index/PTable.cs
  • src/EventStore.Core/TransactionLog/Unbuffered/UnbufferedFileStream.cs
  • src/EventStore.Native/EventStore.Native.csproj
  • src/EventStore.Native/TransactionLog/Unbuffered/ExtendedFileOptions.cs
  • src/EventStore.Native/TransactionLog/Unbuffered/INativeFile.cs
  • src/EventStore.Native/TransactionLog/Unbuffered/MacCaching.cs
  • src/EventStore.Native/TransactionLog/Unbuffered/NativeFileUnix.cs
  • src/EventStore.Native/TransactionLog/Unbuffered/NativeFileWindows.cs
  • src/EventStore.Native/TransactionLog/Unbuffered/WinNative.cs
  • src/EventStore.sln
💤 Files with no reviewable changes (14)
  • qodana.yaml
  • src/EventStore.sln
  • src/EventStore.Native/EventStore.Native.csproj
  • src/EventStore.Native/TransactionLog/Unbuffered/MacCaching.cs
  • NOTICE.html
  • src/EventStore.Core/EventStore.Core.csproj
  • src/Directory.Packages.props
  • src/EventStore.Native/TransactionLog/Unbuffered/NativeFileUnix.cs
  • src/EventStore.Native/TransactionLog/Unbuffered/WinNative.cs
  • src/EventStore.Core/TransactionLog/Unbuffered/UnbufferedFileStream.cs
  • src/EventStore.Native/TransactionLog/Unbuffered/NativeFileWindows.cs
  • src/EventStore.Native/TransactionLog/Unbuffered/INativeFile.cs
  • src/EventStore.Core.Tests/TransactionLog/Unbuffered/UnbufferedTests.cs
  • src/EventStore.Native/TransactionLog/Unbuffered/ExtendedFileOptions.cs

Walkthrough

The change removes the native unbuffered file implementation and its package references. PTable now uses pooled work items directly. HashListMemTable and ReverseComparer reduce allocation overhead. New tests cover file-handle release, reader reuse, and allocation limits.

Changes

Native I/O removal

Layer / File(s) Summary
Remove native project dependencies
NOTICE.html, qodana.yaml, src/Directory.Packages.props, src/EventStore.Core/EventStore.Core.csproj, src/EventStore.Native/EventStore.Native.csproj, src/EventStore.sln
The native project, its package, license entries, project reference, and solution mappings are removed.
Delete unbuffered file I/O
src/EventStore.Native/TransactionLog/Unbuffered/*, src/EventStore.Core/TransactionLog/Unbuffered/UnbufferedFileStream.cs, src/EventStore.Core.Tests/TransactionLog/Unbuffered/UnbufferedTests.cs
The native file implementations, unbuffered stream, and related tests are deleted.

Index access and allocation updates

Layer / File(s) Summary
Use pooled PTable work items
src/EventStore.Core/Index/PTable.cs
PTable always acquires and returns a pooled work item instead of using platform-specific stream handling.
Update indexed memtable access
src/EventStore.Core/Index/HashListMemTable.cs
Indexed lookups use GetKeyAtIndex. Ordered iteration uses a shared descending ulong comparer. ReverseComparer<T> reverses operands without negating comparison results.
Add regression coverage
src/EventStore.Core.Tests/Index/*
Tests cover failed-open file-handle release, reader reuse, ordered-iteration allocations, and comparer allocations.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Poem

A rabbit checks the indexes bright,
No native stream remains in sight.
Pooled work items safely flow,
Fewer little allocations grow.
Tests guard each file and reader tight.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: making PTable construction more predictable through platform and allocation improvements.
Description check ✅ Passed The description directly explains the platform consistency, file-handle safety, and allocation goals of the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch yordis/chore-reduce-platform-index-risk

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@yordis
yordis merged commit 8046703 into master Aug 10, 2026
23 checks passed
@yordis
yordis deleted the yordis/chore-reduce-platform-index-risk branch August 10, 2026 21:50
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