You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "codelipenghui (via GitHub)" <gi...@apache.org> on 2026/03/08 18:03:32 UTC
[PR] [improve][ml] Clean up managed-ledger code: deduplicate logic and use shared utilities [pulsar]
codelipenghui opened a new pull request, #25298:
URL: https://github.com/apache/pulsar/pull/25298
## Summary
- Replace inline `NoSuchLedgerExists` checks with `Errors.isNoSuchLedgerExistsException()` in `ManagedLedgerFactoryImpl` and `ManagedLedgerImpl`
- Refactor `createManagedLedgerException(Throwable)` to use `FutureUtil.unwrapCompletionException()` with proper null guards
- Simplify `NullLedgerOffloader` to use `FutureUtil.failedFuture()`
- Extract duplicated add-completion logic in `OpAddEntry` into `completeAdd()` method
- Extract duplicated range removal in `RangeEntryCacheImpl` into `removeRangeAndNotify()` method
## Motivation
Reduce code duplication and improve maintainability across the managed-ledger module by consolidating repeated patterns into shared utility methods.
## Modifications
- **ManagedLedgerFactoryImpl**: Use `Errors.isNoSuchLedgerExistsException(rc)` instead of inline checks
- **ManagedLedgerImpl**: Remove private `isLedgerNotExistException()`, use shared `Errors.isNoSuchLedgerExistsException()`; refactor `createManagedLedgerException(Throwable)` to use `FutureUtil.unwrapCompletionException()` with null guards for both input and unwrapped cause
- **NullLedgerOffloader**: Replace manual `CompletableFuture` + `completeExceptionally` with `FutureUtil.failedFuture()`
- **OpAddEntry**: Extract duplicated callback-notify-release-recycle pattern from `addComplete`/`closeComplete` into `completeAdd()`
- **RangeEntryCacheImpl**: Extract duplicated `removeRange` + `entriesRemoved` into `removeRangeAndNotify()`, with DEBUG log preserved in `invalidateAllEntries` and TRACE in the shared method
## Verifying this change
This is a refactoring change with no behavioral modifications (except improved null handling in `createManagedLedgerException`). Existing tests should cover all affected code paths.
## Documentation
- [ ] `doc-required`
Check the box above or label this PR directly if your changes impact documentation.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve][ml] Clean up managed-ledger code: deduplicate logic and use shared utilities [pulsar]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #25298:
URL: https://github.com/apache/pulsar/pull/25298#issuecomment-4020798481
## [Codecov](https://app.codecov.io/gh/apache/pulsar/pull/25298?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `48.38710%` with `16 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 72.62%. Comparing base ([`f83251a`](https://app.codecov.io/gh/apache/pulsar/commit/f83251a57fd5f4bc20cd47ec7b950d6321d03488?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`1470c31`](https://app.codecov.io/gh/apache/pulsar/commit/1470c312bffb093d28cc221849142ac7eea16af0?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 1 commits behind head on master.
| [Files with missing lines](https://app.codecov.io/gh/apache/pulsar/pull/25298?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...che/bookkeeper/mledger/impl/ManagedLedgerImpl.java](https://app.codecov.io/gh/apache/pulsar/pull/25298?src=pr&el=tree&filepath=managed-ledger%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbookkeeper%2Fmledger%2Fimpl%2FManagedLedgerImpl.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bWFuYWdlZC1sZWRnZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvbWxlZGdlci9pbXBsL01hbmFnZWRMZWRnZXJJbXBsLmphdmE=) | 53.84% | [3 Missing and 3 partials :warning: ](https://app.codecov.io/gh/apache/pulsar/pull/25298?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [...keeper/mledger/impl/cache/RangeEntryCacheImpl.java](https://app.codecov.io/gh/apache/pulsar/pull/25298?src=pr&el=tree&filepath=managed-ledger%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbookkeeper%2Fmledger%2Fimpl%2Fcache%2FRangeEntryCacheImpl.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bWFuYWdlZC1sZWRnZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvbWxlZGdlci9pbXBsL2NhY2hlL1JhbmdlRW50cnlDYWNoZUltcGwuamF2YQ==) | 44.44% | [3 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/pulsar/pull/25298?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [...e/bookkeeper/mledger/impl/NullLedgerOffloader.java](https://app.codecov.io/gh/apache/pulsar/pull/25298?src=pr&el=tree&filepath=managed-ledger%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbookkeeper%2Fmledger%2Fimpl%2FNullLedgerOffloader.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bWFuYWdlZC1sZWRnZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvbWxlZGdlci9pbXBsL051bGxMZWRnZXJPZmZsb2FkZXIuamF2YQ==) | 0.00% | [3 Missing :warning: ](https://app.codecov.io/gh/apache/pulsar/pull/25298?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [...kkeeper/mledger/impl/ManagedLedgerFactoryImpl.java](https://app.codecov.io/gh/apache/pulsar/pull/25298?src=pr&el=tree&filepath=managed-ledger%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbookkeeper%2Fmledger%2Fimpl%2FManagedLedgerFactoryImpl.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bWFuYWdlZC1sZWRnZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvbWxlZGdlci9pbXBsL01hbmFnZWRMZWRnZXJGYWN0b3J5SW1wbC5qYXZh) | 0.00% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/pulsar/pull/25298?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
[](https://app.codecov.io/gh/apache/pulsar/pull/25298?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## master #25298 +/- ##
============================================
- Coverage 72.80% 72.62% -0.18%
+ Complexity 34660 34169 -491
============================================
Files 1968 1968
Lines 155954 155941 -13
Branches 17766 17765 -1
============================================
- Hits 113537 113251 -286
- Misses 33447 33658 +211
- Partials 8970 9032 +62
```
| [Flag](https://app.codecov.io/gh/apache/pulsar/pull/25298/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [inttests](https://app.codecov.io/gh/apache/pulsar/pull/25298/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `25.63% <16.12%> (-0.61%)` | :arrow_down: |
| [systests](https://app.codecov.io/gh/apache/pulsar/pull/25298/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `22.36% <22.58%> (-0.15%)` | :arrow_down: |
| [unittests](https://app.codecov.io/gh/apache/pulsar/pull/25298/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `73.60% <48.38%> (-0.17%)` | :arrow_down: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
| [Files with missing lines](https://app.codecov.io/gh/apache/pulsar/pull/25298?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...org/apache/bookkeeper/mledger/impl/OpAddEntry.java](https://app.codecov.io/gh/apache/pulsar/pull/25298?src=pr&el=tree&filepath=managed-ledger%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbookkeeper%2Fmledger%2Fimpl%2FOpAddEntry.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bWFuYWdlZC1sZWRnZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvbWxlZGdlci9pbXBsL09wQWRkRW50cnkuamF2YQ==) | `77.61% <100.00%> (+0.40%)` | :arrow_up: |
| [...kkeeper/mledger/impl/ManagedLedgerFactoryImpl.java](https://app.codecov.io/gh/apache/pulsar/pull/25298?src=pr&el=tree&filepath=managed-ledger%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbookkeeper%2Fmledger%2Fimpl%2FManagedLedgerFactoryImpl.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bWFuYWdlZC1sZWRnZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvbWxlZGdlci9pbXBsL01hbmFnZWRMZWRnZXJGYWN0b3J5SW1wbC5qYXZh) | `59.03% <0.00%> (-0.26%)` | :arrow_down: |
| [...e/bookkeeper/mledger/impl/NullLedgerOffloader.java](https://app.codecov.io/gh/apache/pulsar/pull/25298?src=pr&el=tree&filepath=managed-ledger%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbookkeeper%2Fmledger%2Fimpl%2FNullLedgerOffloader.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bWFuYWdlZC1sZWRnZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvbWxlZGdlci9pbXBsL051bGxMZWRnZXJPZmZsb2FkZXIuamF2YQ==) | `66.66% <0.00%> (+26.66%)` | :arrow_up: |
| [...keeper/mledger/impl/cache/RangeEntryCacheImpl.java](https://app.codecov.io/gh/apache/pulsar/pull/25298?src=pr&el=tree&filepath=managed-ledger%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbookkeeper%2Fmledger%2Fimpl%2Fcache%2FRangeEntryCacheImpl.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bWFuYWdlZC1sZWRnZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvbWxlZGdlci9pbXBsL2NhY2hlL1JhbmdlRW50cnlDYWNoZUltcGwuamF2YQ==) | `72.24% <44.44%> (+0.15%)` | :arrow_up: |
| [...che/bookkeeper/mledger/impl/ManagedLedgerImpl.java](https://app.codecov.io/gh/apache/pulsar/pull/25298?src=pr&el=tree&filepath=managed-ledger%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbookkeeper%2Fmledger%2Fimpl%2FManagedLedgerImpl.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bWFuYWdlZC1sZWRnZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvbWxlZGdlci9pbXBsL01hbmFnZWRMZWRnZXJJbXBsLmphdmE=) | `80.82% <53.84%> (-0.49%)` | :arrow_down: |
... and [100 files with indirect coverage changes](https://app.codecov.io/gh/apache/pulsar/pull/25298/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve][ml] Clean up managed-ledger code: deduplicate logic and use shared utilities [pulsar]
Posted by "Technoboy- (via GitHub)" <gi...@apache.org>.
Technoboy- merged PR #25298:
URL: https://github.com/apache/pulsar/pull/25298
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve][ml] Clean up managed-ledger code: deduplicate logic and use shared utilities [pulsar]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #25298:
URL: https://github.com/apache/pulsar/pull/25298#issuecomment-4019686368
@codelipenghui 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 -->
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org