Skip to content

[feat][ml] Support Bookkeeper Batch Read API#25280

Open
dao-jun wants to merge 14 commits into
apache:masterfrom
dao-jun:dev/support_bk_batch_read
Open

[feat][ml] Support Bookkeeper Batch Read API#25280
dao-jun wants to merge 14 commits into
apache:masterfrom
dao-jun:dev/support_bk_batch_read

Conversation

@dao-jun

@dao-jun dao-jun commented Mar 4, 2026

Copy link
Copy Markdown
Member

Motivation

In BP-62, Bookkeeper starting to support batch read API,
the PR is to support Bookkeeper batch reading on the Pulsar side.

Modifications

  1. Support Bookkeeper batch read API
  2. Introduce a new flag bookkeeperEnableBatchRead to control enable BK batch read or not, the default value is false.

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

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:

@dao-jun dao-jun self-assigned this Mar 4, 2026
@dao-jun dao-jun added type/feature The PR added a new feature or issue requested a new feature ready-to-test area/ML labels Mar 4, 2026
@github-actions github-actions Bot added doc-not-needed Your PR changes do not impact docs and removed doc-label-missing labels Mar 4, 2026
@apache apache deleted a comment from github-actions Bot Mar 4, 2026
@merlimat merlimat requested a review from hangc0276 March 4, 2026 22:04
@codelipenghui codelipenghui added this to the 4.2.0 milestone Mar 5, 2026

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The EntryCacheDisabled.java should also adopt the new method?

And from the test perspective, this PR has 0 test coverage for the core batch read logic.

@dao-jun dao-jun marked this pull request as draft April 4, 2026 07:41
@dao-jun dao-jun marked this pull request as ready for review April 4, 2026 08:12
@dao-jun dao-jun closed this Apr 4, 2026
@dao-jun dao-jun reopened this Apr 4, 2026
@dao-jun dao-jun requested review from codelipenghui and coderzc April 5, 2026 05:35
@lhotari lhotari modified the milestones: 4.2.0, 4.3.0 Apr 27, 2026
dao-jun added 4 commits June 11, 2026 10:53
# Conflicts:
#	testmocks/src/main/java/org/apache/bookkeeper/client/PulsarMockLedgerHandle.java
serviceConfig.isCacheEvictionByMarkDeletedPosition());
managedLedgerConfig.setCacheEvictionByExpectedReadCount(false);
}
managedLedgerConfig.setBatchReadEnabled(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should probably be gated by the final BookKeeper ClientConfiguration instead of ServiceConfiguration alone. BookKeeperClientFactoryImpl#createBkClientConfiguration later applies bookkeeper_ passthrough properties, so an operator can set managedLedgerBatchReadEnabled=true and bookkeeper_useV2WireProtocol=false. In that case ML enables batch reads, but the actual BK client uses the v3 protocol path where batch reads are unsupported. Please either reject this conflicting configuration or derive the ML batch-read flag from the actual BK client config.

private static void doBatchRead(ReadHandle handle, long firstEntry, int maxCount, int maxSize,
List<LedgerEntry> receivedEntries, List<LedgerEntries> ledgerEntries,
CompletableFuture<LedgerEntries> future) {
handle.batchReadUnconfirmedAsync(firstEntry, maxCount - receivedEntries.size(), maxSize)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

batchReadUnconfirmedAsync can throw synchronously, for example when the actual BK client uses the non-v2 path where PerChannelBookieClient throws UnsupportedOperationException for batch reads. Since this method returns CompletableFuture, Pulsar convention is to surface failures through the returned future. Please wrap this call and complete the future exceptionally, or fallback to readUnconfirmedAsync.

lastReceivedEntry = entry.getEntryId();
}
ledgerEntries.add(entries);
if (receivedEntries.size() >= maxCount || prevReceivedCount == receivedEntries.size()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can complete successfully with fewer entries than the caller requested. BK batch read may legally return a partial prefix, but the previous readAsync(firstEntry, lastEntry) contract for these callers is effectively "read the full range or fail". If a later batch returns empty after some entries were already collected, this code currently returns the partial result. Please verify receivedEntries.size() == maxCount before completing successfully, or fallback/fail when the full range cannot be assembled.

/**
* Max size in bytes for per-batch read request. If set to 0 or negative,
* uses the netty max frame size (default 5MB).
* Batch read may return fewer entries if total size exceeds this limit.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The comment says batchReadMaxSizeBytes <= 0 uses the Netty max frame size, but ReadEntryUtils only enables batch read when batchReadMaxSize > 0. Please align the implementation and the config contract, either by passing non-positive values through to BK so it can apply its fallback, or by updating this documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ML doc-not-needed Your PR changes do not impact docs ready-to-test type/feature The PR added a new feature or issue requested a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants