Skip to content

perf(binding-kafka): claim a block in the log file for produce-path trailer entries - #2457

Merged
jfallows merged 1 commit into
developfrom
claude/zilla-plus-pii-status-nfzbgr
Aug 30, 2026
Merged

jfallows merged 1 commit into
developfrom
claude/zilla-plus-pii-status-nfzbgr

Conversation

@jfallows

Copy link
Copy Markdown
Contributor

Description

KafkaCacheTrailerEnvelope accumulated a composed transform's set() calls during produce-path encode in a per-stream, heap-resident growable arena (an expandable buffer plus parallel offset/length arrays), retained for the entire lifetime of the producing stream.

The storage layer already solves an equivalent problem for a transformed value's own output with zero retained per-stream heap state: KafkaCachePartition reserves a worst-case-sized block once per message in convertedFile, and the transform writes directly into that already-claimed block via consumeTransformed -- no heap buffer at all, just a couple of file positions tracked.

This applies the same claim-per-message approach to trailer entries, but without introducing a new file: the log file already reserves a cache.client.trailers.size.max-sized block per message for the final merged trailers (committed at FIN). This adds a second, separate claim of the same size, right next to it, for the envelope's own accumulation during encode. KafkaCacheTrailerEnvelope now writes set() calls directly into that claimed block via a small write cursor, instead of a growable arena -- count()/get()/writeHeaders() scan the claimed block directly. If a message's entries exceed the claimed block, the excess is dropped and the entry is marked aborted (mirroring how a transformed value exceeding its own reservation is handled) rather than corrupting anything or rejecting the whole record.

Testing

  • KafkaCacheTrailerEnvelopeTest rewritten test-first for the claimed-slot design (against a real KafkaCacheFile backed by a temp file), including new coverage for the overflow/abort case and for set() calls made before any claim.
  • New k3po scenario (message.value.envelope.overflow, CacheProduceIT#shouldSendMessageValueEnvelopeOverflow) configuring cache.client.trailers.size.max small enough to overflow on the second of two configured fields, proving the entry becomes invisible to the downstream relay (aborted) rather than corrupting or partially leaking data.
  • The existing message.value.envelope* scenarios (feat(binding-kafka): wire ModelEnvelope into kafka cache storage's read and write paths #2455) continue to pass unmodified -- only the envelope's internal storage changed, not its observable contract.
  • Full runtime/binding-kafka module (clean verify): all unit tests, all k3po ITs, checkstyle, license, and jacoco coverage pass with no regressions.

Fixes #2456


Generated by Claude Code

…railer entries

KafkaCacheTrailerEnvelope accumulated a composed transform's envelope.set()
calls in a per-stream, heap-resident growable arena retained for the entire
lifetime of the producing stream. The log file already solves an equivalent
problem for a transformed value's own output with zero retained heap state:
a worst-case block is reserved once per message (mirroring convertedFile's
existing claim), and the transform writes directly into it.

Apply the same claim-per-message approach to trailer entries: reserve a
second, separate block per message (sized from the existing
cache.client.trailers.size.max bound) right next to the block already
reserved for the final merged trailers, and have KafkaCacheTrailerEnvelope
write set() calls directly into it via a small write cursor instead of a
growable arena. If a message's entries exceed the claimed block, the excess
is dropped and the entry is marked aborted rather than completed, mirroring
how a transformed value exceeding its own reservation is handled.

Fixes #2456

@jfallows jfallows left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LGTM

@jfallows
jfallows merged commit 91144fa into develop Aug 30, 2026
42 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.

binding-kafka: avoid per-stream heap accumulation buffer for produce-path trailer entries

2 participants