Repository navigation
[fix][broker] Fix unexpected subscription deletion caused by the cursor last active time not updated in time - #17573
Conversation
liangyepianzhou
left a comment
There was a problem hiding this comment.
If I understand correctly, this issue does not relate to the broker restart, right?
It is that the subscriptionExpirationTimeMinutes should be the last ack time of the consumers in the subscription.
Instead of the last time that the consumer was modified (consumer add or remove) in the subscription.
If the broker shutdown gracefully, everything is fine. Because it will go through the As for the check of If the consumer is connected, it will skip the check. |
codelipenghui
left a comment
There was a problem hiding this comment.
If there are brokers shutdown with OOM or other situation, which make the broker not shutdown gracefully, the new broker load the topics and then do subscription expiry check soon before consumer reconnected, then the subscription may be deleted unexpectedly.
If the topic is loaded by another broker, the lastActive will be reset to clock.millis()
How the above situation can happen?
|
I see. Actually, only ledger rollover and updating the cursor Ledger failed will cause the |
|
If we can persistent the |
I will take a look at this and try to persistent the |
|
After discussed with @codelipenghui , this PR mainly fix the bug that subscription may be deleted unexpectedly caused by
However, the persistence is triggered only in 4 places: All of them are not high frequency triggered. The new broker may recover the cursor with The better solution is to save the |
|
@dragonls I have approved the PR. Please also update your last comment to the PR description. So that we don't to go through all the comment to understand what is the scope of this PR and what is not the scope of this PR |
…or last active time not updated in time (apache#17573) (cherry picked from commit 8a9d70a) Signed-off-by: Zixuan Liu <[email protected]>

Fixes #17572
Motivation
The
lastActiveinManagedCursorImplonly 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#internalResetCursorIf there are brokers shutdown with OOM or other situation, which make the broker not shutdown gracefully, the new broker load the topics and then do subscription expiry check soon before consumer reconnected, then the subscription may be deleted unexpectedly.
Need to update
lastActiveinManagedCursorImplwhile consuming stably, such as consumer acknowledged messages, which makeslastActivecloser to the last active meaning.Note
This PR mainly fix the bug that subscription may be deleted unexpectedly caused by
lastActivenot being updated in time, which depends on thelastActivepersistence in zk.lastActiveis saved in zk inorg.apache.bookkeeper.mledger.impl.ManagedCursorImpl#persistPositionMetaStore:pulsar/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java
Lines 2500 to 2514 in d7c09be
However, the persistence is triggered only in 4 places:

All of them are not high frequency triggered. The new broker may recover the cursor with
lastActivefrom zk which is not the real last active time. The unexpectedly subscription deletion still can appear during two persistence having broker shutdown not gracefully.The better solution is to save the
lastActiveinto cursor ledger instead of only save to zk, but this is not the problem this PR solving, and need further discussion.Modifications
cursor.updateLastActive()inorg.apache.pulsar.broker.service.persistent.PersistentSubscription#acknowledgeMessage.Verifying this change
This change added tests and can be verified as follows:
org.apache.pulsar.broker.service.persistent.PersistentTopicTest#testUpdateCursorLastActiveorg.apache.pulsar.broker.service.persistent.PersistentSubscriptionTest#testAcknowledgeUpdateCursorLastActiveDoes this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
doc-required(Your PR needs to update docs and you will update later)
doc-not-needed(Please explain why)
doc(Your PR contains doc changes)
doc-complete(Docs have been already added)