You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/04/11 14:29:35 UTC

[GitHub] [pulsar] cbornet commented on a diff in pull request #15122: Add a cache of versioned sub-schemas in KeyValueSchemaImpl

cbornet commented on code in PR #15122:
URL: https://github.com/apache/pulsar/pull/15122#discussion_r847392607


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/KeyValueSchemaImpl.java:
##########
@@ -292,14 +298,27 @@ public String toString() {
         if (!supportSchemaVersioning()) {
             return this;
         } else {
-            Schema<?> keySchema = this.keySchema instanceof AbstractSchema ? ((AbstractSchema) this.keySchema)
-                    .atSchemaVersion(schemaVersion) : this.keySchema;
-            Schema<?> valueSchema = this.valueSchema instanceof AbstractSchema ? ((AbstractSchema) this.valueSchema)
-                    .atSchemaVersion(schemaVersion) : this.valueSchema;
+            Schema<?> keySchema = getSchemaAtVersion(this.keySchema, keySchemaMap, schemaVersion);
+            Schema<?> valueSchema = getSchemaAtVersion(this.valueSchema, valueSchemaMap, schemaVersion);
             return KeyValueSchemaImpl.of(keySchema, valueSchema, keyValueEncodingType);
         }
     }
 
+    private Schema<?> getSchemaAtVersion(Schema<?> schema,
+                                         Map<SchemaVersion, Schema<?>> schemaMap,
+                                         byte[] schemaVersion) {
+        if (!(schema instanceof AbstractSchema)) {
+            return schema;
+        }
+        Objects.requireNonNull(schemaVersion);
+        SchemaVersion cacheSchemaVersion = BytesSchemaVersion.of(schemaVersion);
+        schemaMap.computeIfAbsent(

Review Comment:
   Indeed!



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

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org