Skip to content

[feat][ml] Configure and track named Pulsar allocators independently - #26597

Merged
merlimat merged 4 commits into
apache:masterfrom
lhotari:lh-feat-named-bytebuf-allocators
Sep 15, 2026
Merged

merlimat merged 4 commits into
apache:masterfrom
lhotari:lh-feat-named-bytebuf-allocators

Conversation

@lhotari

@lhotari lhotari commented Sep 15, 2026

Copy link
Copy Markdown
Member

Builds on #26595, which has merged. This branch has been rebased onto master; the diff now contains only the named-allocator changes.

Motivation

The managed-ledger entry cache needs its own allocator to retain separate allocation statistics, while benefiting from Pulsar's configurable allocator implementation and OOM handling. This also allows cache copies to use the adaptive allocator introduced in #26595. Efficient cache-owned copies are relevant to the BP-62 batch-read work in #25280, where retaining individual entries can retain larger backing buffers.

Modifications

  • Introduce a registry that atomically creates one allocator per identifier. RangeEntryCacheImpl keeps a private ALLOCATOR obtained through PulsarByteBufAllocator.getOrCreate("ml-cache").
  • Resolve each setting from pulsar.allocator.<id>.<setting>, then pulsar.allocator.<setting>, then its built-in default. Supported settings are type, exit_on_oom, and out_of_memory_policy.
  • Support pulsar.allocator.default.* overrides for the default allocator. These overrides do not affect other identifiers. Settings are read when each allocator is first created.
  • Preserve separate cache metrics. Generalize the allocation-statistics snapshot for pooled, unpooled, and adaptive allocators, and resolve broker allocator stats through the registry without creating unknown allocators. Adaptive used-memory statistics report usedDirectMemory(); unavailable allocation counts report -1.
  • Use Netty's global leak-detection level. Remove support for pulsar.allocator.leak_detection; no per-allocator leak-detection setting is introduced.
  • Document named configuration and retain the deprecated pulsar.allocator.pooled fallback introduced in [feat][misc] Support AdaptiveByteBufAllocator with configurable allocator type and metrics #26595.

For example, keep general allocation pooled while enabling adaptive allocation for cache copies:

-Dpulsar.allocator.type=pooled -Dpulsar.allocator.ml-cache.type=adaptive

Verifying this change

  • Make sure that the change passes the CI checks.

All 46 scoped tests and quickCheck passed locally:

./gradlew :pulsar-common:test --tests 'org.apache.pulsar.common.allocator.*' \
  :managed-ledger:test --tests 'org.apache.bookkeeper.mledger.impl.cache.RangeEntryCacheImplTest' \
  :pulsar-broker:test --tests 'org.apache.pulsar.broker.stats.AllocatorStatsGeneratorTest' \
  --tests 'org.apache.pulsar.broker.stats.OpenTelemetryManagedLedgerCacheStatsTest' quickCheck

Tests cover concurrent registration, independent heap/direct metrics for all three allocator types, property inheritance and overrides, OOM policies, global leak detection, cache copy ownership, and broker metrics. Shell syntax and whitespace checks also passed.

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

  • Dependencies (add or upgrade a dependency)
  • The public API — adds registry APIs, makes the cache allocator private, moves/generalizes the allocation-statistics helper, and removes the Pulsar leak-detection property constant.
  • The schema
  • The default values of configurations — named cache allocation uses the selected allocator's standard defaults instead of custom zero heap arenas and caching for all threads; leak detection follows Netty's global setting.
  • The threading model
  • The binary protocol
  • The REST endpoints — allocator stats look up registered identifiers, retaining the response schema.
  • The admin CLI options
  • The metrics — retain separate cache statistics and support the selected allocator implementation.
  • Anything that affects deployment — adds named allocator settings and changes leak-detection configuration to Netty's global property.

Register one allocator per identifier with atomic get-or-create. Named type and OOM settings override unqualified defaults, including overrides for the default allocator. Use Netty global leak detection instead of Pulsar allocator leak settings.

Give the entry cache a private ml-cache allocator from the registry and restore its separate pool metrics. Resolve allocator stats through the registry and share a metric snapshot implementation across JVM and cache reporting for pooled, unpooled, and adaptive allocation.

Validation: 46 scoped allocator, cache, and broker metrics tests; quickCheck; shell syntax checks.

Assisted-by: Codex
@lhotari
lhotari force-pushed the lh-feat-named-bytebuf-allocators branch from 30782aa to df6dc19 Compare September 15, 2026 16:53
@lhotari
lhotari marked this pull request as ready for review September 15, 2026 16:54
@lhotari

lhotari commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

/pulsarbot rerun

@lhotari
lhotari requested a review from merlimat September 15, 2026 20:24
@merlimat
merlimat merged commit ca58c20 into apache:master Sep 15, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants