[pulsar-broker] cursor: safe guard to avoid cursor-znode after cursor is closed #3556
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Sometimes while shutting down the broker, unknown uncompleted callback tries to update
managed-cursor
even if managed-cursor is closed and because of that topic which is already loaded by new broker sees below exception while updating managed-cursor-metadata and cursor is not able to update mark-delete position until it unloaded again.It seems it always happens for replicator-cursor and not sure exact step to reproduce but it might happen when bookies might be in unstable state (not sure about the root cause). one of the example:
Behavior:
broker-1 unloads the topic by
09:21:59.451
and broker-2 loads the same topic at09:22:00.135
. But broker-1 has log of updating metadata-znode at09:22:05.207
. So, broker-2 fails to update cursor-metadata with exceptionBadVersionException
Modification
It happens when someone tries to update cursor metadata by calling
persistPositionMetaStore(..)
so, it should have safe guard and should not update metadata if cursor is already closed.Result
It avoids any unexpected behavior while updating cursor-metadata in closed cursor state.