Skip to content

Commit 2ccc479

Browse files
committed
ARTEMIS-6076 Prevent auto delete for non-empty addresses
When an address has no direct bindings but the address size is > 0, it means queues on other addresses have one or more message references pointing to this address (e.g., queues bound to wildcard addresses).
1 parent 9f7ebd6 commit 2ccc479

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,12 @@ private void deleteDuplicateCache(SimpleString address) throws Exception {
10681068
@Override
10691069
public boolean isAddressBound(final SimpleString address) throws Exception {
10701070
Collection<Binding> bindings = getDirectBindings(address);
1071-
return bindings != null && !bindings.isEmpty();
1071+
return (bindings != null && !bindings.isEmpty()) ||
1072+
// When an address has no direct bindings but the address size is > 0, it means queues on other addresses
1073+
// have one or more message references pointing to this address (e.g., queues bound to wildcard addresses).
1074+
// The address must be considered bound because these message references keep it in use, preventing
1075+
// operations like auto-deletion that should only occur when the address is truly unused.
1076+
pagingManager.getPageStore(address).getAddressSize() > 0;
10721077
}
10731078

10741079
@Override

tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoDeleteAddressTest.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,16 @@
1818

1919
import static org.junit.jupiter.api.Assertions.assertNotNull;
2020
import static org.junit.jupiter.api.Assertions.assertNull;
21-
import static org.junit.jupiter.api.Assertions.assertTrue;
2221

2322
import java.util.ArrayList;
2423
import java.util.Arrays;
2524
import java.util.List;
26-
import java.util.concurrent.CountDownLatch;
27-
import java.util.concurrent.TimeUnit;
2825

2926
import org.apache.activemq.artemis.api.core.QueueConfiguration;
3027
import org.apache.activemq.artemis.api.core.RoutingType;
3128
import org.apache.activemq.artemis.api.core.SimpleString;
3229
import org.apache.activemq.artemis.api.core.client.ClientConsumer;
30+
import org.apache.activemq.artemis.api.core.client.ClientMessage;
3331
import org.apache.activemq.artemis.api.core.client.ClientProducer;
3432
import org.apache.activemq.artemis.api.core.client.ClientSession;
3533
import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
@@ -122,13 +120,11 @@ public void testAutoDeleteAddressWithWildcardAddress() throws Exception {
122120
String wildcardAddress = prefix + ".#";
123121
String queue = RandomUtil.randomUUIDString();
124122
final int MESSAGE_COUNT = 10;
125-
final CountDownLatch latch = new CountDownLatch(MESSAGE_COUNT);
126123

127124
server.createQueue(QueueConfiguration.of(queue).setAddress(wildcardAddress).setRoutingType(RoutingType.ANYCAST).setAutoCreated(true));
128125

129126
ClientSession consumerSession = cf.createSession();
130127
ClientConsumer consumer = consumerSession.createConsumer(queue);
131-
consumer.setMessageHandler(message -> latch.countDown());
132128
consumerSession.start();
133129

134130
ClientSession producerSession = cf.createSession();
@@ -143,7 +139,19 @@ public void testAutoDeleteAddressWithWildcardAddress() throws Exception {
143139
}
144140
producerSession.close();
145141

146-
assertTrue(latch.await(2, TimeUnit.SECONDS));
142+
PostOfficeTestAccessor.sweepAndReapAddresses((PostOfficeImpl) server.getPostOffice());
143+
144+
for (String address : addresses) {
145+
assertNotNull(server.getAddressInfo(SimpleString.of(address)));
146+
Wait.assertTrue(() -> Arrays.asList(server.getPagingManager().getStoreNames()).contains(SimpleString.of(address)), 2000, 100);
147+
}
148+
149+
for (int i = 0; i < MESSAGE_COUNT; i++) {
150+
ClientMessage message = consumer.receive(3000);
151+
assertNotNull(message);
152+
message.acknowledge();
153+
}
154+
consumerSession.commit();
147155

148156
for (String address : addresses) {
149157
assertNotNull(server.getAddressInfo(SimpleString.of(address)));

0 commit comments

Comments
 (0)