Skip to content

Conversation

@oneby-wang
Copy link
Contributor

@oneby-wang oneby-wang commented Dec 24, 2025

Motivation

We do mark deleting operation in ManagedLedgerImpl.maybeUpdateCursorBeforeTrimmingConsumedLedger() after #25087.

Mark deleting an already mark-deleted position will throw an Exception.

Please see comment for race condition case: #25101 (comment).

See also:

  1. [fix][test] Fix ManagedCursorTest and NonDurableCursorTest flaky tests #25101
  2. [fix][test] Fix ManagedCursorTest and NonDurableCursorTest flaky tests #25101 (comment)

Modifications

  1. Modify ManagedLedgerImpl.maybeUpdateCursorBeforeTrimmingConsumedLedger() method:
    a. snapshot positions into a local variable to avoid race condition.
    b. use markDeletePosition instead of persistentMarkDeletedPosition to set lastAckedPosition, because persistentMarkDeletedPosition is updated after markDeletePosition.
    c. add if check logic to avoid mark deleting an already mark-deleted position.
    d. wait maybeUpdateCursorBeforeTrimmingConsumedLedger() completed when opening ledger.
    e. move maybeUpdateCursorBeforeTrimmingConsumedLedger() into synchronized block when creating a new ledger. I think new ledger's initialization work should be completed before the first entry is added to this ledger.

  2. Modify ManagedCursorImpl.getNumberOfEntries() method: snapshot positions into a local variable to avoid race condition, error logs like this:

java.lang.IllegalArgumentException: Invalid range: [104:0..103:1)

    at com.google.common.collect.Range.<init>(Range.java:334)
    at com.google.common.collect.Range.create(Range.java:134)
    at com.google.common.collect.Range.closedOpen(Range.java:171)
    at org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.getNumberOfEntries(ManagedCursorImpl.java:1253)
    at org.apache.bookkeeper.mledger.impl.ManagedLedgerTest.testNeverThrowsMarkDeletingMarkedPositionInMaybeUpdateCursorBeforeTrimmingConsumedLedger(ManagedLedgerTest.java:3838)
  1. Ignore changes in ManagedCursorImpl.asyncMarkDelete() method, I just snapshot positions into a local variable to avoid race condition. It should be fixed by: [fix][broker] Move newPosition to nextValidLedger:-1 to avoid cursor position and ledger inconsistency in ManagedCursorImpl #25117.

  2. Add testNeverThrowsMarkDeletingMarkedPositionInMaybeUpdateCursorBeforeTrimmingConsumedLedger test in ManagedLedgerImplTest to verify the code change.

  3. Fix tests due to this PR's code change.

Verifying this change

  • Make sure that the change passes the CI checks.

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: oneby-wang#18

@github-actions
Copy link

@oneby-wang Please add the following content to your PR description and select a checkbox:

- [ ] `doc` <!-- Your PR contains doc changes -->
- [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
- [ ] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-complete` <!-- Docs have been already added -->

@oneby-wang oneby-wang marked this pull request as draft December 24, 2025 01:58
@github-actions github-actions bot added doc-not-needed Your PR changes do not impact docs and removed doc-label-missing labels Dec 24, 2025
@oneby-wang oneby-wang force-pushed the maybeUpdateCursorBeforeTrimmingConsumedLedger_mark_delete branch from eed610c to 3f77d84 Compare December 24, 2025 02:27
@oneby-wang oneby-wang force-pushed the maybeUpdateCursorBeforeTrimmingConsumedLedger_mark_delete branch from f0619ec to 3de1d97 Compare December 25, 2025 04:56
@oneby-wang oneby-wang marked this pull request as ready for review December 28, 2025 04:29
@oneby-wang oneby-wang force-pushed the maybeUpdateCursorBeforeTrimmingConsumedLedger_mark_delete branch from a72d351 to 8a5b7d4 Compare December 28, 2025 04:46
@oneby-wang oneby-wang force-pushed the maybeUpdateCursorBeforeTrimmingConsumedLedger_mark_delete branch from 8a5b7d4 to 3294d78 Compare December 28, 2025 04:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-not-needed Your PR changes do not impact docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant