codelipenghui commented on a change in pull request #5227: [PIP-44] Separate 
schema compatibility checker for producer and consumer
URL: https://github.com/apache/pulsar/pull/5227#discussion_r333393457
 
 

 ##########
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/SchemasResource.java
 ##########
 @@ -314,34 +315,38 @@ public void postSchema(
 
         NamespaceName namespaceName = NamespaceName.get(tenant, namespace);
         getNamespacePoliciesAsync(namespaceName).thenAccept(policies -> {
-            SchemaCompatibilityStrategy schemaCompatibilityStrategy = 
SchemaCompatibilityStrategy
-                    
.fromAutoUpdatePolicy(policies.schema_auto_update_compatibility_strategy);
-        byte[] data;
-        if (SchemaType.KEY_VALUE.name().equals(payload.getType())) {
-            data = DefaultImplementation
-                    
.convertKeyValueDataStringToSchemaInfoSchema(payload.getSchema().getBytes(Charsets.UTF_8));
-        } else {
-            data = payload.getSchema().getBytes(Charsets.UTF_8);
-        }
-        pulsar().getSchemaRegistryService().putSchemaIfAbsent(
-            buildSchemaId(tenant, namespace, topic),
-            SchemaData.builder()
+            SchemaCompatibilityStrategy schemaCompatibilityStrategy = 
policies.schema_compatibility_strategy;
+            if (schemaCompatibilityStrategy == 
SchemaCompatibilityStrategy.UNDEFINED) {
+                schemaCompatibilityStrategy = SchemaCompatibilityStrategy
+                        
.fromAutoUpdatePolicy(policies.schema_auto_update_compatibility_strategy);
+            }
+            byte[] data;
+            if (SchemaType.KEY_VALUE.name().equals(payload.getType())) {
+                data = DefaultImplementation
+                        
.convertKeyValueDataStringToSchemaInfoSchema(payload.getSchema().getBytes(Charsets.UTF_8));
+            } else {
+                data = payload.getSchema().getBytes(Charsets.UTF_8);
+            }
+            pulsar().getSchemaRegistryService().putSchemaIfAbsent(
+                buildSchemaId(tenant, namespace, topic),
+                SchemaData.builder()
                 .data(data)
                 .isDeleted(false)
                 .timestamp(clock.millis())
                 .type(SchemaType.valueOf(payload.getType()))
                 .user(defaultIfEmpty(clientAppId(), ""))
                 .props(payload.getProperties())
                 .build(),
-                schemaCompatibilityStrategy
-        ).thenAccept(version ->
-            response.resume(
-                Response.accepted().entity(
-                    PostSchemaResponse.builder()
-                        .version(version)
-                        .build()
-                ).build()
-            )
+                schemaCompatibilityStrategy,
+                true
 
 Review comment:
   I think we don't need to add a new parameter for putSchemaIfAbsent(), add 
flag is_allow_auto_update_schema only effect the schema creation of producers 
and consumers, so move the check logic to topic.addSchema is more simpler, so 
that we don't need to transfer this parameter here

----------------------------------------------------------------
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