sijie commented on a change in pull request #4262: Delete schema when deleting 
inactive topic
URL: https://github.com/apache/pulsar/pull/4262#discussion_r285340923
 
 

 ##########
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/nonpersistent/NonPersistentTopic.java
 ##########
 @@ -1040,6 +1040,21 @@ public void markBatchMessagePublished() {
             .putSchemaIfAbsent(id, schema, schemaCompatibilityStrategy);
     }
 
+    @Override
+    public CompletableFuture<SchemaVersion> deleteSchema() {
+        String base = TopicName.get(getName()).getPartitionedTopicName();
+        String id = TopicName.get(base).getSchemaName();
+        SchemaRegistryService schemaRegistryService = 
brokerService.pulsar().getSchemaRegistryService();
+        return schemaRegistryService.getSchema(id)
+                .thenCompose(schema -> {
+                    if (schema != null) {
+                        return schemaRegistryService.deleteSchema(id, "");
 
 Review comment:
   @liketic 
   
   1) I don't think we should change async to sync. since sync will be blocking 
threads, which can potentially lead to deadlock.
   
   2) what I would suggest is to mask the exception thrown due to schema not 
exists when deleteSchema. so you logic would be something like below:
   
   ```
   public CompletableFuture<SchemaVersion> deleteSchema() {
           String base = TopicName.get(getName()).getPartitionedTopicName();
           String id = TopicName.get(base).getSchemaName();
           SchemaRegistryService schemaRegistryService = 
brokerService.pulsar().getSchemaRegistryService();
           return schemaRegistryService.getSchema(id)
                   .thenCompose(schema -> {
                       CompletableFuture<SchemaVersion> deleteFuture = new 
CompletableFuture<SchemaVersion>();
                       if (schema != null) {
                           schemaRegistryService.deleteSchema(id, 
"").whenComplete((version, cause) -> {
                               if (null != cause) {
                                   if (cause instanceof 
SchemaNotFoundException) {
                                       deleteFuture.complete(null);
                                   } else {
                                       
deleteFuture.completeExceptionally(cause);
                                   }
                               } else {
                                   deleteFuture.complete(version);
                               }
                           });
                       } else {
                           deleteFuture.complete(null);
                       }
                       return deleteFuture;
                   });
       }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to