BewareMyPower commented on code in PR #23915:
URL: https://github.com/apache/pulsar/pull/23915#discussion_r1948367911
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentStickyKeyDispatcherMultipleConsumers.java:
##########
@@ -439,12 +439,18 @@ private Map<Consumer, List<Entry>>
filterAndGroupEntriesForDispatching(List<Entr
permitsForConsumer.computeIfAbsent(consumer,
k -> new
MutableInt(getAvailablePermits(k)));
// a consumer was found for the sticky key hash and the
entry can be dispatched
- if (permits.intValue() > 0
- && canDispatchEntry(consumer, entry, readType,
stickyKeyHash, blockedByHash)) {
Review Comment:
Having a nullable boolean flag is very confusing and complicated.
The initialization of `blockedByHash` could be simplified like:
```java
MutableBoolean blockedByHash = null;
if (!hashIsAlreadyBlocked) {
consumer = selector.select(stickyKeyHash);
if (consumer != null) {
// ...
if (lookAheadAllowed && readType == ReadType.Normal) {
blockedByHash = new MutableBoolean(false);
}
if (permits.intValue() > 0) {
// ...
} else {
if (blockedByHash != null) {
blockedByHash.setTrue();
}
}
}
}
```
and the validation on this variable is:
```java
if (blockedByHash != null && blockedByHash.isTrue()) {
// the entry is blocked by hash, add the consumer to the
blocked set
blockedByHashConsumers.add(consumer);
}
```
It should still be a boolean **that the null value is treated as false**.
--
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]