AnonHxy commented on code in PR #15825:
URL: https://github.com/apache/pulsar/pull/15825#discussion_r886695725


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentReplicator.java:
##########
@@ -704,10 +705,23 @@ public Optional<DispatchRateLimiter> getRateLimiter() {
     }
 
     @Override
-    public void initializeDispatchRateLimiterIfNeeded() {
-        if (!dispatchRateLimiter.isPresent()
-            && 
DispatchRateLimiter.isDispatchRateEnabled(topic.getReplicatorDispatchRate())) {
-            this.dispatchRateLimiter = Optional.of(new 
DispatchRateLimiter(topic, Type.REPLICATOR));
+    public boolean initializeDispatchRateLimiterIfNeeded() {
+        synchronized (dispatchRateLimiterLock) {
+            if (!dispatchRateLimiter.isPresent()
+                && 
DispatchRateLimiter.isDispatchRateEnabled(topic.getReplicatorDispatchRate())) {
+                this.dispatchRateLimiter = Optional.of(new 
DispatchRateLimiter(topic, Type.REPLICATOR));
+                return true;
+            }
+            return false;
+        }
+    }
+
+    @Override
+    public void updateRateLimiter() {
+        synchronized (dispatchRateLimiterLock) {

Review Comment:
   @Jason918  It seems not necessary. I will remove the `synchronized ` here.  
Because `updateDispatchRate(dispatchRate)` is synchronized, which located at 
Line203 :
   
   
https://github.com/apache/pulsar/blob/d4be6bb05204c270122e159c5c361cd7a2412805/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/DispatchRateLimiter.java#L178-L204



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

Reply via email to