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 2022/03/17 06:48:03 UTC

[GitHub] [pulsar] codelipenghui commented on a change in pull request #14727: when consumer close and create frequently, delay message will be duplicated

codelipenghui commented on a change in pull request #14727:
URL: https://github.com/apache/pulsar/pull/14727#discussion_r828799516



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/InMemoryDelayedDeliveryTracker.java
##########
@@ -78,6 +83,17 @@ public boolean addMessage(long ledgerId, long entryId, long deliveryAt) {
             return false;
         }
 
+        synchronized (this) {
+            if (ComparisonChain.start().compare(ledgerId, lastLedgerId).compare(entryId, lastEntryId).result() <= 0) {
+                if (log.isWarnEnabled()) {
+                    log.warn("[{}] Add message  {}:{}  less than last {} {} ", dispatcher.getName(), ledgerId, entryId,

Review comment:
       The info log is ok here since it's expected behavior.

##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/InMemoryDelayedDeliveryTracker.java
##########
@@ -78,6 +83,17 @@ public boolean addMessage(long ledgerId, long entryId, long deliveryAt) {
             return false;
         }
 
+        synchronized (this) {

Review comment:
       I think we don't need `synchronized` here?
   
   The `InMemoryDelayedDeliveryTracker` is not a thread-safe container.

##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/InMemoryDelayedDeliveryTracker.java
##########
@@ -78,6 +83,17 @@ public boolean addMessage(long ledgerId, long entryId, long deliveryAt) {
             return false;
         }
 
+        synchronized (this) {
+            if (ComparisonChain.start().compare(ledgerId, lastLedgerId).compare(entryId, lastEntryId).result() <= 0) {

Review comment:
       Using Guava's ComparisonChain will create object instances.
   
   ```java
   if (ledgerId < lastLedgerId || (ledgerId == lastLedgerId && entryId < lastEntryId))
   ```




-- 
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: commits-unsubscribe@pulsar.apache.org

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