You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/04/09 15:55:00 UTC

[GitHub] [pulsar] merlimat commented on a change in pull request #10180: Use AtomicIntegerFieldUpdater to mutate volatile int totalAvailablePermits in PersistentDispatcherMultipleConsumers class

merlimat commented on a change in pull request #10180:
URL: https://github.com/apache/pulsar/pull/10180#discussion_r610736439



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java
##########
@@ -184,7 +184,7 @@ public synchronized void removeConsumer(Consumer consumer) throws BrokerServiceE
                     messagesToRedeliver.add(ledgerId, entryId);
                     redeliveryTracker.addIfAbsent(PositionImpl.get(ledgerId, entryId));
                 });
-                totalAvailablePermits -= consumer.getAvailablePermits();
+                TOTAL_AVAILABLE_PERMITS_UPDATER.addAndGet(this, -consumer.getAvailablePermits());

Review comment:
       The increments/decrement on the `totalAvailablePermits` should already be safe because they're all done while holding the mutex on the dispatcher object.

##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java
##########
@@ -175,7 +175,7 @@ public synchronized void removeConsumer(Consumer consumer) throws BrokerServiceE
                     log.info("[{}] All consumers removed. Subscription is disconnected", name);
                     closeFuture.complete(null);
                 }
-                totalAvailablePermits = 0;
+                TOTAL_AVAILABLE_PERMITS_UPDATER.set(this, 0);

Review comment:
       This would be equivalent to `totalAvailablePermits = 0` 




-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org