GeezerVison is showing github.com — [fix][broker] Apply managedLedgerContinueCachingAddedEntriesAfterLastActiveCursorLeavesMillis to managed ledgers by lhotari · Pull Request #26785 · apache/pulsar
Conversation
lhotari
commented
Sep 30, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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.
…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)
…ast active cursor leaves
Assisted-by: Claude Code (claude-opus-5-5)
…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)
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)
Uh oh!
There was an error while loading. Please reload this page.
dao-jun
pushed a commit
to ascentstream/pulsar
that referenced
this pull request
Oct 5, 2026
…ActiveCursorLeavesMillis to managed ledgers (apache#26785)
(cherry picked from commit 2aee226)
nodece
pushed a commit
to ascentstream/pulsar
that referenced
this pull request
Oct 13, 2026
…ActiveCursorLeavesMillis to managed ledgers (apache#26785)
(cherry picked from commit 2aee226)
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Development
Successfully merging this pull request may close these issues.
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.
|