From bca0af4133a6e226783f8e953f1abe7d4e165743 Mon Sep 17 00:00:00 2001 From: "Christopher L. Shannon (cshannon)" Date: Wed, 18 Apr 2018 09:04:11 -0400 Subject: [PATCH] AMQ-6947 - Update Queue metrics on expiration The updated dropMessage method only decrements the destination metrics if a message is removed from the pagedInMessages list to prevent duplicate updates. There is also a case where we still need to update metrics if the message never makes it into the pagedInMessages list in the first place and that is on expiration so this patch fixes that. A couple existing tests found this issue. (cherry picked from commit 6e468b4540754cad5cd30de373cadc026c998669) --- .../org/apache/activemq/broker/region/Queue.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java index 2946ac538c..f669e41604 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java @@ -1842,8 +1842,7 @@ public class Queue extends BaseDestination implements Task, UsageListener, Index pagedInMessagesLock.writeLock().lock(); try { if (pagedInMessages.remove(reference) != null) { - getDestinationStatistics().getDequeues().increment(); - getDestinationStatistics().getMessages().decrement(); + updateMetricsOnMessageDrop(); } } finally { pagedInMessagesLock.writeLock().unlock(); @@ -1851,6 +1850,11 @@ public class Queue extends BaseDestination implements Task, UsageListener, Index } } + private void updateMetricsOnMessageDrop() { + getDestinationStatistics().getDequeues().increment(); + getDestinationStatistics().getMessages().decrement(); + } + public void messageExpired(ConnectionContext context, MessageReference reference) { messageExpired(context, null, reference); } @@ -2007,6 +2011,11 @@ public class Queue extends BaseDestination implements Task, UsageListener, Index if (processExpired && ref.isExpired()) { if (broker.isExpired(ref)) { messageExpired(createConnectionContext(), ref); + + //We need to update the metrics here because the drop message + //method will only update if the message was removed from the + //pagedInMessages list which won't happen in this case + updateMetricsOnMessageDrop(); } else { ref.decrementReferenceCount(); }