Class InternalAvroSpecificSerializer<SPECIFIC_RECORD extends org.apache.avro.specific.SpecificRecord>
java.lang.Object
com.linkedin.venice.serialization.avro.InternalAvroSpecificSerializer<SPECIFIC_RECORD>
- All Implemented Interfaces:
VeniceKafkaSerializer<SPECIFIC_RECORD>
,Closeable
,AutoCloseable
- Direct Known Subclasses:
ChunkedKeySuffixSerializer
,ChunkedValueManifestSerializer
,KafkaValueSerializer
public class InternalAvroSpecificSerializer<SPECIFIC_RECORD extends org.apache.avro.specific.SpecificRecord>
extends Object
implements VeniceKafkaSerializer<SPECIFIC_RECORD>
Serializer for translating a versioned protocol of Avro records.
The protocol is the following:
1st byte: The magic byte, should always equal '
magicByte
'.
2nd byte: The protocol version
3rd byte and onward: The payload (a single binary-encoded Avro record) encoded
with a writer schema determined by the protocol version specified in #2.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final String
Deprecated.static final int
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
InternalAvroSpecificSerializer
(AvroProtocolDefinition protocolDef) protected
InternalAvroSpecificSerializer
(AvroProtocolDefinition protocolDef, Integer payloadOffsetOverride) protected
InternalAvroSpecificSerializer
(AvroProtocolDefinition protocolDef, Integer payloadOffsetOverride, BiConsumer<Integer, org.apache.avro.Schema> newSchemaEncountered) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close this serializer.void
Configure this class.protected org.apache.avro.io.BinaryDecoder
createBinaryDecoder
(byte[] bytes, int offset, int length, org.apache.avro.io.BinaryDecoder reuse) deserialize
(byte[] bytes, int protocolVersion) deserialize
(byte[] bytes, int protocolVersion, SPECIFIC_RECORD reuse) deserialize
(byte[] bytes, org.apache.avro.Schema providedProtocolSchema, SPECIFIC_RECORD reuse) deserialize
(byte[] bytes, SPECIFIC_RECORD reuse) deserialize
(String topic, byte[] bytes) Create an object from an array of bytes This method is used by the Kafka consumer.org.apache.avro.Schema
it.unimi.dsi.fastutil.ints.IntSet
void
byte[]
serialize
(String topic, SPECIFIC_RECORD object) Construct an array of bytes from the given objectserialize
(SPECIFIC_RECORD object) void
setSchemaReader
(SchemaReader schemaReader)
-
Field Details
-
VENICE_SCHEMA_READER_CONFIG
Deprecated.Used to configure theschemaReader
. Deprecated: This path has now been superseded bysetSchemaReader(SchemaReader)
, which is used everywhere except incom.linkedin.venice.kafka.KafkaClientFactory#getConsumer(Properties, PubSubMessageDeserializer)
()}. Once that usage is also eliminated we could remove the config from here.- See Also:
-
MAX_ATTEMPTS_FOR_SCHEMA_READER
public static final int MAX_ATTEMPTS_FOR_SCHEMA_READER- See Also:
-
WAIT_TIME_BETWEEN_SCHEMA_READER_ATTEMPTS_IN_MS
public static final int WAIT_TIME_BETWEEN_SCHEMA_READER_ATTEMPTS_IN_MS- See Also:
-
SENTINEL_PROTOCOL_VERSION_USED_FOR_UNDETECTABLE_COMPILED_SCHEMA
public static final int SENTINEL_PROTOCOL_VERSION_USED_FOR_UNDETECTABLE_COMPILED_SCHEMA- See Also:
-
SENTINEL_PROTOCOL_VERSION_USED_FOR_UNVERSIONED_PROTOCOL
public static final int SENTINEL_PROTOCOL_VERSION_USED_FOR_UNVERSIONED_PROTOCOL- See Also:
-
-
Constructor Details
-
InternalAvroSpecificSerializer
-
InternalAvroSpecificSerializer
protected InternalAvroSpecificSerializer(AvroProtocolDefinition protocolDef, Integer payloadOffsetOverride) -
InternalAvroSpecificSerializer
protected InternalAvroSpecificSerializer(AvroProtocolDefinition protocolDef, Integer payloadOffsetOverride, BiConsumer<Integer, org.apache.avro.Schema> newSchemaEncountered)
-
-
Method Details
-
close
public void close()Close this serializer. This method has to be idempotent if the serializer is used in KafkaProducer because it might be called multiple times.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceVeniceKafkaSerializer<SPECIFIC_RECORD extends org.apache.avro.specific.SpecificRecord>
-
knownProtocols
public it.unimi.dsi.fastutil.ints.IntSet knownProtocols() -
getCompiledProtocol
public org.apache.avro.Schema getCompiledProtocol() -
configure
Configure this class.KafkaConsumer(Properties)
would eventually callconfigure(Map, boolean)
which would pass in the customized Kafka config map with schema reader.- Specified by:
configure
in interfaceVeniceKafkaSerializer<SPECIFIC_RECORD extends org.apache.avro.specific.SpecificRecord>
- Parameters:
configMap
- configs in key/value pairsisKey
- whether is for key or value
-
setSchemaReader
-
serialize
Construct an array of bytes from the given object- Specified by:
serialize
in interfaceVeniceKafkaSerializer<SPECIFIC_RECORD extends org.apache.avro.specific.SpecificRecord>
- Parameters:
topic
- Topic to which the object belongs (for API compatibility reason only, but unused)object
- AInternalAvroSpecificSerializer
instance to be serialized.- Returns:
- The Avro binary format bytes which represent the
-
serialize
-
deserialize
Create an object from an array of bytes This method is used by the Kafka consumer. These calls are always intended to be for protocols which use a magic byte and a protocol version, both of which are stored in the header, before the payload.- Specified by:
deserialize
in interfaceVeniceKafkaSerializer<SPECIFIC_RECORD extends org.apache.avro.specific.SpecificRecord>
- Parameters:
topic
- Topic to which the array of bytes belongs (only there to implement the interface, but otherwise useless)bytes
- An array of bytes representing the object's data serialized in Avro binary format.- Returns:
- A
InternalAvroSpecificSerializer
deserialized from the bytes
-
deserialize
-
deserialize
-
deserialize
-
deserialize
public SPECIFIC_RECORD deserialize(byte[] bytes, org.apache.avro.Schema providedProtocolSchema, SPECIFIC_RECORD reuse) -
createBinaryDecoder
protected org.apache.avro.io.BinaryDecoder createBinaryDecoder(byte[] bytes, int offset, int length, org.apache.avro.io.BinaryDecoder reuse) -
removeAllSchemas
public void removeAllSchemas()
-