[Enhancement] Concurrent Snapshots for Replicated Subscriptions controller could cause BadVersionException
- Dominant language
- Java
- Stars
- 15.3k
- Forks
- 3.8k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 160
Description
### Search before reporting
- [x] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.
### Motivation
Replicated subscription snapshot creation is scheduled at a fixed interval. There is a risk of initiating overlapping snapshot tasks in slow environments with small interval.
This could result in the following exception in the ManagedLedger.
> java.util.concurrent.CompletionException: org.apache.bookkeeper.mledger.ManagedLedgerException$BadVersionException: org.apache.pulsar.metadata.api.MetadataStoreException$BadVersionException: org.apache.zookeeper.KeeperException$BadVersionException: KeeperErrorCode = BadVersion for
### Solution
Added a concurrency guard using an AtomicBoolean to ensure only one startNewSnapshot() runs at a time. When a snapshot is already in progress, subsequent attempts are skipped with a warning log.
### Alternatives
_No response_
### Anything else?
_No response_
### Are you willing to submit a PR?
- [x] I'm willing to submit a PR!
Contributor guide
Research direction
Start at the replicated subscriptions controller and trace the scheduled snapshot path into startNewSnapshot(). Check how overlapping snapshot tasks can reach ManagedLedger and where a concurrency guard belongs. Done means concurrent attempts are skipped with a warning and the BadVersionException scenario is covered by the relevant existing tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- distributed-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100