Skip to content

[fix][ml] Read published positions through stale read-only caches - #27223

Merged
codelipenghui merged 2 commits into
apache:masterfrom
codelipenghui:penghui/fix-published-read-only-cache-reads
Nov 6, 2026
Merged

codelipenghui merged 2 commits into
apache:masterfrom
codelipenghui:penghui/fix-published-read-only-cache-reads

Conversation

@codelipenghui

@codelipenghui codelipenghui commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

A shared entry cache can retain an older read-only managed ledger whose inventory predates a newly published snapshot ledger. Falling back to the read handle LAC rejects that published position when the open handle piggyback LAC lags, interrupting snapshot recovery. Explicit point reads need to work without changing cursor visibility.

Modifications

  • Route read-only singleton reads before the captured-inventory fallback.
  • Use unconfirmed reads for an open handle and retain the confirmed final bound for a closed handle.
  • Preserve writable/shadow, cursor and range-read bounds.
  • Cover direct published-tail reads and shared-cache rollover with real BookKeeper tests, plus focused boundary tests.

The real BookKeeper tests create their cursors before reading, so this change is independent of the separate read-only frontier initialization fix.

Verifying this change

  • Make sure that the change passes the CI checks.

Base: Apache master 8b827b7953aa62f51913b29377b760aec59db0d0.

  • Scoped Gradle tests: org.apache.bookkeeper.mledger.impl.cache.ReadEntryUtilsTest, org.apache.bookkeeper.mledger.impl.ManagedLedgerBkTest.testReadOnlyDirectReadLastPublishedEntryBeyondCursorFrontier, org.apache.bookkeeper.mledger.impl.ManagedLedgerBkTest.testReadOnlyDirectReadWithSharedCacheAfterRollover. 42 passed, zero failures/errors/skips, retries disabled.
  • ./gradlew quickCheck --max-workers=2: passed.
  • git diff --check: passed.

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

  • 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

Route explicit read-only singleton positions before the captured-inventory fallback. Use the open handle published-position read without changing cursor or range frontiers, and retain closed-handle bounds. Cover direct LAC lag and cache-owner rollover with real BookKeeper tests.

Assisted-by: OpenAI Codex
@codelipenghui
codelipenghui marked this pull request as ready for review October 31, 2026 00:28
@codelipenghui codelipenghui self-assigned this Oct 31, 2026
@codelipenghui codelipenghui added this to the 5.1.0 milestone Oct 31, 2026

@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. Thanks for tracking down this snapshot-recovery read failure and covering it with real BookKeeper tests.

I checked that the cursor and range-read paths stay bounded before they reach this method: ManagedLedgerImpl.java:2962-2998 caps the range at the captured last position, so only explicit point reads take the new branch. Reverting the production change makes the new ReadEntryUtilsTest cases and both new ManagedLedgerBkTest cases fail. The red Broker Group 2 check is a Failed to bind to /0.0.0.0:42175 error in PulsarFunctionTlsMixedListenersTest.setup, which does not touch this code, so a re-run should clear it. One small, non-blocking note is inline.

@codelipenghui
codelipenghui merged commit fb8916a into apache:master Nov 6, 2026
118 of 123 checks passed
codelipenghui added a commit that referenced this pull request Nov 8, 2026
…7223)

Adapted for branch-4.0: ReadEntryUtils has no batch read parameters on this branch, so ReadEntryUtilsTest
is a new file with only the tests of this change, and ManagedLedgerBkTest uses new ManagedLedgerConfig()
instead of defaultConfig().

(cherry picked from commit fb8916a)
codelipenghui added a commit that referenced this pull request Nov 9, 2026
…7223)

Adapted for branch-4.2: ReadEntryUtils has no batch read parameters on this branch, so ReadEntryUtilsTest
is a new file with only the tests of this change.

(cherry picked from commit fb8916a)
lhotari pushed a commit that referenced this pull request Nov 9, 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.

2 participants