This is an automated email from the ASF dual-hosted git repository.

karp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/rocketmq-schema-registry.git


The following commit(s) were added to refs/heads/main by this push:
     new bffdb52  [ISSUE #43] prevent update same schema (#50)
bffdb52 is described below

commit bffdb5234e106e58c419b3ee667d44bdd1b6e9dd
Author: wangfan <[email protected]>
AuthorDate: Wed Aug 31 10:52:34 2022 +0800

    [ISSUE #43] prevent update same schema (#50)
---
 .../core/compatibility/AvroSchemaValidator.java         | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git 
a/core/src/main/java/org/apache/rocketmq/schema/registry/core/compatibility/AvroSchemaValidator.java
 
b/core/src/main/java/org/apache/rocketmq/schema/registry/core/compatibility/AvroSchemaValidator.java
index ad38c3e..73931c2 100644
--- 
a/core/src/main/java/org/apache/rocketmq/schema/registry/core/compatibility/AvroSchemaValidator.java
+++ 
b/core/src/main/java/org/apache/rocketmq/schema/registry/core/compatibility/AvroSchemaValidator.java
@@ -58,15 +58,20 @@ public class AvroSchemaValidator implements 
org.apache.rocketmq.schema.registry.
 
     @Override
     public void validate(SchemaInfo update, SchemaInfo current) {
+        Schema toValidate = new 
Schema.Parser().parse(update.getLastRecordIdl());
+        List<Schema> existingList = new ArrayList<>();
+        for (String schemaIdl : current.getAllRecordIdlInOrder()) {
+            Schema existing = new Schema.Parser().parse(schemaIdl);
+            if (existing.equals(toValidate)) {
+                throw new SchemaCompatibilityException("Schema record: " + 
schemaIdl + " is exist.");
+            }
+            existingList.add(existing);
+        }
+
         org.apache.avro.SchemaValidator validator =
             SCHEMA_VALIDATOR_CACHE.get(current.getMeta().getCompatibility());
         try {
-            Schema toValidate = new 
Schema.Parser().parse(update.getLastRecordIdl());
-            List<Schema> existing = new ArrayList<>();
-            for (String schemaIdl : current.getAllRecordIdlInOrder()) {
-                existing.add(new Schema.Parser().parse(schemaIdl));
-            }
-            validator.validate(toValidate, existing);
+            validator.validate(toValidate, existingList);
         } catch (SchemaValidationException e) {
             throw new SchemaCompatibilityException("Schema compatibility 
validation failed", e);
         }

Reply via email to