BewareMyPower commented on a change in pull request #14545:
URL: https://github.com/apache/pulsar/pull/14545#discussion_r823807052
##########
File path:
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java
##########
@@ -2363,13 +2363,13 @@ private void
maybeOffload(CompletableFuture<PositionImpl> finalPromise) {
+ ", total size = {}, already offloaded =
{}, to offload = {}",
name,
toOffload.stream().map(LedgerInfo::getLedgerId).collect(Collectors.toList()),
sizeSummed, alreadyOffloadedSize, toOffloadSize);
+ offloadLoop(unlockingPromise, toOffload,
PositionImpl.LATEST, Optional.empty());
} else {
// offloadLoop will complete immediately with an empty
list to offload
log.debug("[{}] Nothing to offload, total size = {},
already offloaded = {}, threshold = {}",
name, sizeSummed, alreadyOffloadedSize, threshold);
+ unlockingPromise.complete(PositionImpl.LATEST);
}
-
- offloadLoop(unlockingPromise, toOffload, PositionImpl.LATEST,
Optional.empty());
Review comment:
I see. But the code here is very weird. It looks like the result of the
future has no effect because `maybeOffload` accepts `NULL_OFFLOAD_PROMISE`,
which is a completed future.
```java
unlockingPromise.whenComplete((res, ex) -> {
offloadMutex.unlock();
// The following code is meaningless because
`finalPromise` is already completed
if (ex != null) {
finalPromise.completeExceptionally(ex);
} else {
finalPromise.complete(res);
}
});
```
And I've checked the calls of `maybeOffload`, it is only called in
`maybeOffloadInBackground`, which could be called by:
1. `ledgerClosed`: the future is `NULL_OFFLOAD_PROMISE`.
2. `maybeOffload` when locking the `offloadMutex` successfully: since
`maybeOffload` could only be called in `maybeOffloadInBackground`, the future
must be `NULL_OFFLOAD_PROMISE` as well.
The code design here is really confused.
--
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]