Skip to content

fix(table): bound out-of-order audit-chain walk to prevent full-copy OOM - #1122

Merged
kriszyp merged 1 commit into
v5.0from
cherry-pick/v5.0/pr-1116
Jun 3, 2026
Merged

kriszyp merged 1 commit into
v5.0from
cherry-pick/v5.0/pr-1116

Conversation

@kriszyp

@kriszyp kriszyp commented Jun 3, 2026

Copy link
Copy Markdown
Member

Cherry-pick of #1116 for v5.0.26 patch release.

During replication full-copy catch-up, Table.commit's out-of-order
reconciliation walked the entire backward audit-history chain per record,
synchronously, buffering intermediate records in the JS heap. Peak heap scaled
with audit-history depth times worker count and OOM-killed the worker.

- Materialize each patch value during the walk and retain only { version, value }
  so the backing transaction-log buffer and decoders are released immediately,
  instead of pinning the full audit records for the whole walk.
- Cap the walk at MAX_OUT_OF_ORDER_AUDIT_DEPTH (RocksDB only, where the OOM was
  observed). Beyond it, reconcile against the retained most-recent window via the
  existing rebuildUpdateBefore fold and rule out duplicate re-delivery with an
  O(1) lookup at txnTime so commutative ops are not double-applied. LMDB keeps its
  exact unbounded walk.

Refs #1114

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@kriszyp
kriszyp requested a review from a team as a code owner June 3, 2026 18:47
@kriszyp kriszyp added the patch label Jun 3, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request addresses an out-of-memory (OOM) issue (#1114) caused by pathologically deep audit chains during out-of-order write reconciliation in RocksDB. It introduces a depth cap of 1000 steps to bound the audit-chain walk and optimizes memory usage by retaining only the necessary version and value fields of succeeding updates instead of full audit records. Additionally, it adds duplicate detection for capped walks to prevent double-applying re-delivered commutative operations. Corresponding regression tests have been added to verify the bounded walk and duplicate prevention. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants