qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oru...@apache.org
Subject qpid-broker-j git commit: QPID-8225 : Fix incorrect implementation of infinite credit
Date Tue, 07 Aug 2018 09:44:27 GMT
Repository: qpid-broker-j
Updated Branches:
  refs/heads/7.0.x 6fd5156b6 -> 11a0845fe


QPID-8225 : Fix incorrect implementation of infinite credit

(cherry picked from commit cf40fdea39d9633702ee286d94e950a19ec7be74)


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/11a0845f
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/11a0845f
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/11a0845f

Branch: refs/heads/7.0.x
Commit: 11a0845fe098ebf1039e99a054424a522fa2598a
Parents: 6fd5156
Author: Robert Godfrey <rgodfrey@apache.org>
Authored: Mon Aug 6 19:02:03 2018 +0200
Committer: Alex Rudyy <orudyy@apache.org>
Committed: Tue Aug 7 10:00:28 2018 +0100

----------------------------------------------------------------------
 .../protocol/v0_10/ConsumerTarget_0_10.java     |  3 +-
 .../protocol/v0_10/CreditCreditManager.java     | 45 +++++++++++++++++---
 .../protocol/v0_10/FlowCreditManager_0_10.java  |  2 +
 .../protocol/v0_10/WindowCreditManager.java     | 35 ++++++++++-----
 4 files changed, 66 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/11a0845f/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ConsumerTarget_0_10.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ConsumerTarget_0_10.java
b/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ConsumerTarget_0_10.java
index 8d42d2b..c58f897 100644
--- a/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ConsumerTarget_0_10.java
+++ b/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ConsumerTarget_0_10.java
@@ -513,11 +513,10 @@ public class ConsumerTarget_0_10 extends AbstractConsumerTarget<ConsumerTarget_0
         switch (unit)
         {
             case MESSAGE:
-
                 creditManager.addCredit(value, 0L);
                 break;
             case BYTE:
-                creditManager.addCredit(0l, value);
+                creditManager.addCredit(0L, value);
                 break;
         }
         updateNotifyWorkDesired();

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/11a0845f/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/CreditCreditManager.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/CreditCreditManager.java
b/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/CreditCreditManager.java
index 698351c..6cee5dd 100644
--- a/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/CreditCreditManager.java
+++ b/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/CreditCreditManager.java
@@ -21,8 +21,12 @@
 package org.apache.qpid.server.protocol.v0_10;
 
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 public class CreditCreditManager implements FlowCreditManager_0_10
 {
+    private static final Logger LOG = LoggerFactory.getLogger(CreditCreditManager.class);
     private volatile long _bytesCredit;
     private volatile long _messageCredit;
 
@@ -41,22 +45,51 @@ public class CreditCreditManager implements FlowCreditManager_0_10
     @Override
     public synchronized void addCredit(final long messageCredit, final long bytesCredit)
     {
-        if(_messageCredit >= 0L && messageCredit > 0L)
+
+        if(_messageCredit >= 0L)
         {
-            _messageCredit += messageCredit;
+            if(messageCredit == INFINITE_CREDIT)
+            {
+                _messageCredit = -1L;
+            }
+            else
+            {
+                _messageCredit += messageCredit;
+                if (_messageCredit < 0L)
+                {
+                    LOG.warn("Message credit wraparound: attempt to add {} message credit
to existing total of {}",
+                             messageCredit,
+                             _messageCredit - messageCredit);
+                    _messageCredit = Long.MAX_VALUE;
+                }
+            }
         }
 
-        if(_bytesCredit >= 0L && bytesCredit > 0L)
+        if(_bytesCredit >= 0L)
         {
-            _bytesCredit += bytesCredit;
+            if(bytesCredit == INFINITE_CREDIT)
+            {
+                _bytesCredit = -1L;
+            }
+            else
+            {
+                _bytesCredit += bytesCredit;
+                if (_bytesCredit < 0L)
+                {
+                    LOG.warn("Bytes credit wraparound: attempt to add {} bytes credit to
existing total of {}",
+                             bytesCredit,
+                             _bytesCredit - bytesCredit);
+                    _bytesCredit = Long.MAX_VALUE;
+                }
+            }
         }
     }
 
     @Override
     public synchronized void clearCredit()
     {
-        _bytesCredit = 0l;
-        _messageCredit = 0l;
+        _bytesCredit = 0L;
+        _messageCredit = 0L;
     }
 
 

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/11a0845f/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/FlowCreditManager_0_10.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/FlowCreditManager_0_10.java
b/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/FlowCreditManager_0_10.java
index a8ee98e..a4c32fd 100755
--- a/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/FlowCreditManager_0_10.java
+++ b/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/FlowCreditManager_0_10.java
@@ -24,6 +24,8 @@ import org.apache.qpid.server.flow.FlowCreditManager;
 
 public interface FlowCreditManager_0_10 extends FlowCreditManager
 {
+    long INFINITE_CREDIT = 0xFFFFFFFFL;
+
     void addCredit(long count, long bytes);
 
     void clearCredit();

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/11a0845f/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/WindowCreditManager.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/WindowCreditManager.java
b/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/WindowCreditManager.java
index d5c09d4..3f6f086 100644
--- a/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/WindowCreditManager.java
+++ b/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/WindowCreditManager.java
@@ -140,30 +140,43 @@ public class WindowCreditManager implements FlowCreditManager_0_10
     @Override
     public synchronized void addCredit(long count, long bytes)
     {
-        if(bytes > 0)
+        if(bytes == INFINITE_CREDIT)
         {
-            _bytesCreditLimit += bytes;
+            _bytesCreditLimit = -1L;
         }
-        else if(bytes == -1)
+        else if(_bytesCreditLimit >= 0L)
         {
-            _bytesCreditLimit = -1;
+            _bytesCreditLimit += bytes;
+            if (_bytesCreditLimit < 0L)
+            {
+                LOGGER.warn("Bytes credit wraparound: attempt to add {} bytes credit to existing
total of {}",
+                         bytes,
+                         _bytesCreditLimit - bytes);
+                _bytesCreditLimit = Long.MAX_VALUE;
+            }
         }
 
-
-        if(count > 0)
+        if(count == INFINITE_CREDIT)
         {
-            _messageCreditLimit += count;
+            _messageCreditLimit = -1L;
         }
-        else if(count == -1)
+        else if(_messageCreditLimit >= 0L)
         {
-            _messageCreditLimit = -1;
+            _messageCreditLimit += count;
+            if (_messageCreditLimit < 0L)
+            {
+                LOGGER.warn("Message credit wraparound: attempt to add {} message credit
to existing total of {}",
+                         count,
+                         _messageCreditLimit - count);
+                _messageCreditLimit = Long.MAX_VALUE;
+            }
         }
     }
 
     @Override
     public synchronized void clearCredit()
     {
-        _bytesCreditLimit = 0l;
-        _messageCreditLimit = 0l;
+        _bytesCreditLimit = 0L;
+        _messageCreditLimit = 0L;
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message