[Bug] Shadow topics and topics that have shadow topics cannot be deleted cleanly
- Dominant language
- Java
- Stars
- 15.3k
- Forks
- 3.8k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 160
Description
### Search before asking
- [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.
### Read release policy
- [X] I understand that unsupported versions don't get bug fixes. I will attempt to reproduce the issue on a supported version of Pulsar client and Pulsar broker.
### Version
Pulsar version: master 15b88d2
### Minimal reproduce step
Add the following tests to `ShadowTopicRealBkTest`
```java
public void test() throws Exception {
final var sourceTopic = TopicName.get("test-read-from-source").toString();
final var shadowTopic = sourceTopic + "-shadow";
admin.topics().createNonPartitionedTopic(sourceTopic);
admin.topics().createShadowTopic(shadowTopic, sourceTopic);
admin.topics().setShadowTopics(sourceTopic, Lists.newArrayList(shadowTopic));
Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(()->{
final var sourcePersistentTopic = (PersistentTopic) pulsar.getBrokerService()
.getTopicIfExists(sourceTopic).get().orElseThrow();
final var replicator = (ShadowReplicator) sourcePersistentTopic.getShadowReplicators().get(shadowTopic);
Assert.assertNotNull(replicator);
Assert.assertEquals(String.valueOf(replicator.getState()), "Started");
});
admin.topics().delete(shadowTopic);
admin.topics().delete(sourceTopic);
}
```
### What did you expect to see?
The tests passed
### What did you see instead?
The tests failed because of the shadow replicators have producers and readers registered to the shadow topic and the source topic.
```
org.apache.pulsar.client.admin.PulsarAdminException$PreconditionFailedException: Topic has 1 connected producers/consumers
```
### Anything else?
Even if we delete these topics by force, the shadow replicator will not be cleared correctly.
### Are you willing to submit a PR?
- [X] I'm willing to submit a PR!
Contributor guide
Assessment
This issue has not been assessed yet.