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/01/15 23:50:00 UTC
[PR] Fix reset cursor retry and fencing [pulsar]
codelipenghui opened a new pull request, #25148:
URL: https://github.com/apache/pulsar/pull/25148
## Summary
- retry offload reads once when the read handle is closed
- fence reset-cursor-by-timestamp to avoid concurrent resets
- add unit tests for retry and concurrent timestamp reset
## Testing
- mvn -pl managed-ledger -Dtest=RangeEntryCacheImplTest test
- mvn -pl pulsar-broker -Dtest=SubscriptionSeekTest#testConcurrentResetCursorByTimestamp test (run by @lipenghui)
--
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] [fix][broker] fix reset cursor retry and fencing [pulsar]
Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on code in PR #25148:
URL: https://github.com/apache/pulsar/pull/25148#discussion_r2696593233
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/SubscriptionSeekTest.java:
##########
@@ -457,6 +457,56 @@ public void run() {
}
}
+ @Test
+ public void testConcurrentResetCursorByTimestamp() throws Exception {
Review Comment:
This test can pass even without the change of this PR.
> fence reset-cursor-by-timestamp to avoid concurrent resets
Is the fencing mechanism change necessary? Even if so, it would be better to open a separated PR for it.
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/SubscriptionSeekTest.java:
##########
@@ -428,7 +428,7 @@ public void testConcurrentResetCursor() throws Exception {
messageIds.add(msgId);
}
- List<PulsarAdminException> exceptions = new ArrayList<>();
+ List<PulsarAdminException> exceptions = new java.util.concurrent.CopyOnWriteArrayList<>();
Review Comment:
Same long type
##########
managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/cache/RangeEntryCacheImplTest.java:
##########
@@ -183,6 +185,59 @@ public void testPartialCachingWithMultipleEntriesInCacheWhilePartialReadFails()
verify(pendingReadsManager, times(1)).readEntries(any(), eq(0L), eq(99L), any(), any(), any());
}
+ @Test
+ public void testReadFromStorageRetriesWhenHandleClosed() {
+ RangeEntryCacheManagerImpl mockEntryCacheManager = mock(RangeEntryCacheManagerImpl.class);
+ ManagedLedgerFactoryMBeanImpl mlFactoryMBean = mock(ManagedLedgerFactoryMBeanImpl.class);
+ when(mockEntryCacheManager.getMlFactoryMBean()).thenReturn(mlFactoryMBean);
+ ManagedLedgerImpl mockManagedLedger = mock(ManagedLedgerImpl.class);
+ ManagedLedgerMBeanImpl mockManagedLedgerMBean = mock(ManagedLedgerMBeanImpl.class);
+ when(mockManagedLedger.getMbean()).thenReturn(mockManagedLedgerMBean);
+ when(mockManagedLedger.getName()).thenReturn("testManagedLedger");
+ when(mockManagedLedger.getExecutor()).thenReturn(mock(java.util.concurrent.ExecutorService.class));
+ when(mockManagedLedger.getOptionalLedgerInfo(1L)).thenReturn(Optional.empty());
+ RangeCacheRemovalQueue mockRangeCacheRemovalQueue = mock(RangeCacheRemovalQueue.class);
+ when(mockRangeCacheRemovalQueue.addEntry(any())).thenReturn(true);
+ InflightReadsLimiter inflightReadsLimiter = mock(InflightReadsLimiter.class);
+ when(mockEntryCacheManager.getInflightReadsLimiter()).thenReturn(inflightReadsLimiter);
+ doAnswer(invocation -> {
+ long permits = invocation.getArgument(0);
+ InflightReadsLimiter.Handle handle = new InflightReadsLimiter.Handle(permits, System.currentTimeMillis(),
+ true);
+ return Optional.of(handle);
+ }).when(inflightReadsLimiter).acquire(anyLong(), any());
+
+ RangeEntryCacheImpl cache = new RangeEntryCacheImpl(mockEntryCacheManager, mockManagedLedger, false,
+ mockRangeCacheRemovalQueue, EntryLengthFunction.DEFAULT, mock(PendingReadsManager.class));
+
+ ReadHandle readHandle = mock(ReadHandle.class);
+ when(readHandle.getId()).thenReturn(1L);
+ when(mockManagedLedger.reopenReadHandle(1L)).thenReturn(CompletableFuture.completedFuture(readHandle));
+
+ LedgerEntryImpl ledgerEntry = LedgerEntryImpl.create(1L, 0L, 1, Unpooled.wrappedBuffer(new byte[] {1}));
+ org.apache.bookkeeper.client.api.LedgerEntries ledgerEntries =
+ mock(org.apache.bookkeeper.client.api.LedgerEntries.class);
+ List<LedgerEntry> entryList = List.of((LedgerEntry) ledgerEntry);
+ when(ledgerEntries.iterator()).thenReturn(entryList.iterator());
+
+ java.util.concurrent.atomic.AtomicInteger readAttempts = new java.util.concurrent.atomic.AtomicInteger();
Review Comment:
I see some types include full package path, could you just import them?
--
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] [fix][ml] Retry offload reads when OffloadReadHandleClosedException is encountered [pulsar]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #25148:
URL: https://github.com/apache/pulsar/pull/25148#issuecomment-3758922939
## [Codecov](https://app.codecov.io/gh/apache/pulsar/pull/25148?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 `76.47059%` with `4 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 72.60%. Comparing base ([`99fdca8`](https://app.codecov.io/gh/apache/pulsar/commit/99fdca8af6742dd36bec93ab0038fb572e6eeb0e?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`325b5f8`](https://app.codecov.io/gh/apache/pulsar/commit/325b5f801d3f6c608e36c9b068eebead793cd862?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/25148?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/25148?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=) | 0.00% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/pulsar/pull/25148?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/25148?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==) | 86.66% | [0 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/pulsar/pull/25148?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/25148?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## master #25148 +/- ##
=============================================
+ Coverage 37.41% 72.60% +35.19%
- Complexity 13148 33854 +20706
=============================================
Files 1899 1956 +57
Lines 150564 154739 +4175
Branches 17156 17644 +488
=============================================
+ Hits 56334 112349 +56015
+ Misses 86500 33420 -53080
- Partials 7730 8970 +1240
```
| [Flag](https://app.codecov.io/gh/apache/pulsar/pull/25148/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/25148/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `25.72% <23.52%> (+0.07%)` | :arrow_up: |
| [systests](https://app.codecov.io/gh/apache/pulsar/pull/25148/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `22.46% <23.52%> (+<0.01%)` | :arrow_up: |
| [unittests](https://app.codecov.io/gh/apache/pulsar/pull/25148/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `73.54% <76.47%> (+39.50%)` | :arrow_up: |
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/25148?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...che/bookkeeper/mledger/impl/ManagedLedgerImpl.java](https://app.codecov.io/gh/apache/pulsar/pull/25148?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=) | `81.35% <0.00%> (+30.49%)` | :arrow_up: |
| [...keeper/mledger/impl/cache/RangeEntryCacheImpl.java](https://app.codecov.io/gh/apache/pulsar/pull/25148?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.08% <86.66%> (+18.97%)` | :arrow_up: |
... and [1419 files with indirect coverage changes](https://app.codecov.io/gh/apache/pulsar/pull/25148/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] Fix reset cursor retry and fencing [pulsar]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #25148:
URL: https://github.com/apache/pulsar/pull/25148#issuecomment-3757411499
@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
Re: [PR] [fix][ml] Retry offload reads when OffloadReadHandleClosedException is encountered [pulsar]
Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on code in PR #25148:
URL: https://github.com/apache/pulsar/pull/25148#discussion_r2696732401
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/RangeEntryCacheImpl.java:
##########
@@ -550,17 +556,31 @@ CompletableFuture<List<Entry>> readFromStorage(ReadHandle lh, long firstEntry, l
ledgerEntries.close();
}
});
- // handle LH invalidation
- readResult.exceptionally(exception -> {
- if (exception instanceof BKException
- && ((BKException) exception).getCode() == BKException.Code.TooManyRequestsException) {
- } else {
+
+ return readResult.handle((entries, exception) -> {
+ if (exception == null) {
+ return CompletableFuture.completedFuture(entries);
+ }
+
+ Throwable cause = FutureUtil.unwrapCompletionException(exception);
+ if (allowRetry && cause instanceof ManagedLedgerException.OffloadReadHandleClosedException) {
+ log.info("[{}] Read handle closed for ledger {}, reopening", ml.getName(), lh.getId());
+ pendingReadsManager.invalidateLedger(lh.getId());
+ return ml.reopenReadHandle(lh.getId())
+ .thenCompose(reopened -> readFromStorage(reopened, firstEntry, lastEntry, expectedReadCount,
+ false));
+ }
+
+ if (!(cause instanceof BKException
+ && ((BKException) cause).getCode() == BKException.Code.TooManyRequestsException)) {
ml.invalidateLedgerHandle(lh);
pendingReadsManager.invalidateLedger(lh.getId());
}
- return null;
- });
- return readResult;
+
+ CompletableFuture<List<Entry>> failed = new CompletableFuture<>();
+ failed.completeExceptionally(cause);
+ return failed;
Review Comment:
You can use `CompletabnleFuture.failedFuture` for simplicity.
--
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] [fix][ml] Retry offload reads when OffloadReadHandleClosedException is encountered [pulsar]
Posted by "codelipenghui (via GitHub)" <gi...@apache.org>.
codelipenghui commented on code in PR #25148:
URL: https://github.com/apache/pulsar/pull/25148#discussion_r2696798971
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/RangeEntryCacheImpl.java:
##########
@@ -550,17 +556,31 @@ CompletableFuture<List<Entry>> readFromStorage(ReadHandle lh, long firstEntry, l
ledgerEntries.close();
}
});
- // handle LH invalidation
- readResult.exceptionally(exception -> {
- if (exception instanceof BKException
- && ((BKException) exception).getCode() == BKException.Code.TooManyRequestsException) {
- } else {
+
+ return readResult.handle((entries, exception) -> {
+ if (exception == null) {
+ return CompletableFuture.completedFuture(entries);
+ }
+
+ Throwable cause = FutureUtil.unwrapCompletionException(exception);
+ if (allowRetry && cause instanceof ManagedLedgerException.OffloadReadHandleClosedException) {
+ log.info("[{}] Read handle closed for ledger {}, reopening", ml.getName(), lh.getId());
+ pendingReadsManager.invalidateLedger(lh.getId());
+ return ml.reopenReadHandle(lh.getId())
+ .thenCompose(reopened -> readFromStorage(reopened, firstEntry, lastEntry, expectedReadCount,
+ false));
+ }
+
+ if (!(cause instanceof BKException
+ && ((BKException) cause).getCode() == BKException.Code.TooManyRequestsException)) {
ml.invalidateLedgerHandle(lh);
pendingReadsManager.invalidateLedger(lh.getId());
}
- return null;
- });
- return readResult;
+
+ CompletableFuture<List<Entry>> failed = new CompletableFuture<>();
+ failed.completeExceptionally(cause);
+ return failed;
Review Comment:
Fixed.
--
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] [fix][ml] Retry offload reads when OffloadReadHandleClosedException is encountered [pulsar]
Posted by "Technoboy- (via GitHub)" <gi...@apache.org>.
Technoboy- merged PR #25148:
URL: https://github.com/apache/pulsar/pull/25148
--
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] [fix][ml] Retry offload reads when OffloadReadHandleClosedException is encountered [pulsar]
Posted by "codelipenghui (via GitHub)" <gi...@apache.org>.
codelipenghui commented on code in PR #25148:
URL: https://github.com/apache/pulsar/pull/25148#discussion_r2696724200
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/SubscriptionSeekTest.java:
##########
@@ -457,6 +457,56 @@ public void run() {
}
}
+ @Test
+ public void testConcurrentResetCursorByTimestamp() throws Exception {
Review Comment:
This has been split into a separate pull request: https://github.com/apache/pulsar/pull/25151
--
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