Skip to content

Harden ordered-view bulk index builds: memory budget, cancellable sort, bounded tail replay - #679

Merged
Joseph Schick (jschick04) merged 3 commits into
mainfrom
baked-sort-key-rebuild
Aug 13, 2026
Merged

Harden ordered-view bulk index builds: memory budget, cancellable sort, bounded tail replay#679
Joseph Schick (jschick04) merged 3 commits into
mainfrom
baked-sort-key-rebuild

Conversation

@jschick04

Copy link
Copy Markdown
Collaborator

Hardens the ordered-view bulk index build path for the large-log extreme, in three independent, order/rank-preserving changes (no public API change):

Memory-bounded bulk build - OrderedViewState.BuildIndex estimates peak transient bytes and falls back to the bounded-memory delegating insert path when a build would exceed available heap headroom (and always for unbounded Keyword joins), so a large rebuild can't OOM.

Cancellable sort - replaces Array.Sort in ColumnDirectSort (both the permutation sort and the dense-rank string sort) with a token-checking introsort that throws on cancellation (never returns a partial array), so a superseded build stops promptly instead of running an uncancellable multi-second sort. Consolidates the repeated cancellation-check stride into Concurrency.CooperativeCancellation.

Bounded tail replay + forward progress - OrderedViewState.TryAdoptRebuild abandons an over-budget owner-thread tail replay and reschedules; a breach counter forces a bounded owner-thread replay after repeated abandons, preventing both owner-thread stalls and a sustained-append livelock.

Tests - +3 files (~26 tests): identical-permutation parity across 756 sort configs, mid-sort cancellation at both sort sites, the memory-budget fallback, and the tail-replay abandon / forced-fallback / hold-clear paths (deterministic concurrency tests; key ones verified to fail under their target regression). Before/after benchmark is perf-neutral with identical allocation.

Copilot AI lite review requested due to automatic review settings August 13, 2026 19:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the ordered-view bulk index rebuild path under extreme log sizes by adding memory-bounded bulk-build selection, making the internal sorts cooperatively cancellable, and bounding/rescheduling tail replay to ensure forward progress without long owner-thread stalls. It also adds targeted unit tests to validate parity and the new abandonment/forced-replay behaviors.

Changes:

  • Adds a bulk-build peak-memory estimator and a default memory budget that triggers a safe fallback to the bounded-memory delegating build path (and always delegates for Keyword joins).
  • Replaces Array.Sort in ordered-view sorting paths with a cancellation-aware introsort (ColumnDirectSort.CancellableSort) plus a shared cancellation check stride (CooperativeCancellation).
  • Extends rebuild adoption to support bounded tail replay with abandonment + a breach counter to force replay after repeated abandons, and adds deterministic concurrency tests to cover the behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/Unit/EventLogExpert.Runtime.Tests/LogTable/OrderedView/OrderedViewTailReplayTests.cs Adds unit tests for tail-replay abandon/forced-replay/hold-release scenarios.
tests/Unit/EventLogExpert.Runtime.Tests/LogTable/OrderedView/OrderedViewBulkBuildTests.cs Adds a memory-budget fallback parity test to ensure identical ordering vs bulk build.
tests/Unit/EventLogExpert.Runtime.Tests/LogTable/CancellableSortTests.cs Adds cancellation + parity tests for the new cancellable sort implementation.
src/EventLogExpert.Runtime/LogTable/OrderedView/OrderedViewWriter.cs Introduces tail replay budget/breach limit wiring and rescheduling behavior on abandoned tails.
src/EventLogExpert.Runtime/LogTable/OrderedView/OrderedViewState.cs Implements memory-budgeted bulk build selection and tail measurement/abandon behavior for adoption.
src/EventLogExpert.Runtime/LogTable/OrderedView/ChunkedOrderIndex.cs Switches cancellation polling to the shared cooperative cancellation stride/mask.
src/EventLogExpert.Runtime/LogTable/ColumnDirectSort.cs Adds cancellable introsort and routes existing sort sites through it.
src/EventLogExpert.Runtime/Concurrency/CooperativeCancellation.cs Centralizes the cancellation check stride/mask constants used across hot loops.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@jschick04
Joseph Schick (jschick04) marked this pull request as ready for review August 13, 2026 19:44
@jschick04
Joseph Schick (jschick04) requested a review from a team as a code owner August 13, 2026 19:45

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

@jschick04
Joseph Schick (jschick04) merged commit 8b101e0 into main Aug 13, 2026
8 checks passed
@jschick04
Joseph Schick (jschick04) deleted the baked-sort-key-rebuild branch August 13, 2026 19:49
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.

3 participants