Fix: init of subcription rateLimiter to avoid race-condition and NPE#3413
Fix: init of subcription rateLimiter to avoid race-condition and NPE#3413rdhabalia wants to merge 1 commit intoapache:masterfrom
Conversation
|
Excellent solution! just a question/proposal, has anyone ever considered of using annotations to document better thread safety like |
|
@lovelle I think it makes more sense to use jcip-annotations for the public api for better documentation. for internally, I am not sure because most of the entities at broker and clients are thread-safe and but it might be helpful for developers if we come across with such apis that requires explicit documentation. |
|
Great! I agree 👍 |
|
@rdhabalia Thanks for the change. lgtm. but from the code, this looks like a lazy creation, which could avoid creating a |
|
I shared the same concern with @jiazhai - this change is forcing every consumer to have one instance of dispatcher limiter. this can be potentially expensive for users who have a lot of consumers. @rdhabalia can we find some other approaches to fix the problem? |
umm..that's not correct. Rate-Limiter is per dispatcher-level so, not every consumer will create a rate-limiter but it will be limited at subscription level. Also, this PR is not creating additional object but it just creates RateLimiter object in a thread-safe way.
Actually existing code is also initializing rate-limiter as soon as subscription reads the message. It's lazy, non-thread-safe and unnecessary if throttling is not configured for the subscription: https://github.com/apache/pulsar/blob/master/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherSingleActiveConsumer.java#L373 However, we can avoid creating rateLimiter object if throttling is not configured and it can save us some heap. I will make the fix. |
|
@rdhabalia Thanks for the fix in #3479. Does this mean we could close this pr? |
|
@jiazhai yes, we can close this one now. |
Motivation
Initialize final
dispatchRateLimiterto avoid multiple init fordispatchRateLimiterand avoid possible NPE due to uninitializeddispatchRateLimiter