[ 
https://issues.apache.org/jira/browse/ARTEMIS-3502?focusedWorklogId=658970&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-658970
 ]

ASF GitHub Bot logged work on ARTEMIS-3502:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 01/Oct/21 14:23
            Start Date: 01/Oct/21 14:23
    Worklog Time Spent: 10m 
      Work Description: clebertsuconic commented on a change in pull request 
#3777:
URL: https://github.com/apache/activemq-artemis/pull/3777#discussion_r720292426



##########
File path: 
artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java
##########
@@ -1843,47 +1843,74 @@ public void run() {
 
       @Override
       public void run() {
-         getLocalQueues().forEach(queue -> {
-            if (!queue.isInternalQueue() && 
QueueManagerImpl.isAutoDelete(queue) && 
QueueManagerImpl.consumerCountCheck(queue) && 
QueueManagerImpl.delayCheck(queue) && QueueManagerImpl.messageCountCheck(queue) 
&& queueWasUsed(queue)) {
+         reapAddresses();
+      }
+   }
+
+   private boolean queueWasUsed(Queue queue) {
+      return queue.getMessagesExpired() > 0 || queue.getMessagesAcknowledged() 
> 0 || queue.getMessagesKilled() > 0 || queue.getConsumerRemovedTimestamp() != 
-1;
+   }
+
+   /** To be used by the AddressQueueReaper */
+   void reapAddresses() {
+      getLocalQueues().forEach(queue -> {
+         if (!queue.isInternalQueue() && QueueManagerImpl.isAutoDelete(queue) 
&& QueueManagerImpl.consumerCountCheck(queue) && 
QueueManagerImpl.delayCheck(queue) && QueueManagerImpl.messageCountCheck(queue) 
&& queueWasUsed(queue)) {
+            if (queue.isSwept()) {
+               if (logger.isDebugEnabled()) {
+                  logger.debug("Removing queue " + queue.getName() + " after 
it being swept twice on reaping process");
+               }
                QueueManagerImpl.performAutoDeleteQueue(server, queue);
+            } else {
+               queue.setSweep(true);
             }
-         });
+         } else {
+            queue.setSweep(false);
+         }
+      });
 
-         Set<SimpleString> addresses = addressManager.getAddresses();
+      Set<SimpleString> addresses = addressManager.getAddresses();
 
-         for (SimpleString address : addresses) {
-            AddressInfo addressInfo = getAddressInfo(address);
-            AddressSettings settings = 
addressSettingsRepository.getMatch(address.toString());
+      for (SimpleString address : addresses) {
+         AddressInfo addressInfo = getAddressInfo(address);
+         AddressSettings settings = 
addressSettingsRepository.getMatch(address.toString());
 
-            try {
-               if (settings.isAutoDeleteAddresses() && addressInfo != null && 
addressInfo.isAutoCreated() && !isAddressBound(address) && 
addressInfo.getBindingRemovedTimestamp() != -1 && (System.currentTimeMillis() - 
addressInfo.getBindingRemovedTimestamp() >= 
settings.getAutoDeleteAddressesDelay())) {
+         try {
+            if (addressManager.checkAutoRemoveAddress(address, addressInfo, 
settings)) {
+               if (addressInfo.isSwept()) {
 
-                  if (ActiveMQServerLogger.LOGGER.isDebugEnabled()) {
-                     ActiveMQServerLogger.LOGGER.debug("deleting auto-created 
address \"" + address + ".\"");
+                  server.autoRemoveAddressInfo(address, null);
+               } else {
+                  if (logger.isDebugEnabled()) {
+                     logger.debug("Sweeping address " + address);
                   }
-
-                  server.removeAddressInfo(address, null);
+                  addressInfo.setSweep(true);
+               }
+            } else {
+               if (addressInfo != null) {
+                  addressInfo.setSweep(false);
                }
-            } catch (ActiveMQShutdownException e) {
+            }
+         } catch (ActiveMQShutdownException e) {
+            // the address and queue reaper is asynchronous so it may happen
+            // that the broker is shutting down while the reaper iterates
+            // through the addresses, next restart this operation will be 
retried
+            logger.debug(e.getMessage(), e);
+         } catch (Exception e) {
+            if (e instanceof ActiveMQAddressDoesNotExistException && 
getAddressInfo(address) == null) {
                // the address and queue reaper is asynchronous so it may happen
-               // that the broker is shutting down while the reaper iterates
-               // through the addresses, next restart this operation will be 
retried
+               // that the address is removed before the reaper removes it
                logger.debug(e.getMessage(), e);
-            } catch (Exception e) {
-               if (e instanceof ActiveMQAddressDoesNotExistException && 
getAddressInfo(address) == null) {
-                  // the address and queue reaper is asynchronous so it may 
happen
-                  // that the address is removed before the reaper removes it
-                  logger.debug(e.getMessage(), e);
-               } else {
-                  ActiveMQServerLogger.LOGGER.errorRemovingAutoCreatedQueue(e, 
address);
-               }
+            } else {
+               ActiveMQServerLogger.LOGGER.errorRemovingAutoCreatedQueue(e, 
address);

Review comment:
       thanks for this...
   it was broken since 2018 though..of course I'm fixing it :)




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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 658970)
    Time Spent: 2h  (was: 1h 50m)

> Auto delete of a queue could lead to inconsistencies
> ----------------------------------------------------
>
>                 Key: ARTEMIS-3502
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-3502
>             Project: ActiveMQ Artemis
>          Issue Type: Bug
>            Reporter: Clebert Suconic
>            Assignee: Clebert Suconic
>            Priority: Major
>          Time Spent: 2h
>  Remaining Estimate: 0h
>
> Auto delete might happen after a disconnect of consumers.
> on a situation where the consumer was up to date the queue could be removed, 
> leading to a few issues.
> we should improve how we handle with auto-delete and avoid these 
> inconsistencies.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to