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 — [fix][broker] Apply managedLedgerContinueCachingAddedEntriesAfterLastActiveCursorLeavesMillis to managed ledgers by lhotari · Pull Request #26785 · apache/pulsar

Conversation

@lhotari

@lhotari lhotari commented Sep 30, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

PIP: PIP-430

Motivation

PIP-430 (#24623) added managedLedgerContinueCachingAddedEntriesAfterLastActiveCursorLeavesMillis, which keeps caching added entries for a while when there are no active cursors: after the last active cursor leaves, and right after a topic is loaded. This avoids cache misses when a consumer disconnects and reconnects shortly after. The default is 2 * managedLedgerCacheEvictionTimeThresholdMillis.

The setting never took effect. The broker set the value on ManagedLedgerFactoryConfig, but nothing reads it there. ManagedLedgerImpl reads the value from ManagedLedgerConfig, where the field had only a getter and was never assigned, so it was always 0. As a result, with cacheEvictionByExpectedReadCount enabled (the default), ActiveManagedCursorContainerImpl.shouldCacheAddedEntry() returned false as soon as there were no active cursors, and the configured grace period was ignored.

Modifications

  • Add a setter for continueCachingAddedEntriesAfterLastActiveCursorLeavesMillis to ManagedLedgerConfig.
  • Fill the value in BrokerService.getManagedLedgerConfig, next to the other cache settings. When the setting is unset, it defaults to 2 * managedLedgerCacheEvictionTimeThresholdMillis, as documented.
  • Remove the unused field from ManagedLedgerFactoryConfig, and the code in ManagedLedgerClientFactory that set it.
  • Set the setting to 0 in tests that count BookKeeper reads of entries added while there is no active cursor. With the default now in effect, those entries are read from the cache instead:
    • PersistentMessageExpiryMonitorTest.testTopicExpireMessages counts ledger reads while its subscriptions have no active consumers.
    • OpenTelemetryTopicStatsTest.testMessagingMetrics checks the storage entry incoming counter for messages produced before any consumer subscribes.

With this change, the documented default takes effect: added entries keep being cached for 2 * managedLedgerCacheEvictionTimeThresholdMillis (2 seconds by default) after the last active cursor leaves or the topic is loaded. Before, they stopped being cached immediately.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • ManagedLedgerTest.testContinueCachingAddedEntriesWithoutActiveCursors: with a 5-second window and no cursors, an added entry is cached.
  • ManagedLedgerTest.testNoCachingOfAddedEntriesWithoutActiveCursorsWhenContinueCachingDisabled: with the window set to 0, an added entry isn't cached.
  • ManagedLedgerTest.testContinueCachingAddedEntriesStartsWhenLastActiveCursorLeaves: the window starts only when the last active cursor leaves, not when one of several cursors leaves; added entries stop being cached after the window passes, and a cursor leaving again starts a new window.
  • BrokerServiceTest.testManagedLedgerContinueCachingAddedEntriesConfiguration: an explicit broker setting reaches the ManagedLedgerConfig, and an unset setting gives the 2 * managedLedgerCacheEvictionTimeThresholdMillis default.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Sorry, something went wrong.

Uh oh!

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

All reactions
@lhotari
[fix][broker] Apply managedLedgerContinueCachingAddedEntriesAfterLast…
e816ae6
…ActiveCursorLeavesMillis to managed ledgers

The broker set the value on ManagedLedgerFactoryConfig, which nothing read.
ManagedLedgerImpl reads it from ManagedLedgerConfig, where it had no setter
and was always 0, so added entries stopped being cached as soon as the last
active cursor left or the topic was loaded.

Add a setter to ManagedLedgerConfig, fill it in
BrokerService.getManagedLedgerConfig (defaulting to
2 * managedLedgerCacheEvictionTimeThresholdMillis when unset) and remove the
unused ManagedLedgerFactoryConfig field.

Assisted-by: Claude Code (claude-opus-5-5)
@lhotari
lhotari requested review from Technoboy-, dao-jun, david-streamlio, merlimat and nodece September 30, 2026 19:46
@lhotari lhotari added this to the 5.0.0 milestone Sep 30, 2026
lhotari added 2 commits September 30, 2026 22:48
@lhotari
[fix][broker] Test that the continue-caching window starts when the l…
7d476ae
…ast active cursor leaves

Assisted-by: Claude Code (claude-opus-5-5)
@lhotari
[fix][test] Disable continue-caching in PersistentMessageExpiryMonito…
54074a5
…rTest

testTopicExpireMessages counts BookKeeper reads of the first ledger. Now that
managedLedgerContinueCachingAddedEntriesAfterLastActiveCursorLeavesMillis takes
effect, added entries stay in the entry cache although the subscriptions have no
active consumers, the expiry check reads them from the cache and the count is 0.

Assisted-by: Claude Code (claude-opus-5-5)
dao-jun
dao-jun approved these changes Sep 30, 2026
View reviewed changes
@lhotari
[fix][test] Disable continue-caching in OpenTelemetryTopicStatsTest
7e2453e
testMessagingMetrics asserts the storage entry incoming counter, which counts
entries read from BookKeeper. Now that
managedLedgerContinueCachingAddedEntriesAfterLastActiveCursorLeavesMillis takes
effect, the entries produced before any consumer subscribes stay in the entry
cache, the consumers read them from the cache and the counter is 0.

Assisted-by: Claude Code (claude-opus-5-5)
@lhotari
lhotari merged commit 2aee226 into apache:master Sep 30, 2026
44 checks passed

Uh oh!

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

@lhotari lhotari added the release/4.2.5 label Oct 1, 2026
ascentstream-bot pushed a commit to ascentstream/pulsar that referenced this pull request Oct 1, 2026
@lhotari
[fix][broker] Apply managedLedgerContinueCachingAddedEntriesAfterLast…
0f05f89
…ActiveCursorLeavesMillis to managed ledgers (apache#26785)

(cherry picked from commit 2aee226)
@dao-jun dao-jun mentioned this pull request Oct 5, 2026
[feat][ml] Port batch read and managed-ledger cache improvements (PIP-430) on BK 4.17.4.1 ascentstream/pulsar#105
Closed
dao-jun pushed a commit to ascentstream/pulsar that referenced this pull request Oct 5, 2026
@lhotari @dao-jun
[fix][broker] Apply managedLedgerContinueCachingAddedEntriesAfterLast…
0210b23
…ActiveCursorLeavesMillis to managed ledgers (apache#26785)

(cherry picked from commit 2aee226)
Radiancebobo pushed a commit to Radiancebobo/pulsar that referenced this pull request Oct 8, 2026
@lhotari hechengbo
[fix][broker] Apply managedLedgerContinueCachingAddedEntriesAfterLast…
0de0838
…ActiveCursorLeavesMillis to managed ledgers (apache#26785)
@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
[fix][broker] Apply managedLedgerContinueCachingAddedEntriesAfterLast…
ad64a19
…ActiveCursorLeavesMillis to managed ledgers (apache#26785)

(cherry picked from commit 2aee226)
@lhotari lhotari added release/4.2.6 release/4.2.5 cherry-picked/branch-4.2 and removed release/4.2.5 release/4.2.6 labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@dao-jun dao-jun dao-jun approved these changes
@merlimat merlimat Awaiting requested review from merlimat
@nodece nodece Awaiting requested review from nodece
@Technoboy- Technoboy- Awaiting requested review from Technoboy-
@david-streamlio david-streamlio Awaiting requested review from david-streamlio

Uh oh!

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

Assignees

No one assigned

Labels

cherry-picked/branch-4.2 release/4.2.5

Projects

None yet

Milestone

5.0.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

2 participants

@lhotari @dao-jun
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.