poorbarcode commented on code in PR #21915:
URL: https://github.com/apache/pulsar/pull/21915#discussion_r1461380541
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java:
##########
@@ -2793,30 +2794,23 @@ public void skipNonRecoverableLedger(final long
ledgerId){
if (ledgerInfo == null) {
return;
}
- lock.writeLock().lock();
log.warn("[{}] [{}] Since the ledger [{}] is lost and the
autoSkipNonRecoverableData is true, this ledger will"
+ " be auto acknowledge in subscription", ledger.getName(),
name, ledgerId);
- try {
- for (int i = 0; i < ledgerInfo.getEntries(); i++) {
- if (!individualDeletedMessages.contains(ledgerId, i)) {
- asyncDelete(PositionImpl.get(ledgerId, i), new
AsyncCallbacks.DeleteCallback() {
- @Override
- public void deleteComplete(Object ctx) {
- // ignore.
- }
+ asyncDelete(() -> LongStream.range(0, ledgerInfo.getEntries())
Review Comment:
@hrzzzz
> It creates all the Position objects before executing asyncDelete, which
would lead to more memory consumption, right?
Regarding the current implementation, it also creates Position instances,
right?
For example:
- entries count is `1,000`
- asked `500`
- the difference between both solutions
- current solution: will create `1000` position instances
- the solution I suggested will create `500` position instances, and it is
faster
To improve the code, you can do the following:
```java
asyncDelete(() -> LongStream.range(0,
ledgerInfo.getEntries()).filter(entryId -> {
return !individualDeletedMessages.contains(...);
}). iterator();
```
By the way, if you accepted this suggestion, you should add a test to
confirm that another thread called `lock.writeLock().lock` will stuck until the
process `asyncDelete` called by `skipNonRecoverableLedger` is finished.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]