AnonHxy commented on code in PR #17948:
URL: https://github.com/apache/pulsar/pull/17948#discussion_r990612875
##########
pulsar-common/src/main/java/org/apache/pulsar/common/protocol/schema/SchemaHash.java:
##########
@@ -55,15 +82,118 @@ public static SchemaHash of(SchemaData schemaData) {
}
public static SchemaHash of(SchemaInfo schemaInfo) {
- return of(schemaInfo == null ? new byte[0] : schemaInfo.getSchema(),
+ return of(schemaInfo == null ? null : schemaInfo.getSchema(),
schemaInfo == null ? null : schemaInfo.getType());
}
- public static SchemaHash of(byte[] schemaBytes, SchemaType schemaType) {
- return new SchemaHash(hashFunction.hashBytes(schemaBytes), schemaType);
+ public static SchemaHash of() {
+ return of(null, null);
+ }
+
+ private static SchemaHash of(byte[] schemaBytes, SchemaType schemaType) {
+ SchemaHash result = null;
+ if (schemaBytes == null || schemaBytes.length == 0) {
+ result = EmptySchemaHashFactory.get(schemaType);
+ }
+
+ // This should not be a common occurrence if everything goes well.
+ if (result == null) {
+ log.warn("Could not get schemaHash from EmptySchemaHashFactory,
will create by hashFunction. Might bring"
+ + " performance regression. schemaBytes length:{},
schemaType:{}",
Review Comment:
> OK. fixed
After I look into it , it seems that struct schema can also benifit from
`EmptySchemaHashFactory`, because only `whenschemaBytes == null ||
schemaBytes.length == 0` will get from EmptySchemaHashFactory, we don't need
care if it's a struct schema or primitive schema.
So if we couldn't get it from `EmptySchemaHashFactory`, it means we miss
the type in `EmptySchemaHashFactory`
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]