Repository navigation
Description
Search before asking
- I searched in the issues and found nothing similar.
Version
2.8.3
Minimal reproduce step
Set up a Pulsar cluster and set the broker to enable subscription expiry check (subscriptionExpirationTimeMinutes>0).
- Having a topic
persistent://test/test/testwith durable subscriptionsub-test, running onbroker A. The consumer of subscriptionsub-testshould run stably longer thansubscriptionExpirationTimeMinutes. - Make
broker Astuck, such asgdb attach <broke A pid>, and thenkill -9 <consumer pid>; kill -9 <broke A pid>. The main purpose is to prevent the broker from exiting normally and prevent the consumer from reconnecting to new broker ASAP. - The topic
persistent://test/test/testwill be owned by anotherbroker X, and recover the cursor of subscriptionsub-testwithlastActivetime, which mostly is the start time of previous consumer. - The
broker Xwill do subscription expiry check insubscriptionExpiryCheckIntervalInMinutesand then delete subscriptionsub-testof topicpersistent://test/test/test.
What did you expect to see?
The new broker should not delete subscription sub-test of topic persistent://test/test/test, because it is still active just before broker A stopped.
The new broker should recover the cursor of subscription sub-test with lastActive time correctly, which should be the real last active time of the consumer, such as just the time before consumer stopped.
What did you see instead?
Subscription sub-test of topic persistent://test/test/test is deleted unexpectedly.
Anything else?
This bug mostly happened while there are brokers shutdown with OOM or other situation, which make the broker not shutdown gracefully. And the new broker load the topics and then do subscription expiry check soon before consumer reconnected, then the subscription may be deleted unexpectedly.
The broker use sub.cursor.getLastActive() to do subscription expiry check.
pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
Lines 2354 to 2357 in 200f433
| if (System.currentTimeMillis() - sub.cursor.getLastActive() > expirationTimeMillis) { | |
| sub.delete().thenAccept(v -> log.info("[{}][{}] The subscription was deleted due to expiration", | |
| topic, subName)); | |
| } |
The lastActive in ManagedCursorImpl only be updated in 3 places:
org.apache.pulsar.broker.service.persistent.PersistentSubscription#addConsumerorg.apache.pulsar.broker.service.persistent.PersistentSubscription#removeConsumerorg.apache.bookkeeper.mledger.impl.ManagedCursorImpl#internalResetCursor
So it will be be updated during stable consumption.
Are you willing to submit a PR?
- I'm willing to submit a PR!
Activity
dragonls commentedon Sep 9, 2022
Updating
lastActiveinManagedCursorImplduring stable consumption can fix this bug.Fox example, add
cursor.updateLastActive()inorg.apache.pulsar.broker.service.persistent.PersistentSubscription#acknowledgeMessage, but I am not sure whether this is the right place.[fix][broker] Fix unexpected subscription deletion and add last activ…
[fix][broker] Add test cases for updating cursor last active time. (a…
[fix][broker] Fix unexpected subscription deletion caused by the curs…
Merge branch 'dev-druidliu-2.9' into 'branch-2.9-wxg-release' (merge …