We can still get topic’s schema When deleting both the topic&schema
- Dominant language
- Java
- Stars
- 15.3k
- Forks
- 3.8k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 160
Description
**Describe the bug**
We can still get the topic’s schema When we delete both the topic and schema.
**To Reproduce**
Steps to reproduce the behavior:
1. **step-1**: Get topic's schema ✅

2. **step-2**: Delete topic but not delete it's schema, in this case we can still get schema ✅

3. **step-3**: Recreate this topic, in this case we can still get schema ✅

4. **step-4**: Delete both topic and it's schema, In this case we expect not get the schema, however the actual situation does not match the expectation

In addition, I added a test in [SchemaTest.class](https://github.com/apache/pulsar/blob/master/pulsar-broker/src/test/java/org/apache/pulsar/schema/SchemaTest.java) to simulate the above steps, you can paste it and run it directly
```
@Test
public void testDeleteTopicAndSchemaForV2() throws Exception {
final String namespace = PUBLIC_TENANT + "/test-namespace";
final String topic = "persistent://" + namespace + "/partitioned-topic";
admin.namespaces().createNamespace(namespace, Sets.newHashSet(CLUSTER_NAME));
admin.topics().createPartitionedTopic(topic, 1);
@Cleanup
Producer p = pulsarClient.newProducer(Schema.JSON(Schemas.PersonThree.class))
.topic(topic)
.create();
// step-1 ✅
assertEquals(admin.schemas().getAllSchemas(topic).size(), 1);
// step-2 ✅
admin.topics().deletePartitionedTopic(topic, true, false);
assertEquals(admin.schemas().getAllSchemas(topic).size(), 1);
// step-3 ✅
admin.topics().createPartitionedTopic(topic, 1);
assertEquals(admin.schemas().getAllSchemas(topic).size(), 1);
// step-4 ❎
admin.topics().deletePartitionedTopic(topic, true, true);
assertEquals(admin.schemas().getAllSchemas(topic).size(), 0);
}
```
**Expected behavior**
In step-4 we should not get topic's schema because it has been deleted in step-3.
Contributor guide
Research direction
Start with pulsar-broker/src/test/java/org/apache/pulsar/schema/SchemaTest.java and run testDeleteTopicAndSchemaForV2 to reproduce the behavior. Trace the topic and schema deletion flow used by the test, then verify that deleting both removes the schema and that the final getAllSchemas(topic) result is empty.
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
- Clearly specified
- Newbie friendliness
- 30/100