Skip to content

[improve][broker] Expose interface for the replicator in ManagedLedger instead of cast the class - #26298

Open
zymap wants to merge 2 commits into
apache:masterfrom
zymap:yong/refactor-persistentreplicator-cast
Open

[improve][broker] Expose interface for the replicator in ManagedLedger instead of cast the class#26298
zymap wants to merge 2 commits into
apache:masterfrom
zymap:yong/refactor-persistentreplicator-cast

Conversation

@zymap

@zymap zymap commented Aug 10, 2026

Copy link
Copy Markdown
Member

Fixes #xyz

Main Issue: #xyz

PIP: #xyz

Motivation

Managed-ledger callers should depend on the ManagedLedger and ManagedCursor interfaces instead of concrete implementations. The newly added retry logic cast the ledger to ManagedLedgerImpl, causing a ClassCastException for custom managed-ledger implementations.

Modifications

Added ManagedCursor.scheduleReadCallback(...) as a backward-compatible interface method.
Overrode it in ManagedCursorImpl to preserve the existing managed-ledger scheduler and executor behavior.
Updated PersistentReplicator to use the interface method without casting to ManagedLedgerImpl.

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

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


@Override
public void scheduleReadCallback(Runnable callback, long delay, TimeUnit unit) {
ledger.getScheduledExecutor().schedule(() -> ledger.getExecutor().execute(callback), delay, unit);

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.

It could be useful to wrap the Runnable passed to .schedule with org.apache.pulsar.common.util.Runnables.catchingAndLoggingThrowables so that possible runtime exceptions would get logged.

* @param unit the time unit of the delay
*/
default void scheduleReadCallback(Runnable callback, long delay, TimeUnit unit) {
CompletableFuture.delayedExecutor(delay, unit).execute(callback);

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.

It could be useful to wrap callback with org.apache.pulsar.common.util.Runnables.catchingAndLoggingThrowables so that runtime exceptions get logged.

@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, just 2 suggestions to improve logging for failure cases.

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.

2 participants