Skip to content

Commit

Permalink
Fix the schema deletion when delete topic with delete schema (apache#…
Browse files Browse the repository at this point in the history
…11501)

The delete topic REST API already provided delete schema option,
but the delete topic command does not apply this option,
instead call the delete schema independently.

And the delete schema REST API has a different behavior with the delete topic
REST API with deleteSchema=true. When delete a topic with delete schema option,
the schema ledgers and schema indexes will be deleted, but delete schema independently
only write a delete marker to the schema storage.

We may need to improve the delete schema API, but the improvement does not in this PR.
This PR just correct the delete topic with delete schema behavior.

(cherry picked from commit cc54f70)
  • Loading branch information
codelipenghui committed Jul 30, 2021
1 parent 32aa263 commit 1939fa8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -863,9 +863,8 @@ public void topics() throws Exception {
cmdTopics.run(split("truncate persistent://myprop/clust/ns1/ds1"));
verify(mockTopics).truncate("persistent://myprop/clust/ns1/ds1");

cmdTopics.run(split("delete persistent://myprop/clust/ns1/ds1 -d"));
verify(mockTopics).delete("persistent://myprop/clust/ns1/ds1", false);
verify(mockSchemas).deleteSchema("persistent://myprop/clust/ns1/ds1");
cmdTopics.run(split("delete persistent://myprop/clust/ns1/ds1 -f -d"));
verify(mockTopics).delete("persistent://myprop/clust/ns1/ds1", true, true);

cmdTopics.run(split("unload persistent://myprop/clust/ns1/ds1"));
verify(mockTopics).unload("persistent://myprop/clust/ns1/ds1");
Expand Down Expand Up @@ -974,9 +973,8 @@ public void topics() throws Exception {
cmdTopics.run(split("get-partitioned-topic-metadata persistent://myprop/clust/ns1/ds1"));
verify(mockTopics).getPartitionedTopicMetadata("persistent://myprop/clust/ns1/ds1");

cmdTopics.run(split("delete-partitioned-topic persistent://myprop/clust/ns1/ds1 -d"));
verify(mockTopics).deletePartitionedTopic("persistent://myprop/clust/ns1/ds1", false);
verify(mockSchemas, times(2)).deleteSchema("persistent://myprop/clust/ns1/ds1");
cmdTopics.run(split("delete-partitioned-topic persistent://myprop/clust/ns1/ds1 -d -f"));
verify(mockTopics).deletePartitionedTopic("persistent://myprop/clust/ns1/ds1", true, true);

cmdTopics.run(split("peek-messages persistent://myprop/clust/ns1/ds1 -s sub1 -n 3"));
verify(mockTopics).peekMessages("persistent://myprop/clust/ns1/ds1", "sub1", 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,7 @@ private class DeletePartitionedCmd extends CliCommand {
@Override
void run() throws Exception {
String topic = validateTopicName(params);
getTopics().deletePartitionedTopic(topic, force);
if (deleteSchema) {
getAdmin().schemas().deleteSchema(topic);
}
getTopics().deletePartitionedTopic(topic, force, deleteSchema);
}
}

Expand All @@ -483,10 +480,7 @@ private class DeleteCmd extends CliCommand {
@Override
void run() throws PulsarAdminException {
String topic = validateTopicName(params);
getTopics().delete(topic, force);
if (deleteSchema) {
getAdmin().schemas().deleteSchema(topic);
}
getTopics().delete(topic, force, deleteSchema);
}
}

Expand Down

0 comments on commit 1939fa8

Please sign in to comment.