Class AdminOperationSerializer
java.lang.Object
com.linkedin.venice.controller.kafka.protocol.serializer.AdminOperationSerializer
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.apache.avro.Schemastatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSchema(int schemaId, org.apache.avro.Schema schema) deserialize(ByteBuffer byteBuffer, int writerSchemaId) voidfetchAndStoreSchemaIfAbsent(VeniceHelixAdmin admin, int schemaId) Download schema from system store schema repository and add it to the protocol map if not already present.org.apache.avro.SchemagetSchema(int schemaId) Get schema by schema id from either built-in protocol map or system store schema repository cache.voidremoveSchema(int schemaId) byte[]serialize(AdminOperation object, int targetSchemaId) Serialize AdminOperation object to bytes[] with the writer schemavoidvalidate(AdminOperation message, int targetSchemaId) Validate the AdminOperation message against the target schema for serialization compatibility.
-
Field Details
-
LATEST_SCHEMA_ID_FOR_ADMIN_OPERATION
public static final int LATEST_SCHEMA_ID_FOR_ADMIN_OPERATION -
LATEST_SCHEMA
public static final org.apache.avro.Schema LATEST_SCHEMA
-
-
Constructor Details
-
AdminOperationSerializer
public AdminOperationSerializer()
-
-
Method Details
-
serialize
Serialize AdminOperation object to bytes[] with the writer schema- Parameters:
object- AdminOperation objecttargetSchemaId- writer schema id that we will refer to for serialization and deserializationIf targetSchemaId equals LATEST_SCHEMA_ID_FOR_ADMIN_OPERATION, return the bytes[] from the first serialization. Otherwise, serialize the object to the writer schema (lower version).
This involves:
- Serializing the object to a GenericRecord with the latest schema.
- Deserializing it to a GenericRecord with the writer schema.
- Serializing it to bytes.
This process ensures the object is serialized to the lower schema version. The normal serialization process may fail (ClassCastException) due to:
- Differences in field types
- New fields added in the middle of the schema instead of at the end
-
deserialize
-
validate
Validate the AdminOperation message against the target schema for serialization compatibility.- Throws:
VeniceProtocolException- if the message does not conform to the target schema.
-
initProtocolMap
-
getSchema
public org.apache.avro.Schema getSchema(int schemaId) Get schema by schema id from either built-in protocol map or system store schema repository cache. -
fetchAndStoreSchemaIfAbsent
Download schema from system store schema repository and add it to the protocol map if not already present.- Throws:
VeniceProtocolException- if the schema could not be found in the system store schema repository.
-
addSchema
public void addSchema(int schemaId, org.apache.avro.Schema schema) -
removeSchema
public void removeSchema(int schemaId)
-