use of org.apache.kafka.common.record.InvalidRecordException in project kafka by apache.
the class Fetcher method parseRecord.
/**
* Parse the record entry, deserializing the key / value fields if necessary
*/
private ConsumerRecord<K, V> parseRecord(TopicPartition partition, LogEntry logEntry) {
Record record = logEntry.record();
if (this.checkCrcs) {
try {
record.ensureValid();
} catch (InvalidRecordException e) {
throw new KafkaException("Record for partition " + partition + " at offset " + logEntry.offset() + " is invalid, cause: " + e.getMessage());
}
}
try {
long offset = logEntry.offset();
long timestamp = record.timestamp();
TimestampType timestampType = record.timestampType();
ByteBuffer keyBytes = record.key();
byte[] keyByteArray = keyBytes == null ? null : Utils.toArray(keyBytes);
K key = keyBytes == null ? null : this.keyDeserializer.deserialize(partition.topic(), keyByteArray);
ByteBuffer valueBytes = record.value();
byte[] valueByteArray = valueBytes == null ? null : Utils.toArray(valueBytes);
V value = valueBytes == null ? null : this.valueDeserializer.deserialize(partition.topic(), valueByteArray);
return new ConsumerRecord<>(partition.topic(), partition.partition(), offset, timestamp, timestampType, record.checksum(), keyByteArray == null ? ConsumerRecord.NULL_SIZE : keyByteArray.length, valueByteArray == null ? ConsumerRecord.NULL_SIZE : valueByteArray.length, key, value);
} catch (RuntimeException e) {
throw new SerializationException("Error deserializing key/value for partition " + partition + " at offset " + logEntry.offset(), e);
}
}
Aggregations