Skip to content

[improve][broker] Make entry cache copying dynamically configurable - #27148

Merged
dao-jun merged 1 commit into
apache:masterfrom
poorbarcode:dynamic_entry_cache
Oct 28, 2026
Merged

dao-jun merged 1 commit into
apache:masterfrom
poorbarcode:dynamic_entry_cache

Conversation

@poorbarcode

Copy link
Copy Markdown
Contributor

Motivation

A cached entry can retain a small slice of a much larger inbound direct-memory buffer. The existing managedLedgerCacheCopyEntries setting avoids that retention by copying entry payloads, but changing it currently requires restarting the broker and recreating caches. Operators need to enable or disable copying for future cache inserts without restarting the broker or clearing useful cached data.

This change is extracted from #27110 and can be reviewed and merged independently of request-frame memory tracking and limiting.

Modifications

This change makes the existing managedLedgerCacheCopyEntries setting dynamically configurable. Existing and newly created entry caches read one shared policy when inserting entries, so updates do not require cache recreation. Updates affect future inserts without clearing or recopying existing entries, while BookKeeper batch reads continue to force copying.

  • Mark the broker setting as dynamic and propagate configuration updates to the managed-ledger factory through the existing configuration listener mechanism.
  • Store the copy policy in one volatile factory configuration field and remove per-cache snapshots that can miss or overwrite concurrent updates during cache creation.
  • Preserve coverage for cache creation and publication races, overlapping updates, batch inserts, asynchronous storage reads, and existing-entry retention.
  • Add an independent broker test for enabling, disabling, and deleting the dynamic override, and document the behavior in broker, standalone, and deployment configuration files.

Validation: full ./gradlew quickCheck and 41 focused managed-ledger and broker tests passed with retries disabled.

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

  • Broker configuration: managedLedgerCacheCopyEntries becomes dynamic; its default remains false.
  • Public API
  • Wire protocol
  • Metrics
  • Dependencies

Best practice

Enable managedLedgerCacheCopyEntries when cached entry slices retain substantially larger inbound buffers, using pulsar-admin brokers update-dynamic-config --config managedLedgerCacheCopyEntries --value true. This trades payload-copy work for reduced retention of larger source buffers. Existing cached entries keep their original buffers until normal eviction or removal, so enabling copying does not immediately reclaim their memory. Set the value to false to stop copying future normal inserts, or delete the dynamic override to restore the broker's startup setting; batch reads still copy entries.

Apply managedLedgerCacheCopyEntries updates to future inserts through one shared volatile policy. Preserve cached entries and mandatory batch-read copying, and cover dynamic override deletion, asynchronous reads, and concurrent cache creation and publication.

Extracted from the request-frame memory tracking change for independent review.

Assisted-by: Codex

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@dao-jun
dao-jun merged commit aa2e7b9 into apache:master Oct 28, 2026
44 checks passed
lhotari pushed a commit that referenced this pull request Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants