pulsar
pulsar copied to clipboard
[fix][ml]Received more than once callback when calling cursor.delete
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 tomark-deleted.scenario-B1: Acked some positions, butindividualDeletedMessagesbecame empty after combining ranges in the methodsetAcknowledgedPosition,scenario-B2: Acked some positions, andindividualDeletedMessageswas still not empty.
Triggering callbacks
- Regarding the
scenario-A, Cursor will skip callingmark-deleted, because it is meaningless. - Regarding the
scenario-B, Cursor will callmark-deleted, which will trigger acallback.
Issue
Regarding the scenario-B1, the Cursor triggers twice the callbacks.
- The first time: calls the callback if
individualDeletedMessagesis 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 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.
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
@@ 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: |
: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.