315157973 commented on a change in pull request #11691:
URL: https://github.com/apache/pulsar/pull/11691#discussion_r690865866
##########
File path:
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerBase.java
##########
@@ -790,31 +778,20 @@ protected void notifyPendingBatchReceivedCallBack() {
}
}
- private OpBatchReceive<T> peekNextBatchReceive() {
- OpBatchReceive<T> opBatchReceive = null;
- while (opBatchReceive == null) {
- opBatchReceive = pendingBatchReceives.peek();
- // no entry available
- if (opBatchReceive == null) {
- return null;
- }
- // remove entries where future is null or has been completed
(cancel / timeout)
- if (opBatchReceive.future == null ||
opBatchReceive.future.isDone()) {
- OpBatchReceive<T> removed = pendingBatchReceives.poll();
- if (removed != opBatchReceive) {
- log.error("Bug: Removed entry wasn't the expected one.
expected={}, removed={}", opBatchReceive, removed);
- }
- opBatchReceive = null;
- }
- }
- return opBatchReceive;
+ private boolean hasNextBatchReceive() {
+ return !pendingBatchReceives.isEmpty();
}
- private OpBatchReceive<T> pollNextBatchReceive() {
+ private OpBatchReceive<T> nextBatchReceive() {
OpBatchReceive<T> opBatchReceive = null;
while (opBatchReceive == null) {
- opBatchReceive = pendingBatchReceives.poll();
+ try {
+ pendingBatchLock.lock();
Review comment:
`pendingBatchReceives` is thread-safe, why do we need to lock it? If it
is to make peek also thread-safe, should a read-write lock be used?
--
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]