10BC0 [AMQ-9692] Support destination gc sweep of destinations with only wildcard consumers by mattrpav · Pull Request #1484 · apache/activemq · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@mattrpav
Copy link
Contributor

No description provided.

@mattrpav mattrpav self-assigned this Aug 26, 2025
@mattrpav mattrpav changed the title WIP: [AMQ-9692] Support destination gc sweep of destinations with only wildcard consumers [AMQ-9692] Support destination gc sweep of destinations with only wildcard consumers Aug 26, 2025
@mattrpav mattrpav requested a review from cshannon August 26, 2025 22:34
@mattrpav mattrpav changed the title [AMQ-9692] Support destination gc sweep of destinations with only wildcard consumers WIP: [AMQ-9692] Support destination gc sweep of destinations with only wildcard consumers Aug 26, 2025
@mattrpav mattrpav force-pushed the AMQ-9692 branch 3 times, most recently from 8a4acfd to d8f0981 Compare August 27, 2025 14:28
@mattrpav mattrpav changed the title WIP: [AMQ-9692] Support destination gc sweep of destinations with only wildcard consumers [AMQ-9692] Support destination gc sweep of destinations with only wildcard consumers Aug 27, 2025
@mattrpav mattrpav changed the title [AMQ-9692] Support destination gc sweep of destinations with only wildcard consumers WIP: [AMQ-9692] Support destination gc sweep of destinations with only wildcard consumers Sep 12, 2025
@mattrpav mattrpav force-pushed the AMQ-9692 branch 2 times, most recently from bc16e3a to 6ad24d0 Compare January 13, 2026 16:53
@mattrpav
Copy link
Contributor Author
mattrpav commented Jan 13, 2026

[x] GC of destinations with wildcard only works
[x] Tested lifecycle of wildcard consumer working when matching queue is added, gc'd and re-added. Messages are consumed properly.

@mattrpav mattrpav changed the title WIP: [AMQ-9692] Support destination gc sweep of destinations with only wildcard consumers [AMQ-9692] Support destination gc sweep of destinations with only wildcard consumers Jan 16, 2026
@mattrpav mattrpav requested review from cshannon and jbonofre January 20, 2026 15:52
Copy link
Member
@jbonofre jbonofre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks !

@cshannon
Copy link
Contributor

@mattrpav - The biggest thing now is I think the test coverage is lacking.

  1. Some of the new methods could be unit tested . The new hasActiveConsumers() and canGcConsumer predicate can probably be tested in isolation as they are protected so maybe with mocks or something.
  2. I think we need to double check there is sufficient test cover for the different combinations of the gcWithOnlyWildcardConsumers and gcWithOnlyWildcardConsumers flags being set. You added a test if gcWithOnlyWildcardConsumers is true but we should also add a quick test where both flags are true (easy enough to change in the policy and can probably just reuse the same test). We should also verify there's a test somewhere that still works for gc network consumers flag (i would hope so).
  3. Verify that there's good GC test coverage with both flags false as the default, i would expect there should already be some GC tests but I haven't looked in a while.

I think better test coverage is important because it would be bad to start deleting destinations that should not be deleted as that leads to permanent data loss.

@mattrpav
Copy link
Contributor Author
mattrpav commented Jan 24, 2026

@cshannon new DestinationIsActiveTest adds parameterized tests for logical combinations of:

PolicyEntry gc flag combinations vs status of:

  1. Normal consumer
  2. Network consumer
  3. Wildcard consumer

There is also a fail-safe check to ensure parameter config is correct by verifying that anytime the normal app consumer is active, the queue is flagging as active.

Intellij confirmed 100% branch coverage on those methods (aside from the producer count test)

@mattrpav mattrpav requested a review from cshannon January 24, 2026 22:09
throw new JMSException("Destination: " + destination + " still has an active subscription: " + sub);
if(sub.isWildcard()) {
var dest = destinations.get(destination);
if(dest != null && dest.isGcWithOnlyWildcardConsumers()) {
Copy link
Contributor
@cshannon cshannon Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There still seems to be a missing test case because this logic is broken, Intellij flagged it. This continue does nothing as it's in a loop and this will not throw the exception if isGcWithOnlyWildcardConsumers() is false.

This should likely just be rewritten as something like and include a test that would catch a similar mistake in the future.

if (sub.matches(destination) ) {
    var dest = destinations.get(destination);
    if(!sub.isWildcard() || dest == null || !dest.isGcWithOnlyWildcardConsumers()) {
        throw new JMSException("Destination: " + destination + " still has an active subscription: " + sub);
    } 
}

Copy link
Contributor Author
@mattrpav mattrpav Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this also need to look for the same for network-only subscribers for consistency? Or better yet perhaps re-use the isActive() or canGC() methods?

Note: This method is invoked by the RegionBroker gc check after confirming the expiration rules apply for the given destination.

In the case of GC, this is a repeat of the check.

In the case of an admin operation (ie via CLI or JMX) this is the only check to prevent deleting a destination w/ active subscribers.

Copy link
Contributor
@cshannon cshannon Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isActive() and canGC() are a bit different because they also check for active producers. I'm not entirely sure why the method to remove was written not to care about producers, maybe an oversight, but changing that now would be a behavior change that could cause some side effects that are unexpected. Re-using logic is good but maybe it just needs to be subdivided to only check for active consumers (that method already exists and isActive() calls it now).

As you pointed out, the RegionBroker calls this to delete the destination but already after the gc check so we know there are no active consumer/producers. So the real question is whether or not we care about blocking a manual deletion through JMX if there are active producers. It seems odd to not check that but changing that now as I said is a behavior change that could break someone's use case. (I suppose i could see someone wanting to block deletes with active consumers but not producers).

Your point about it not checking the gcWithNetworkConsumers flag is valid and probably a bug. In fact it proves the point that we should be sharing the logic because the GC automated check will check it but not the manual deletion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a long list of things that are like this where we may want to revisit for AMQ 7 where we want to change default behavior or settings but it's technically a breaking change so a major version is more appropriate. I guess whether or not we change this to check active producers depends on if we consider it a bug or not.

If we change it I would think by default this would share the same logic as the isActive and GC check and that should block removal by default even by an admin through JMX/console etc to prevent mistakes. But, if we do that we could add a force flag that would allow an administrator to force delete, but all of this is kind of out scope of the work for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0