apache / apache/pulsar

We can still get topic’s schema When deleting both the topic&schema

Open
#13,431 7 comments 0 reactions 0 assignees View on GitHub
lifecycle/stale Stale type/bug
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 ✅
![0](https://user-images.githubusercontent.com/13013780/146904743-ed4b38a0-23c3-4352-bdb9-6e1fd8ff2491.jpg)

2. **step-2**: Delete topic but not delete it's schema, in this case we can still get schema ✅
![1](https://user-images.githubusercontent.com/13013780/146905564-6e20b0b5-e481-405d-b127-1dc4e1d06247.jpg)

3. **step-3**: Recreate this topic, in this case we can still get schema ✅
![2](https://user-images.githubusercontent.com/13013780/146905285-590dae70-7a1e-475a-a507-9370c1a644b3.jpg)

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
![3](https://user-images.githubusercontent.com/13013780/146905297-8549e543-fb78-4e03-a5ee-3806fd7e3bd9.jpg)

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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.