GeezerVison is showing github.com — [improve][broker] Reduce unnecessary MessageMetadata parsing by caching the parsed instance in the broker cache by lhotari · Pull Request #24682 · apache/pulsar
Conversation
lhotari
commented
Aug 28, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Fixes #24644
Motivation
See #24644. Currently in Pulsar, MessageMetadata isn't cached in the broker entry cache and parsing of MessageMetata also happens multiple times during dispatching. When there's a large fan-out, each dispatcher for each subscription will be also doing the parsing. Most of this could be avoided.
Modifications
- add MessageMetadata caching
- cleanup and optimize BrokerEntryMetadata parsing
Documentation
-
doc
-
doc-required
-
doc-not-needed
-
doc-complete
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…ekAndCopyMessageMetadata
lhotari
changed the title
[improve][broker] Reduce
[improve][broker] Reduce unnecessary MessageMetadata parsing by caching the parsed instance in the broker cache
Aug 28, 2025
|
❌ Patch coverage is 74.28571% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.10%. Comparing base (a2b69cc) to head (36a3f18).
⚠️ Report is 439 commits behind head on master.
Additional details and impacted files

@@ Coverage Diff @@
## master #24682 +/- ##
============================================
- Coverage 74.17% 74.10% -0.07%
- Complexity 33470 33480 +10
============================================
Files 1895 1896 +1
Lines 148029 148109 +80
Branches 17142 17163 +21
============================================
- Hits 109796 109762 -34
- Misses 29479 29564 +85
- Partials 8754 8783 +29
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 82 files with indirect coverage changes
🚀 New features to boost your workflow:
- ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Sep 8, 2026
lhotari
added a commit
to lhotari/pulsar
that referenced
this pull request
Sep 8, 2026
…ld messages
### Motivation
`MLTransactionLogImpl` and `MLPendingAckStore` open their own managed ledgers and store bare
lightproto `TransactionMetadataEntry` / `PendingAckMetadataEntry` records rather than Pulsar
messages. Since apache#24682 the entry cache parses every entry as a `MessageMetadata` at insert and
read time, which for these ledgers can never succeed: `Commands.parseMessageMetadata` reads a
4-byte big-endian metadata length off the front of the payload, and the first byte of one of
these records is a protobuf tag, so the length always decodes to at least 128 MiB and the
lightproto parse walks off the end of the buffer.
`EntryImpl.initializeMessageMetadataIfNeeded` catches the resulting exception and leaves
`messageMetadata` null, so no wrong metadata is ever produced, but it logs a warning with a
stack trace for every entry. A broker with transactions enabled therefore warns once per
transaction log and pending ack entry it writes, and once per entry it replays during recovery.
### Modifications
- Added `ManagedLedgerConfig.pulsarMessageEntries`, defaulting to true. The transaction log and
the pending ack store set it to false on the config they already build before `asyncOpen`, so
the value is fixed before the managed ledger and its entry cache exist.
- `RangeEntryCacheImpl.insert`, `RangeEntryCacheImpl.readFromStorage` and `EntryCacheDisabled`
skip `initializeMessageMetadataIfNeeded` when the flag is false. These are the only three
places that parse an entry's metadata; every other reader falls back to peeking the buffer
when `Entry#getMessageMetadata()` is null, which is already a normal condition.
- Dropped the lazy metadata initialization from `RangeCacheEntryWrapper`. With the parse skipped
for these ledgers it would have re-introduced it on the first cache read, and for the ledgers
that do hold messages `insert` has parsed the metadata eagerly since apache#26463. Removing it also
makes the `managedLedgerName` that was threaded through `RangeCache` and
`RangeCacheEntryWrapper` for its warning message dead, so that goes too, along with the
two-argument `RangeCache` constructor which never had a caller.
### Verifying this change
Added a test per guarded site asserting that the metadata isn't parsed when the entries aren't
Pulsar messages, each carrying an in-test control that pushes the same bytes through the same
path with the flag on, so the assertion can't pass merely because the payload is unparseable.
`RangeEntryCacheImplTest.testInsertDoesNotParseMessageMetadataWhenTheEntriesArentPulsarMessages`
also reads the entry back through the cache, which is what pins the removal of the wrapper's
lazy initialization. `MLTransactionLogImplTest` and `TransactionTest` assert that the two stores
mark their managed ledgers, and that a plain one keeps the default.
This was referenced Oct 3, 2026
nodece
pushed a commit
to ascentstream/pulsar
that referenced
this pull request
Oct 13, 2026
…ng the parsed instance in the broker cache (apache#24682)
(cherry picked from commit 53bbd4a)
(cherry picked from commit 87e7159)
Reviewers
coderzc
coderzc approved these changes
Technoboy-
Awaiting requested review from Technoboy-
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|