You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.
Implement a ProtobufNativeSchemaValidator, just like the SchemaValidatorBuilder and SchemaValidator in Avro(data written with one schema can be read using another).
Define and implement incompatible rules between different "version" of protoBuf, and throw an exception (schema incompatibility) when matched.
publicenumProtobufNativeSchemaValidationStrategy {
/** * a schema can be used to read existing schema(s). */CanReadExistingStrategy,
/** * a schema can be read by existing schema(s). */CanBeReadByExistingStrategy,
/** * a schema can read existing schema(s). */CanBeReadMutualStrategy
}
Backward(CanReadExistingStrategy): The schema of the "old" version is writtenSchema, and the schema of the "new" version is readSchema.
Forward(CanBeReadByExistingStrategy): The schema of the "new" version is writtenSchema, and the schema of the "old" version is readSchema.
Full(CanBeReadMutualStrategy): Both checks are needed.
The checkSchemaCompatibility() in ProtobufNativeSchemaBreakCheckUtils:
(1) Create:
The writtenSchema cannot add required fields, but optional or duplicate fields can be added (The field number must be new).
(2) Update:
The writtenSchema do not change the field number of any field in 'readSchema' (the field name is the same, but the field number is different).
The writtenSchema does not change the field name and number, but it does change the field type.
int32, uint32, int64, uint64, and bool are all compatible – this means you can change a field from one of these types to another without breaking forwards- or backwards-compatibility.
sint32 and sint64 are compatible with each other but are not compatible with the other integer types.
string and bytes are compatible as long as the bytes are valid UTF-8.
Embedded messages are compatible with bytes if the bytes contain an encoded version of the message.
fixed32 is compatible with sfixed32, and fixed64 with sfixed64.
enum is compatible with int32, uint32, int64, and uint64 in terms of wire format (note that values will be truncated if they don’t fit).
(3) Delete:
The writtenSchema cannot remove required fields in the readSchema or fields that do not have a default value.
Original Issue: apache#19565
Motivation
In apache#19385:
The current implementation checks only for changing a root message name.
https://github.com/apache/pulsar/blob/34c18704ce759922ce45820321af44b382a28e10/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/ProtobufNativeSchemaCompatibilityCheck.java#L67-L72
And the schema compatibility strategy only has FULL. So we need to improve the PROTOBUF_NATIVE schema compatibility checks.
Goal
ProtobufNativeSchemaValidator
, just like theSchemaValidatorBuilder
andSchemaValidator
inAvro
(data written with one schema can be read using another).API Changes
ProtobufNativeSchemaValidator
ProtobufNativeSchemaValidationStrategy
ProtobufNativeSchemaValidatorBuilder
Implementation
ProtobufNativeSchemaCompatibilityCheck
.canRead()
will check that the written schema can be read by another.CanReadExistingStrategy
): The schema of the "old" version iswrittenSchema
, and the schema of the "new" version isreadSchema
.CanBeReadByExistingStrategy
): The schema of the "new" version iswrittenSchema
, and the schema of the "old" version isreadSchema
.CanBeReadMutualStrategy
): Both checks are needed.checkSchemaCompatibility()
inProtobufNativeSchemaBreakCheckUtils
:(1) Create:
writtenSchema
cannot add required fields, but optional or duplicate fields can be added (The field number must be new).(2) Update:
writtenSchema
do not change the field number of any field in 'readSchema' (the field name is the same, but the field number is different).writtenSchema
does not change the field name and number, but it does change the field type.int32
,uint32
,int64
,uint64
, andbool
are all compatible – this means you can change a field from one of these types to another without breaking forwards- or backwards-compatibility.sint32
andsint64
are compatible with each other but are not compatible with the other integer types.string
andbytes
are compatible as long as the bytes are valid UTF-8.bytes
if the bytes contain an encoded version of the message.fixed32
is compatible withsfixed32
, andfixed64
withsfixed64
.enum
is compatible withint32
,uint32
,int64
, anduint64
in terms of wire format (note that values will be truncated if they don’t fit).(3) Delete:
writtenSchema
cannot remove required fields in thereadSchema
or fields that do not have a default value.Alternatives
No response
Anything else?
No response
Links
Discussion: https://lists.apache.org/thread/c59qqzcf77w7gm9tq7thdmg0lt3qf5w8
Vote:
PR: apache#19566
The text was updated successfully, but these errors were encountered: