GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@lhotari lhotari commented Aug 28, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

All reactions
lhotari added 7 commits August 28, 2025 14:10
@lhotari
Simplify caching decision for tailing reads
468cd30
@lhotari
Add peekMessageMetadata that can use a provided instance, optimize pe…
c5e4703
…ekAndCopyMessageMetadata
@lhotari
Optimize skipping of checksum slightly
f545b88
@lhotari
Add metadata caching when entry is fetched from cache
ca8b128
@lhotari
Initialize message metadata after reading from entries from storage
2ebd5a5
@lhotari
Reduce unnecessary MessageMetadata parsing and reuse Entry's MessageM…
c1ba1dc
…etadata when applicable
@lhotari
Fix NPE in accessing RangeCacheEntryWrapper
d555711
@lhotari lhotari added this to the 4.1.0 milestone Aug 28, 2025
@lhotari lhotari self-assigned this Aug 28, 2025
@lhotari lhotari added the ready-to-test label Aug 28, 2025
@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Aug 28, 2025
@lhotari 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
@coderzc coderzc modified the milestones: 4.1.0, 4.2.0 Sep 1, 2025
coderzc
coderzc approved these changes Sep 5, 2025
View reviewed changes
@coderzc
coderzc requested a review from Technoboy- September 5, 2025 09:27
@Technoboy- Technoboy- closed this Sep 9, 2025
@Technoboy- Technoboy- reopened this Sep 9, 2025
@codecov-commenter

codecov-commenter commented Sep 9, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

❌ 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.

Files with missing lines Patch % Lines
...sar/broker/service/persistent/PersistentTopic.java 38.46% 5 Missing and 3 partials ⚠️
.../pulsar/broker/service/AbstractBaseDispatcher.java 56.25% 3 Missing and 4 partials ⚠️
...per/mledger/impl/cache/RangeCacheEntryWrapper.java 50.00% 1 Missing and 5 partials ⚠️
...pulsar/broker/admin/impl/PersistentTopicsBase.java 50.00% 3 Missing and 3 partials ⚠️
...main/java/org/apache/bookkeeper/mledger/Entry.java 50.00% 2 Missing and 2 partials ⚠️
...ker/service/persistent/PersistentSubscription.java 40.00% 2 Missing and 1 partial ⚠️
...va/org/apache/pulsar/common/protocol/Commands.java 93.18% 2 Missing and 1 partial ⚠️
...apache/pulsar/broker/service/EntryAndMetadata.java 75.00% 1 Missing and 1 partial ⚠️
...va/org/apache/pulsar/broker/service/ServerCnx.java 33.33% 1 Missing and 1 partial ⚠️
...ransaction/buffer/impl/TopicTransactionBuffer.java 33.33% 1 Missing and 1 partial ⚠️
... and 2 more
Additional details and impacted files

Impacted file tree graph

@@             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     
Flag Coverage Δ
inttests 26.39% <30.28%> (+0.14%) ⬆️
systests 22.65% <26.85%> (-0.01%) ⬇️
unittests 73.64% <74.28%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
.../org/apache/bookkeeper/mledger/impl/EntryImpl.java 90.27% <100.00%> (+0.88%) ⬆️
...org/apache/bookkeeper/mledger/impl/OpAddEntry.java 77.35% <100.00%> (-0.11%) ⬇️
...okkeeper/mledger/impl/ShadowManagedLedgerImpl.java 59.04% <100.00%> (+0.19%) ⬆️
...kkeeper/mledger/impl/cache/EntryCacheDisabled.java 76.59% <100.00%> (+1.04%) ⬆️
...ache/bookkeeper/mledger/impl/cache/RangeCache.java 76.28% <100.00%> (-0.06%) ⬇️
...keeper/mledger/impl/cache/RangeEntryCacheImpl.java 70.95% <100.00%> (+0.10%) ⬆️
...tent/NonPersistentDispatcherMultipleConsumers.java 67.46% <100.00%> (ø)
...t/NonPersistentDispatcherSingleActiveConsumer.java 87.50% <100.00%> (ø)
...ersistentStickyKeyDispatcherMultipleConsumers.java 75.28% <100.00%> (ø)
...sistent/PersistentDispatcherMultipleConsumers.java 75.53% <100.00%> (+0.03%) ⬆️
... and 17 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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lhotari lhotari added the release/4.1.1 label Sep 9, 2025
lhotari added 3 commits September 9, 2025 19:34
@lhotari
Merge remote-tracking branch 'origin/master' into lh-cache-parsed-mes…
90f959a
…sage-metadata
@lhotari
Fix test failure
c8ea564
@lhotari
Skip parsing metadata if it's already cached
36a3f18
@lhotari
lhotari merged commit 53bbd4a into apache:master Sep 9, 2025
@Technoboy- Technoboy- added the cherry-picked/branch-4.1 label Sep 10, 2025
Technoboy- pushed a commit that referenced this pull request Sep 10, 2025
@lhotari @Technoboy-
[improve][broker] Reduce unnecessary MessageMetadata parsing by cachi…
6509ee3
…ng the parsed instance in the broker cache (#24682)
KannarFr pushed a commit to CleverCloud/pulsar that referenced this pull request Sep 22, 2025
@lhotari @KannarFr
[improve][broker] Reduce unnecessary MessageMetadata parsing by cachi…
ee9583f
…ng the parsed instance in the broker cache (apache#24682)
walkinggo pushed a commit to walkinggo/pulsar that referenced this pull request Oct 8, 2025
@lhotari @walkinggo
[improve][broker] Reduce unnecessary MessageMetadata parsing by cachi…
b37b46e
…ng the parsed instance in the broker cache (apache#24682)
This was referenced Sep 8, 2026
[Bug] Cached MessageMetadata can outlive the buffer it was parsed from when managedLedgerCacheCopyEntries=true #26493
Closed
[Bug] Transaction log and pending-ack store entries are parsed as MessageMetadata on every cache insert and always fail #26494
Open
@lhotari lhotari mentioned this pull request Sep 8, 2026
[fix][ml] Parse the cached entry's message metadata from the buffer the cache keeps #26495
Merged
1 of 14 tasks
lhotari added a commit to lhotari/pulsar that referenced this pull request Sep 8, 2026
@lhotari
[improve][ml] Skip message metadata parsing for ledgers that don't ho…
f57acac
…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.
dao-jun pushed a commit to ascentstream/pulsar that referenced this pull request Sep 20, 2026
@lhotari @dao-jun
[improve][broker] Reduce unnecessary MessageMetadata parsing by cachi…
87e7159
…ng the parsed instance in the broker cache (apache#24682)

(cherry picked from commit 53bbd4a)
This was referenced Oct 3, 2026
[fix][ml] Decode the shared cached message metadata before publishing it to other threads lhotari/pulsar#342
Closed
[fix][ml] Decode the shared cached message metadata before publishing it to other threads #26824
Merged
@dao-jun dao-jun mentioned this pull request Oct 4, 2026
[feat][ml] Port batch read and managed-ledger cache improvements (PIP-430) on BK 4.17.4.1 ascentstream/pulsar#105
Closed
@nodece nodece mentioned this pull request Oct 13, 2026
[feat][ml] Port batch read and managed-ledger cache improvements (PIP-430) on BK 4.17.4.1 (ml-only subset) ascentstream/pulsar#106
Closed
nodece pushed a commit to ascentstream/pulsar that referenced this pull request Oct 13, 2026
@lhotari @nodece
[improve][broker] Reduce unnecessary MessageMetadata parsing by cachi…
a1ec003
…ng the parsed instance in the broker cache (apache#24682)

(cherry picked from commit 53bbd4a)
(cherry picked from commit 87e7159)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@coderzc coderzc coderzc approved these changes
@Technoboy- Technoboy- Awaiting requested review from Technoboy-

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@lhotari lhotari

Labels

cherry-picked/branch-4.1 doc-not-needed Your PR changes do not impact docs ready-to-test release/4.1.1

Projects

None yet

Milestone

4.2.0

Development

Successfully merging this pull request may close these issues.

[Bug] Performance improvement opportunity in caching parsed message metadata

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@lhotari @codecov-commenter @coderzc @Technoboy-
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.