pulsar icon indicating copy to clipboard operation
pulsar copied to clipboard

[fix][ml]Received more than once callback when calling cursor.delete

Open poorbarcode opened this issue 5 months ago • 2 comments
trafficstars

Motivation

About cursor deleting, there are two cases

  • scenario-A: Acked nothing, because all positions have been acknowledged before.
  • scenario-B: Acked some position, then it will try to mark-deleted.
    • scenario-B1: Acked some positions, but individualDeletedMessages became empty after combining ranges in the method setAcknowledgedPosition,
    • scenario-B2: Acked some positions, and individualDeletedMessages was still not empty.

Triggering callbacks

  • Regarding the scenario-A, Cursor will skip calling mark-deleted, because it is meaningless.
  • Regarding the scenario-B, Cursor will call mark-deleted, which will trigger a callback.

Issue Regarding the scenario-B1, the Cursor triggers twice the callbacks.

  • The first time: calls the callback if individualDeletedMessages is empty. https://github.com/apache/pulsar/blob/master/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java#L2479
boolean empty = individualDeletedMessages.isEmpty();
if (empty) {
    callback.deleteComplete(ctx);
}
  • The first time: calls the callback after calling mark-deleted. https://github.com/apache/pulsar/blob/master/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java#L2499
internalAsyncMarkDelete(newMarkDeletePosition, properties, new MarkDeleteCallback() {
        @Override
        public void markDeleteComplete(Object ctx) {
            callback.deleteComplete(ctx);
        }
}

Modifications

To confirm the scenario matches scenario-A, rather than confirming individualDeletedMessages.isEmpty, use a specific variable to record it.

Documentation

  • [ ] doc
  • [ ] doc-required
  • [x] doc-not-needed
  • [ ] doc-complete

Matching PR in forked repository

PR in forked repository: x

poorbarcode avatar Jun 12 '25 16:06 poorbarcode

@poorbarcode Could you please write down the reason that why the callback get called multiple times? If there is anything that we cannot control (network failures or something). I'm good to add a defensive solution to avoid multiple calls. If the issue which we can control, I would like to fix the issue at the first place.

codelipenghui avatar Jun 12 '25 17:06 codelipenghui

Codecov Report

Attention: Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 74.26%. Comparing base (bbc6224) to head (e0c979e). Report is 1169 commits behind head on master.

Files with missing lines Patch % Lines
...che/bookkeeper/mledger/impl/ManagedCursorImpl.java 75.00% 1 Missing :warning:
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #24405      +/-   ##
============================================
+ Coverage     73.57%   74.26%   +0.69%     
+ Complexity    32624    32313     -311     
============================================
  Files          1877     1868       -9     
  Lines        139502   145366    +5864     
  Branches      15299    16629    +1330     
============================================
+ Hits         102638   107958    +5320     
+ Misses        28908    28860      -48     
- Partials       7956     8548     +592     
Flag Coverage Δ
inttests 26.73% <75.00%> (+2.14%) :arrow_up:
systests 23.36% <25.00%> (-0.97%) :arrow_down:
unittests 73.75% <75.00%> (+0.90%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...che/bookkeeper/mledger/impl/ManagedCursorImpl.java 78.83% <75.00%> (-0.47%) :arrow_down:

... and 1081 files with indirect coverage changes

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov-commenter avatar Jun 14 '25 02:06 codecov-commenter