-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pulsar-broker] Close previous dispatcher when subscription type changes #5288
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed if all consumer disconnected in a subscription, the topic will remove this subscription and the dispatcher is maintained by the subscription. So why don't close previous dispatcher will cause a memory leak, maybe i have not get your point here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -64,6 +64,10 @@ public synchronized boolean canUnsubscribe(Consumer consumer) { | |||
return consumerList.size() == 1 && consumerSet.contains(consumer); | |||
} | |||
|
|||
public boolean isClosed() { | |||
return IS_CLOSED_UPDATER.get(this) == TRUE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: for regular get/set operations, we can just use the variable itself return isClosed == TRUE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
The problem is that the rate limiter used for dispatch throttling is only closed in the Lines 374 to 376 in b9e7bf3
Lines 334 to 344 in b9e7bf3
And if the pulsar/pulsar-common/src/main/java/org/apache/pulsar/common/util/RateLimiter.java Lines 87 to 98 in b9e7bf3
|
@codelipenghui Hmm, if the cursor is not durable, the subscription is closed, so the dispatcher should also be closed and I think it should be fixed. Lines 230 to 232 in 499069e
I will fix it in another pull-request. |
when consumers are removed, it might be very likely that they're going to get reconnected immediately thereafter. if the subscription type is not changed, dispatcher will still be valid |
retest this please |
rerun cpp tests |
…oved from subscription (#5340) ### Motivation If cursor is not durable, the subscription is closed and removed from the topic when all consumers are removed. https://github.com/apache/pulsar/blob/413ba03050036a620fa346456ef6c3ff6071e9ab/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentSubscription.java#L237-L254 As mentioned in #5288, the dispatcher also needs to be closed at this time. Otherwise, `RateLimiter` instances will not be garbage collected, causing a memory leak.
…oved from subscription (#5340) ### Motivation If cursor is not durable, the subscription is closed and removed from the topic when all consumers are removed. https://github.com/apache/pulsar/blob/413ba03050036a620fa346456ef6c3ff6071e9ab/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentSubscription.java#L237-L254 As mentioned in #5288, the dispatcher also needs to be closed at this time. Otherwise, `RateLimiter` instances will not be garbage collected, causing a memory leak. (cherry picked from commit 136048c)
Motivation
If the subscription type on a topic changes, a new dispatcher is created and the old one is discarded. However, this old dispatcher is not closed. This will cause a memory leak.
Modifications
When the type of a subscription changes and a new dispatcher is created, close the previous one.